use mod console

This commit is contained in:
shenjack-mac 2023-05-14 15:49:27 +08:00
parent 957b03be31
commit 7324b6cb79
2 changed files with 16 additions and 3 deletions

View File

@ -211,7 +211,7 @@ class ClientWindow(Window):
def start_game(self) -> None: def start_game(self) -> None:
self.set_icon(pyglet.image.load('./textures/icon.png')) self.set_icon(pyglet.image.load('./textures/icon.png'))
self.run_input = True self.run_input = True
self.read_input() # self.read_input()
try: try:
pyglet.app.event_loop.run(1 / self.main_config['runtime']['fps']) pyglet.app.event_loop.run(1 / self.main_config['runtime']['fps'])
except KeyboardInterrupt: except KeyboardInterrupt:
@ -314,6 +314,7 @@ class ClientWindow(Window):
self.logger.info(tr().window.command.text().format(command)) self.logger.info(tr().window.command.text().format(command))
if command.re_match('stop'): if command.re_match('stop'):
# self.dispatch_event('on_exit') # self.dispatch_event('on_exit')
print("command stop!")
pyglet.app.platform_event_loop.stop() pyglet.app.platform_event_loop.stop()
self.dispatch_event('on_close', 'command') # source = command self.dispatch_event('on_close', 'command') # source = command
elif command.re_match('fps'): elif command.re_match('fps'):
@ -439,10 +440,13 @@ class ClientWindow(Window):
self.game.dispatch_event('on_close', game=self.game, client=self, source=source) self.game.dispatch_event('on_close', game=self.game, client=self, source=source)
self.logger.info(tr().window.game.stop_get().format(tr().game[source]())) self.logger.info(tr().window.game.stop_get().format(tr().game[source]()))
self.logger.info(tr().window.game.stop()) self.logger.info(tr().window.game.stop())
self.fps_log.check_list = False # self.fps_log.check_list = False
DR_runtime.running = False DR_runtime.running = False
if self.run_input: if self.run_input:
self.run_input = False self.run_input = False
self.save_info() self.save_info()
super().on_close() super().on_close()
self.logger.info(tr().window.game.end()) self.logger.info(tr().window.game.end())
ClientWindow.register_event_type("on_command")

View File

@ -36,7 +36,7 @@ if TYPE_CHECKING:
from Difficult_Rocket.client import ClientWindow from Difficult_Rocket.client import ClientWindow
if DR_mod_runtime.use_DR_rust: if DR_mod_runtime.use_DR_rust:
from .Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs from .Difficult_Rocket_rs import CenterCamera_rs, SR1PartList_rs, Console_rs
logger = logging.getLogger('client') logger = logging.getLogger('client')
@ -135,6 +135,7 @@ class SR1ShipRender(BaseScreen):
min_zoom=(1 / 2) ** 10, max_zoom=10) min_zoom=(1 / 2) ** 10, max_zoom=10)
self.rust_parts = None self.rust_parts = None
self.part_list_rs = SR1PartList_rs('configs/PartList.xml', 'default_part_list') self.part_list_rs = SR1PartList_rs('configs/PartList.xml', 'default_part_list')
self.console = Console_rs()
def load_xml(self, file_path: str) -> bool: def load_xml(self, file_path: str) -> bool:
try: try:
@ -270,6 +271,11 @@ class SR1ShipRender(BaseScreen):
self.debug_mouse_label.draw() self.debug_mouse_label.draw()
if SR1ShipRender_Option.debug_mouse_d_pos: if SR1ShipRender_Option.debug_mouse_d_pos:
self.debug_mouse_delta_line.draw() self.debug_mouse_delta_line.draw()
if DR_mod_runtime.use_DR_rust:
read_input = self.console.get_command()
if read_input:
print(f"Rust console: |{read_input}|")
window.dispatch_event("on_command", CommandText(read_input))
def on_resize(self, width: int, height: int, window: "ClientWindow"): def on_resize(self, width: int, height: int, window: "ClientWindow"):
if not self.rendered: if not self.rendered:
@ -382,6 +388,9 @@ class SR1ShipRender(BaseScreen):
break break
self.render_ship() self.render_ship()
def on_close(self, window: "ClientWindow"):
self.console.stop_console()
if __name__ == '__main__': if __name__ == '__main__':
from objprint import op from objprint import op