From 417b20e5251a47501ef7bb9b5254992a79fc2400 Mon Sep 17 00:00:00 2001 From: Petzys <87223648+Petzys@users.noreply.github.com> Date: Wed, 13 Mar 2024 09:43:32 +0100 Subject: [PATCH] Feat(client): TTTK-58 Added functionality to send gamestate to UI on request --- Client/ui_client.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Client/ui_client.py b/Client/ui_client.py index 91170d1..3306b0a 100644 --- a/Client/ui_client.py +++ b/Client/ui_client.py @@ -83,12 +83,7 @@ async def _message_handler(self, message_type: str): self._tk_root.event_generate("<>", when="tail") self.close() case "game/turn": - self._out_queue.put({ - "message_type": "game/turn", - "next_player": int(self._current_player == self._opponent), - "playfield": self._playfield - }) - self._tk_root.event_generate("<>", when="tail") + self.send_gamestate_to_ui() case "statistics/statistics": pass case "game/error": @@ -107,6 +102,14 @@ async def _message_handler(self, message_type: str): return + def send_gamestate_to_ui(self): + self._out_queue.put({ + "message_type": "game/turn", + "next_player": int(self._current_player == self._opponent), + "playfield": self._playfield + }) + self._tk_root.event_generate("<>", when="tail") + async def await_commands(self): # Send messages to the server try: @@ -132,6 +135,8 @@ async def await_commands(self): pass case "server/terminate": await self.terminate() + case "game/gamestate": + self.send_gamestate_to_ui() case _: logger.error(f"Unknown message type received from UI in in_queue: {message['message_type']}") return