state advancer reducer

This commit is contained in:
Tao Tien 2026-02-20 15:36:04 -08:00
parent c12667938e
commit e2c9c815ec
44 changed files with 2063 additions and 773 deletions

View file

@ -1,3 +1,5 @@
use std::time::Instant;
use spacetimedb::{SpacetimeType, table};
use jong_types::{
@ -5,6 +7,8 @@ use jong_types::{
tiles::Tile,
};
use crate::reducers::advance_game;
#[derive(Debug, Clone)]
#[table(name = lobby, public)]
pub struct Lobby {
@ -12,8 +16,6 @@ pub struct Lobby {
#[auto_inc]
pub id: u32,
#[unique]
pub host_player_id: u32,
pub players: Vec<PlayerOrBot>,
pub dealer_idx: u8,
pub current_idx: u8,
@ -45,41 +47,55 @@ pub enum PlayerOrBot {
Bot { id: u32 },
}
#[table(name = advance_state_timer)]
pub struct AdvanceStateTimer {
#[primary_key]
#[auto_inc]
scheduled_id: u64,
scheduled_at: spacetimedb::ScheduleAt,
lobby_id: u32,
}
// FIXME this shant be public, use views
#[table(name = player, public)]
#[table(name = logged_out_player)]
#[derive(Debug)]
pub struct Player {
#[primary_key]
pub identity: spacetimedb::Identity,
#[unique]
#[auto_inc]
pub id: u32,
#[primary_key]
pub identity: spacetimedb::Identity,
pub name: Option<String>,
#[index(btree)]
pub lobby_id: u32,
pub ready: bool,
pub sort: bool,
}
#[table(name = player_clock, public)]
pub struct PlayerClock {
#[primary_key]
pub id: u32,
#[unique]
pub player_id: u32,
pub renewable: u16,
pub total: u16,
}
#[table(name = player_hand)]
pub struct PlayerHand {
#[primary_key]
#[auto_inc]
pub id: u32,
#[unique]
pub player_id: u32,
pub turn_state: TurnState,
pub sort: bool,
pub hand: Vec<DbTile>,
pub pond: Vec<DbTile>,
pub hand: Vec<DbTile>,
pub drawn_tile: Option<DbTile>,
/// drawn or callable tile
pub working_tile: Option<DbTile>,
}
#[table(name = bot)]
@ -91,8 +107,22 @@ pub struct Bot {
#[index(btree)]
pub lobby_id: u32,
pub turn_state: TurnState,
pub hand: Vec<DbTile>,
pub pond: Vec<DbTile>,
pub drawn_tile: Option<DbTile>,
pub working_tile: Option<DbTile>,
}
#[table(name = game_timer, scheduled(advance_game))]
pub struct GameTimer {
#[primary_key]
#[auto_inc]
pub id: u64,
#[unique]
pub lobby_id: u32,
pub scheduled_at: spacetimedb::ScheduleAt,
}