Skip to content

Commit

Permalink
Feat(client): TTTK-58 Added functionality to send gamestate to UI on …
Browse files Browse the repository at this point in the history
…request
  • Loading branch information
Petzys committed Mar 13, 2024
1 parent 2812d20 commit 417b20e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Client/ui_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ async def _message_handler(self, message_type: str):
self._tk_root.event_generate("<<game/end>>", 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("<<game/turn>>", when="tail")
self.send_gamestate_to_ui()
case "statistics/statistics":
pass
case "game/error":
Expand All @@ -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("<<game/turn>>", when="tail")

async def await_commands(self):
# Send messages to the server
try:
Expand All @@ -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
Expand Down

0 comments on commit 417b20e

Please sign in to comment.