diff --git a/DR.py b/DR.py index 53ad9b4..2beb4dc 100644 --- a/DR.py +++ b/DR.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -""" +""" writen by shenjackyuanjie email: 3695888@qq.com """ @@ -23,7 +22,8 @@ error_format = { 'error.happen': '游戏出现了一个报错!正在处理' } -if __name__ == '__main__': + +def main() -> None: start_time_ns = time.time_ns() start_time_perf_ns = time.perf_counter_ns() print(f'{__file__=}') @@ -79,3 +79,7 @@ if __name__ == '__main__': crash.record_thread = False print(crash.all_thread) print(crash.all_process) + + +if __name__ == '__main__': + main() diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index 067f6c8..9d05bed 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -132,7 +132,6 @@ class _DR_runtime(Options): f'Builtin version {relationship} than true version') - DR_option = _DR_option() DR_runtime = _DR_runtime() diff --git a/Difficult_Rocket/utils/tools.py b/Difficult_Rocket/utils/tools.py index 6ac9931..24ef3ae 100644 --- a/Difficult_Rocket/utils/tools.py +++ b/Difficult_Rocket/utils/tools.py @@ -42,7 +42,7 @@ file_error = {FileNotFoundError: 'no {filetype} file was founded!:\n file name: def load_file(file_name: str, stack: Union[str, list, dict] = None, raise_error: bool = True, - encoding: str = 'utf-8') -> Union[dict, list, ElementTree.ElementTree]: + encoding: str = 'utf-8') -> Union[dict, ElementTree.ElementTree]: f_type = file_name[file_name.rfind('.') + 1:] # 从最后一个.到末尾 (截取文件格式) get_file = NotImplementedError('解析失败,请检查文件类型/文件内容/文件是否存在!') try: diff --git a/Difficult_Rocket/utils/translate.py b/Difficult_Rocket/utils/translate.py index 1cce151..9c17bcc 100644 --- a/Difficult_Rocket/utils/translate.py +++ b/Difficult_Rocket/utils/translate.py @@ -162,8 +162,17 @@ class Tr: self.default_config = config.set('source', self) if config is not None else TranslateConfig(source=self) self.translates_cache = Translates(value=self.translates, config=self.default_config.copy()) + def init_translate(self): + self.translates: Dict[str, Union[str, Dict]] = tools.load_file(f'configs/lang/{self.language_name}.toml') + self.default_translate: Dict = tools.load_file(f'configs/lang/{DR_runtime.default_language}.toml') + self.translates_cache = Translates(value=self.translates, config=self.default_config.copy()) + def update_lang(self) -> bool: - if + if DR_runtime.language != self.language_name: + self.language_name = DR_runtime.language + self.init_translate() + return True + return False def default(self, items: Union[str, List[str]]) -> Translates: if isinstance(items, list):