Add preliminary support for multiple card games
CI / Build and push docker image (push) Successful in 3m5s
CI / Build and push docker image (push) Successful in 3m5s
A game-type registry (server/src/tavolo/games.py) is now the single source of truth for the games the platform can host; only scopone scientifico is registered so far. GET /api/game-types exposes it for the lobby's new game dropdown, and POST /api/games accepts a validated game_type (default scopone_scientifico) which is carried on the live GameState and onto each finished Match row (new indexed column, migration 1_20260916235833_update), so statistics can be scoped per game: /api/me/matches and /api/leaderboard take an optional game_type filter and every serialized match includes its game_type. Game states serialized before this change still load with the default game type.
This commit is contained in:
@@ -25,6 +25,24 @@ class InMemoryGameStoreTest(unittest.TestCase):
|
||||
self.assertEqual(16, loaded.target_score)
|
||||
self.assertEqual(["alice", "bob"], [p.sub for p in loaded.players])
|
||||
|
||||
@async_test
|
||||
async def test_game_type_roundtrip_and_default(self) -> None:
|
||||
store = InMemoryGameStore()
|
||||
state = engine.create_game(
|
||||
"g1b", "CODE1B", "alice", "alice", game_type="scopone_scientifico"
|
||||
)
|
||||
await store.save(state)
|
||||
loaded = await store.load("g1b")
|
||||
assert loaded is not None
|
||||
self.assertEqual("scopone_scientifico", loaded.game_type)
|
||||
|
||||
# States serialized before game types existed load with the default.
|
||||
legacy = state.to_json()
|
||||
del legacy["game_type"]
|
||||
from tavolo.game.state import GameState
|
||||
|
||||
self.assertEqual("scopone_scientifico", GameState.from_json(legacy).game_type)
|
||||
|
||||
@async_test
|
||||
async def test_load_missing_returns_none(self) -> None:
|
||||
store = InMemoryGameStore()
|
||||
|
||||
Reference in New Issue
Block a user