diff --git a/Difficult_Rocket/client/__init__.py b/Difficult_Rocket/client/__init__.py index 259438b..16a28d2 100644 --- a/Difficult_Rocket/client/__init__.py +++ b/Difficult_Rocket/client/__init__.py @@ -210,8 +210,6 @@ class ClientWindow(Window): def start_game(self) -> None: self.set_icon(pyglet.image.load('./textures/icon.png')) - self.run_input = True - # self.read_input() try: pyglet.app.event_loop.run(1 / self.main_config['runtime']['fps']) except KeyboardInterrupt: @@ -221,22 +219,6 @@ class ClientWindow(Window): self.dispatch_event("on_close") sys.exit(0) - @new_thread('window read_input', daemon=True) - def read_input(self): - self.logger.debug('read_input start') - while self.run_input: - try: - get = input(">") - except (EOFError, KeyboardInterrupt): - self.run_input = False - break - if get in ('', ' ', '\n', '\r'): - continue - if get == 'stop': - self.run_input = False - self.command_list.append(get) - self.logger.debug('read_input end') - @new_thread('window save_info') def save_info(self): self.logger.info(tr().client.config.save.start()) @@ -266,10 +248,8 @@ class ClientWindow(Window): @_call_screen_after def on_draw(self, *dt): - if self.command_list: - for command in self.command_list: - self.on_command(line.CommandText(command)) - self.command_list.pop(0) + while command := self.game.console.get_command(): + self.on_command(line.CommandText(command)) pyglet.gl.glClearColor(0.1, 0, 0, 0.0) self.clear() self.draw_update(float(self.SPF)) @@ -310,26 +290,26 @@ class ClientWindow(Window): @_call_screen_after def on_command(self, command: line.CommandText): - print(command.re_match('/')) + print(command.find('/')) self.logger.info(tr().window.command.text().format(command)) - if command.re_match('stop'): + if command.find('stop'): # self.dispatch_event('on_exit') print("command stop!") pyglet.app.platform_event_loop.stop() self.dispatch_event('on_close', 'command') # source = command - elif command.re_match('fps'): - if command.re_match('log'): + elif command.find('fps'): + if command.find('log'): self.logger.debug(self.fps_log.fps_list) - elif command.re_match('max'): + elif command.find('max'): self.logger.info(self.fps_log.max_fps) self.command.push_line(self.fps_log.max_fps, block_line=True) - elif command.re_match('min'): + elif command.find('min'): self.logger.info(self.fps_log.min_fps) self.command.push_line(self.fps_log.min_fps, block_line=True) - elif command.re_match('default'): + elif command.find('default'): self.set_size(int(self.main_config['window_default']['width']), int(self.main_config['window_default']['height'])) - elif command.re_match('lang'): + elif command.find('lang'): try: lang = command.text[5:] tr._language = lang diff --git a/Difficult_Rocket/command/api.py b/Difficult_Rocket/command/api.py index 0ddbf27..b9b770a 100644 --- a/Difficult_Rocket/command/api.py +++ b/Difficult_Rocket/command/api.py @@ -43,7 +43,14 @@ class CommandText: break i += 1 - def find(self, text: str) -> Union[str, bool]: + def find(self, text: str) -> bool: + find = self.text.find(text) + if find != -1: + self.text = self.text[find + len(text):] + return True + return False + + def re_find(self, text: str) -> Union[str, bool]: return finding.group() if (finding := re.match(text, self.text)) else False def re_match(self, text: str) -> bool: diff --git a/Difficult_Rocket/main.py b/Difficult_Rocket/main.py index 7f86288..383117c 100644 --- a/Difficult_Rocket/main.py +++ b/Difficult_Rocket/main.py @@ -149,7 +149,7 @@ class Game(Options): DR_runtime.DR_Mod_List = mod_list def init_console(self) -> None: - self.console = Console() + self.console = self.console_class() self.console.start() def start(self): diff --git a/docs/src/update_logs.md b/docs/src/update_logs.md index f299b20..c41eab8 100644 --- a/docs/src/update_logs.md +++ b/docs/src/update_logs.md @@ -114,6 +114,13 @@ - 修改 返回值 类型+类型注释 - Modify the return value type + type annotation - `List[Union[List[Tuple[str, Any, Any]], int, Any]]:` -> `Tuple[List[Tuple[str, Union[Any, Type], Type]], int, int, int]` +- `Difficult_Roocket.main.Game` + - 使用 `Options` 完全重构 + - 分离 `init mods` `init console` `init logger` `load_file` + - Completely refactored using `Options` + - Separate `init mods` `init console` `init logger` `load_file` +- `Difficult_Rocket.command.api.CommandText` + - `find` -> `re_find` ### Add @@ -122,6 +129,10 @@ - 用于方便的用人类可读的 Markdown 格式 直接输出一个已经实例化的 `Options` 类的所有字段 - Add `as_markdown` method - Used to easily output all fields of an instantiated `Options` class in a human-readable Markdown format +- `Difficult_Rocket.command.api.CommandText` + - 添加基于 `str.find` 的 `find(text: str) -> bool` 方法 + - Add method `find(text: str)` based on `str.find` + ### Docs