move ctx.ui to CommonClient.py
This commit is contained in:
		
							parent
							
								
									f5c62a82ac
								
							
						
					
					
						commit
						7f8617d639
					
				| 
						 | 
					@ -88,6 +88,7 @@ class CommonContext():
 | 
				
			||||||
    current_reconnect_delay = starting_reconnect_delay
 | 
					    current_reconnect_delay = starting_reconnect_delay
 | 
				
			||||||
    command_processor = ClientCommandProcessor
 | 
					    command_processor = ClientCommandProcessor
 | 
				
			||||||
    game: None
 | 
					    game: None
 | 
				
			||||||
 | 
					    ui: None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, server_address, password):
 | 
					    def __init__(self, server_address, password):
 | 
				
			||||||
        # server state
 | 
					        # server state
 | 
				
			||||||
| 
						 | 
					@ -204,7 +205,11 @@ class CommonContext():
 | 
				
			||||||
        logger.info(args["text"])
 | 
					        logger.info(args["text"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def on_print_json(self, args: dict):
 | 
					    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):
 | 
					async def server_loop(ctx: CommonContext, address=None):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -54,7 +54,6 @@ class FactorioCommandProcessor(ClientCommandProcessor):
 | 
				
			||||||
class FactorioContext(CommonContext):
 | 
					class FactorioContext(CommonContext):
 | 
				
			||||||
    command_processor = FactorioCommandProcessor
 | 
					    command_processor = FactorioCommandProcessor
 | 
				
			||||||
    game = "Factorio"
 | 
					    game = "Factorio"
 | 
				
			||||||
    ui = None
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # updated by spinup server
 | 
					    # updated by spinup server
 | 
				
			||||||
    mod_version: Utils.Version = Utils.Version(0, 0, 0)
 | 
					    mod_version: Utils.Version = Utils.Version(0, 0, 0)
 | 
				
			||||||
| 
						 | 
					@ -64,7 +63,6 @@ class FactorioContext(CommonContext):
 | 
				
			||||||
        self.send_index = 0
 | 
					        self.send_index = 0
 | 
				
			||||||
        self.rcon_client = None
 | 
					        self.rcon_client = None
 | 
				
			||||||
        self.awaiting_bridge = False
 | 
					        self.awaiting_bridge = False
 | 
				
			||||||
        self.raw_json_text_parser = RawJSONtoTextParser(self)
 | 
					 | 
				
			||||||
        self.factorio_json_text_parser = FactorioJSONtoTextParser(self)
 | 
					        self.factorio_json_text_parser = FactorioJSONtoTextParser(self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def server_auth(self, password_requested):
 | 
					    async def server_auth(self, password_requested):
 | 
				
			||||||
| 
						 | 
					@ -90,14 +88,10 @@ class FactorioContext(CommonContext):
 | 
				
			||||||
            self.print_to_game(args['text'])
 | 
					            self.print_to_game(args['text'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def on_print_json(self, args: dict):
 | 
					    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:
 | 
					        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)
 | 
					            self.print_to_game(text)
 | 
				
			||||||
 | 
					        super(FactorioContext, self).on_print_json(args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def savegame_name(self) -> str:
 | 
					    def savegame_name(self) -> str:
 | 
				
			||||||
| 
						 | 
					@ -279,9 +273,8 @@ async def main(args):
 | 
				
			||||||
    if gui_enabled:
 | 
					    if gui_enabled:
 | 
				
			||||||
        input_task = None
 | 
					        input_task = None
 | 
				
			||||||
        from kvui import FactorioManager
 | 
					        from kvui import FactorioManager
 | 
				
			||||||
        ui_app = FactorioManager(ctx)
 | 
					        ctx.ui = FactorioManager(ctx)
 | 
				
			||||||
        ctx.ui = ui_app
 | 
					        ui_task = asyncio.create_task(ctx.ui.async_run(), name="UI")
 | 
				
			||||||
        ui_task = asyncio.create_task(ui_app.async_run(), name="UI")
 | 
					 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        input_task = asyncio.create_task(console_loop(ctx), name="Input")
 | 
					        input_task = asyncio.create_task(console_loop(ctx), name="Input")
 | 
				
			||||||
        ui_task = None
 | 
					        ui_task = None
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -904,9 +904,8 @@ async def main():
 | 
				
			||||||
    if Utils.is_frozen() or "--nogui" not in sys.argv:
 | 
					    if Utils.is_frozen() or "--nogui" not in sys.argv:
 | 
				
			||||||
        input_task = None
 | 
					        input_task = None
 | 
				
			||||||
        from kvui import LttPManager
 | 
					        from kvui import LttPManager
 | 
				
			||||||
        ui_app = LttPManager(ctx)
 | 
					        ctx.ui = LttPManager(ctx)
 | 
				
			||||||
        ctx.ui = ui_app
 | 
					        ui_task = asyncio.create_task(ctx.ui.async_run(), name="UI")
 | 
				
			||||||
        ui_task = asyncio.create_task(ui_app.async_run(), name="UI")
 | 
					 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        input_task = asyncio.create_task(console_loop(ctx), name="Input")
 | 
					        input_task = asyncio.create_task(console_loop(ctx), name="Input")
 | 
				
			||||||
        ui_task = None
 | 
					        ui_task = None
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue