Skip to content

Commit

Permalink
Fix(statistics): TTTK-55 Fix JSON schema and client code to fit new s…
Browse files Browse the repository at this point in the history
…tatistics
  • Loading branch information
Petzys committed Mar 14, 2024
1 parent 90de2ea commit 31489e5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async def _preprocess_message(self, message:str) -> str:
self._current_player = self.get_player_by_uuid(message_json["next_player_uuid"])
case "statistics/statistics":
for player, statistic in message_json["server_statistics"]:
self._statistics[Player.from_dict(player)] = statistic
self._statistics[Player(**player)] = statistic
case "game/error":
self._error_history.append(message_json["error_message"])
logger.error(f"Game error: {message_json['error_message']}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,31 @@
"message_type": "statistics/statistics",
"server_statistics": [
{
"profile": {
"player": {
"uuid": "123e4567-e89b-12d3-a456-426614174000",
"display_name": "Player1",
"color": 16711680
},
"statistics": {
"wins_first": 5,
"wins_second": 3,
"loses_first": 2,
"loses_second": 4,
"draws": 1,
"wins": 10,
"losses": 5,
"draws": 2,
"moves": 100,
"emojis": 20
"emojis": 50
}
},
{
"profile": {
"player": {
"uuid": "123e4567-e89b-12d3-a456-426614174001",
"display_name": "Player2",
"color": 65280
},
"statistics": {
"wins_first": 3,
"wins_second": 5,
"loses_first": 4,
"loses_second": 2,
"draws": 1,
"wins": 5,
"losses": 10,
"draws": 2,
"moves": 95,
"emojis": 15
"emojis": 45
}
}
]
Expand Down
20 changes: 5 additions & 15 deletions json_schema/server_to_client.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,13 @@
"description": "The statistics of a player",
"type": "object",
"properties": {
"wins_first": {
"description": "The number of wins as first player",
"wins": {
"description": "The number of wins",
"type": "integer",
"minimum": 0
},
"wins_second": {
"description": "The number of wins as second player",
"type": "integer",
"minimum": 0
},
"loses_first": {
"description": "The number of loses as first player",
"type": "integer",
"minimum": 0
},
"loses_second": {
"description": "The number of loses as second player",
"losses": {
"description": "The number of loses",
"type": "integer",
"minimum": 0
},
Expand All @@ -153,7 +143,7 @@
"minimum": 0
}
},
"required": ["wins_first", "wins_second", "loses_first", "loses_second", "draws", "moves", "emojis"]
"required": ["wins", "losses", "draws", "moves", "emojis"]
}
},
"required": ["player", "statistics"]
Expand Down

0 comments on commit 31489e5

Please sign in to comment.