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:
+32
-2
@@ -4,7 +4,16 @@ use sycamore::prelude::*;
|
||||
use sycamore_router::navigate;
|
||||
|
||||
use crate::api;
|
||||
use crate::model::User;
|
||||
use crate::model::{GameTypeInfo, User};
|
||||
|
||||
/// Used when the game-types fetch fails: match creation must still work.
|
||||
fn fallback_game_types() -> Vec<GameTypeInfo> {
|
||||
vec![GameTypeInfo {
|
||||
id: "scopone_scientifico".to_string(),
|
||||
name: "Scopone scientifico".to_string(),
|
||||
description: String::new(),
|
||||
}]
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn LobbyPage() -> View {
|
||||
@@ -12,6 +21,8 @@ pub fn LobbyPage() -> View {
|
||||
let user = create_signal(Option::<Option<User>>::None);
|
||||
let error = create_signal(Option::<String>::None);
|
||||
let code = create_signal(String::new());
|
||||
let game_types = create_signal(fallback_game_types());
|
||||
let selected_game = create_signal("scopone_scientifico".to_string());
|
||||
|
||||
spawn_local(async move {
|
||||
match api::me().await {
|
||||
@@ -23,9 +34,20 @@ pub fn LobbyPage() -> View {
|
||||
}
|
||||
});
|
||||
|
||||
spawn_local(async move {
|
||||
match api::game_types().await {
|
||||
Ok(types) if !types.is_empty() => {
|
||||
selected_game.set(types[0].id.clone());
|
||||
game_types.set(types);
|
||||
}
|
||||
_ => {} // keep the scopone fallback
|
||||
}
|
||||
});
|
||||
|
||||
let on_create = move |target: i32| {
|
||||
let game_type = selected_game.get_clone();
|
||||
spawn_local(async move {
|
||||
match api::create_game(target).await {
|
||||
match api::create_game(&game_type, target).await {
|
||||
Ok(game) => navigate(&format!("/game/{}", game.id)),
|
||||
Err(e) => error.set(Some(e)),
|
||||
}
|
||||
@@ -70,6 +92,14 @@ pub fn LobbyPage() -> View {
|
||||
}
|
||||
div(class="panel") {
|
||||
h2 { "New match" }
|
||||
label(r#for="game-type") { "Game" }
|
||||
select(id="game-type", bind:value=selected_game) {
|
||||
Keyed(
|
||||
list=game_types,
|
||||
view=|g| view! { option(value=g.id.clone()) { (g.name) } },
|
||||
key=|g| g.id.clone(),
|
||||
)
|
||||
}
|
||||
p { "First team to reach the target score wins." }
|
||||
div(class="target-buttons") {
|
||||
button(class="button", on:click=move |_| on_create(11)) { "Target 11" }
|
||||
|
||||
Reference in New Issue
Block a user