diff --git a/examples/bf1chs/__main__.py b/examples/bf1chs/__main__.py index f804ea2..d4c1577 100644 --- a/examples/bf1chs/__main__.py +++ b/examples/bf1chs/__main__.py @@ -37,7 +37,7 @@ from flamethrower.localization import Histogram, StringsBinary -VERSION = "v0.5.0" +VERSION = "v0.5.1" PROJECT_ID = 8862 REPO_NAME = "flamethrower" REPO_OWNER_GITHUB = "zyf722" @@ -419,11 +419,13 @@ def _rich_progress( return None @staticmethod - def _rich_confirm(message: str, default=True, **kwargs): + def _rich_confirm(message: str, default=True, desc: Optional[str] = None, **kwargs): """ Helper function to show confirm in rich format. """ console.print("[dark-gray](输入 y/n 或者回车键直接确认)") + if desc is not None: + console.print(f"[dark-gray]({desc})") return inquirer.confirm( message=message, default=default, @@ -434,11 +436,15 @@ def _rich_confirm(message: str, default=True, **kwargs): ).execute() @staticmethod - def _rich_integer(message: str, default: int = 0, **kwargs): + def _rich_integer( + message: str, default: int = 0, desc: Optional[str] = None, **kwargs + ): """ Helper function to show integer in rich format. """ console.print("[dark-gray](使用方向键上下增减 / 数字键输入数字 / 回车键确认)") + if desc is not None: + console.print(f"[dark-gray]({desc})") result = inquirer.number( message=message, default=default, @@ -448,11 +454,15 @@ def _rich_integer(message: str, default: int = 0, **kwargs): return int(result) @staticmethod - def _rich_text(message: str, default: str = "", **kwargs): + def _rich_text( + message: str, default: str = "", desc: Optional[str] = None, **kwargs + ): """ Helper function to show text in rich format. """ console.print("[dark-gray](输入文本 / 回车键确认)") + if desc is not None: + console.print(f"[dark-gray]({desc})") result = inquirer.text( message=message, default=default, @@ -466,6 +476,7 @@ def _rich_fuzzy_select_file( directory: str, types: Union[str, List[str]], message: str = "选择文件", + desc: Optional[str] = None, **kwargs, ): """ @@ -490,6 +501,8 @@ def validator(types: Union[str, List[str]], file: str): console.print( "[dark-gray](使用方向键上下移动 / 回车键确认 / 输入关键词进行模糊搜索)" ) + if desc is not None: + console.print(f"[dark-gray]({desc})") result = inquirer.fuzzy( message=f"{message} ({types_repr})", choices=choices, @@ -846,6 +859,13 @@ def _create_strings_binary_runner( self._rich_show_object(strings_binary) + debug_mode = self._rich_confirm( + message="是否启用调试模式?", + default=False, + desc="调试模式下,所有词条前将被添加对应键作为注释。", + ) + console.print() + # Load new strings json file with open( os.path.join(processed_path, "strings-zht.csv.json"), @@ -879,6 +899,9 @@ def _create_strings_binary_runner( ) def _import_strings_wrapper(): + if debug_mode: + for key, value in new_dict.items(): + new_dict[key] = f"{key:08X} {value}" strings_binary.import_strings(new_dict) # type: ignore return True @@ -1090,6 +1113,13 @@ def _update_twinkle(self): return console.print() + debug_mode = self._rich_confirm( + message="是否启用调试模式?", + default=False, + desc="调试模式下,所有词条前将被添加对应键作为注释。", + ) + console.print() + def _twinkle_runner( progress: Progress, task: TaskID, @@ -1101,6 +1131,12 @@ def _twinkle_runner( entry_dict[item["original"]] = item["translation"] elif entry_dict[item["original"]] != item["translation"]: conflict_count += 1 + + if debug_mode: + entry_dict[item["original"]] = ( + f"{item['key']} {item['translation']}" + ) + progress.advance(task) with open( @@ -1451,3 +1487,5 @@ def run(self): BF1ChsToolbox().run() except BF1ChsToolbox.ExitException: pass + except BF1ChsToolbox.ExitException: + pass