From 7f8617d63988f7604bffcde3cc1f3b2652f646a5 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sat, 31 Jul 2021 01:53:06 +0200 Subject: [PATCH] move ctx.ui to CommonClient.py --- CommonClient.py | 7 ++++++- FactorioClient.py | 15 ++++----------- LttPClient.py | 5 ++--- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/CommonClient.py b/CommonClient.py index 6078c380..823d93d3 100644 --- a/CommonClient.py +++ b/CommonClient.py @@ -88,6 +88,7 @@ class CommonContext(): current_reconnect_delay = starting_reconnect_delay command_processor = ClientCommandProcessor game: None + ui: None def __init__(self, server_address, password): # server state @@ -204,7 +205,11 @@ class CommonContext(): logger.info(args["text"]) def on_print_json(self, args: dict): - logger.info(self.jsontotextparser(args["data"])) + if self.ui: + self.ui.print_json(args["data"]) + else: + text = self.jsontotextparser(args["data"]) + logger.info(text) async def server_loop(ctx: CommonContext, address=None): diff --git a/FactorioClient.py b/FactorioClient.py index 1be755c7..9e3595d2 100644 --- a/FactorioClient.py +++ b/FactorioClient.py @@ -54,7 +54,6 @@ class FactorioCommandProcessor(ClientCommandProcessor): class FactorioContext(CommonContext): command_processor = FactorioCommandProcessor game = "Factorio" - ui = None # updated by spinup server mod_version: Utils.Version = Utils.Version(0, 0, 0) @@ -64,7 +63,6 @@ class FactorioContext(CommonContext): self.send_index = 0 self.rcon_client = None self.awaiting_bridge = False - self.raw_json_text_parser = RawJSONtoTextParser(self) self.factorio_json_text_parser = FactorioJSONtoTextParser(self) async def server_auth(self, password_requested): @@ -90,14 +88,10 @@ class FactorioContext(CommonContext): self.print_to_game(args['text']) def on_print_json(self, args: dict): - if self.ui: - self.ui.print_json(copy.deepcopy(args["data"])) - else: - text = self.raw_json_text_parser(copy.deepcopy(args["data"])) - logger.info(text) if self.rcon_client: - text = self.factorio_json_text_parser(args["data"]) + text = self.factorio_json_text_parser(copy.deepcopy(args["data"])) self.print_to_game(text) + super(FactorioContext, self).on_print_json(args) @property def savegame_name(self) -> str: @@ -279,9 +273,8 @@ async def main(args): if gui_enabled: input_task = None from kvui import FactorioManager - ui_app = FactorioManager(ctx) - ctx.ui = ui_app - ui_task = asyncio.create_task(ui_app.async_run(), name="UI") + ctx.ui = FactorioManager(ctx) + ui_task = asyncio.create_task(ctx.ui.async_run(), name="UI") else: input_task = asyncio.create_task(console_loop(ctx), name="Input") ui_task = None diff --git a/LttPClient.py b/LttPClient.py index 5113fae9..378b4d65 100644 --- a/LttPClient.py +++ b/LttPClient.py @@ -904,9 +904,8 @@ async def main(): if Utils.is_frozen() or "--nogui" not in sys.argv: input_task = None from kvui import LttPManager - ui_app = LttPManager(ctx) - ctx.ui = ui_app - ui_task = asyncio.create_task(ui_app.async_run(), name="UI") + ctx.ui = LttPManager(ctx) + ui_task = asyncio.create_task(ctx.ui.async_run(), name="UI") else: input_task = asyncio.create_task(console_loop(ctx), name="Input") ui_task = None