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:
@@ -101,6 +101,9 @@ pub struct GameView {
|
||||
pub id: String,
|
||||
#[serde(default)]
|
||||
pub join_code: String,
|
||||
/// Which card game this match is (id from /api/game-types).
|
||||
#[serde(default)]
|
||||
pub game_type: String,
|
||||
pub phase: String,
|
||||
#[serde(default)]
|
||||
pub target_score: i32,
|
||||
@@ -174,6 +177,8 @@ pub struct MatchPlayer {
|
||||
#[allow(dead_code)]
|
||||
pub struct MatchSummary {
|
||||
pub id: String,
|
||||
#[serde(default)]
|
||||
pub game_type: String,
|
||||
pub team_a_score: i32,
|
||||
pub team_b_score: i32,
|
||||
pub winner_team: String,
|
||||
@@ -211,6 +216,22 @@ pub struct LeaderboardPage {
|
||||
pub results: Vec<LeaderboardEntry>,
|
||||
}
|
||||
|
||||
/// A card game the platform can host (GET /api/game-types).
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize)]
|
||||
#[allow(dead_code)]
|
||||
pub struct GameTypeInfo {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
#[serde(default)]
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct GameTypesPage {
|
||||
#[serde(default)]
|
||||
pub results: Vec<GameTypeInfo>,
|
||||
}
|
||||
|
||||
/// Map a card code (e.g. `07D`) to its asset path.
|
||||
pub fn card_asset(code: &str) -> String {
|
||||
format!("/assets/cards/{code}.svg")
|
||||
|
||||
Reference in New Issue
Block a user