From 71ad4cada62554453cf973897dfb769e38337607 Mon Sep 17 00:00:00 2001 From: Tao Tien <29749622+taotien@users.noreply.github.com> Date: Wed, 11 Feb 2026 10:14:02 -0800 Subject: [PATCH] extract player tables --- spacetimedb/src/game.rs | 2 +- spacetimedb/src/game/hand.rs | 2 +- spacetimedb/src/lib.rs | 2 +- spacetimedb/src/tables.rs | 47 ++++---------------------------- spacetimedb/src/tables/player.rs | 40 +++++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 44 deletions(-) create mode 100644 spacetimedb/src/tables/player.rs diff --git a/spacetimedb/src/game.rs b/spacetimedb/src/game.rs index 5ade52f..07eff79 100644 --- a/spacetimedb/src/game.rs +++ b/spacetimedb/src/game.rs @@ -1,7 +1,7 @@ use log::{info, trace}; use spacetimedb::{ReducerContext, Table, reducer}; -use crate::tables::*; +use crate::tables::{player::player, *}; use jong_types::*; mod hand; diff --git a/spacetimedb/src/game/hand.rs b/spacetimedb/src/game/hand.rs index 546ad66..adc9845 100644 --- a/spacetimedb/src/game/hand.rs +++ b/spacetimedb/src/game/hand.rs @@ -1,6 +1,6 @@ use spacetimedb::{ReducerContext, Table, ViewContext, reducer, view}; -use crate::tables::*; +use crate::tables::{player::player, *}; use jong_types::*; pub fn deal_hands(ctx: &ReducerContext, lobby_id: u32) { diff --git a/spacetimedb/src/lib.rs b/spacetimedb/src/lib.rs index 505db51..3af5855 100644 --- a/spacetimedb/src/lib.rs +++ b/spacetimedb/src/lib.rs @@ -1,7 +1,7 @@ use log::info; use spacetimedb::{ReducerContext, Table, reducer}; -use crate::tables::*; +use crate::tables::{player::player, *}; mod game; mod tables; diff --git a/spacetimedb/src/tables.rs b/spacetimedb/src/tables.rs index e06de8e..f92657c 100644 --- a/spacetimedb/src/tables.rs +++ b/spacetimedb/src/tables.rs @@ -1,44 +1,9 @@ -use spacetimedb::{Filter, Identity, SpacetimeType, client_visibility_filter, table}; +use spacetimedb::{Filter, SpacetimeType, client_visibility_filter, table}; use jong_types::*; -#[derive(Debug)] -#[table(name = player, public)] -pub struct Player { - #[primary_key] - pub identity: Identity, - - #[unique] - #[auto_inc] - pub id: u32, - - pub name: Option, - - #[index(btree)] - pub lobby_id: u32, - pub hand_id: u32, - pub pond_id: u32, - - pub ready: bool, -} - -#[table(name = bot)] -pub struct Bot { - #[primary_key] - #[auto_inc] - pub id: u32, - - #[index(btree)] - pub lobby_id: u32, - pub hand_id: u32, - pub pond_id: u32, -} - -#[derive(Debug, Clone, SpacetimeType)] -pub enum PlayerOrBot { - Player { id: u32 }, - Bot { id: u32 }, -} +pub mod player; +pub use player::*; #[derive(Debug, Clone)] #[table(name = lobby, public)] @@ -49,7 +14,7 @@ pub struct Lobby { #[unique] pub host_player_id: u32, - pub players: Vec, + pub players: Vec, pub game_state: GameState, pub turn_state: TurnState, @@ -77,7 +42,7 @@ pub struct Hand { #[auto_inc] pub id: u32, - pub owner: PlayerOrBot, + pub owner: player::PlayerOrBot, pub sort: bool, pub tiles: Vec, @@ -89,7 +54,7 @@ pub struct Pond { #[auto_inc] pub id: u32, - pub owner: PlayerOrBot, + pub owner: player::PlayerOrBot, pub tiles: Vec, } diff --git a/spacetimedb/src/tables/player.rs b/spacetimedb/src/tables/player.rs new file mode 100644 index 0000000..0f580df --- /dev/null +++ b/spacetimedb/src/tables/player.rs @@ -0,0 +1,40 @@ +use spacetimedb::Identity; +use spacetimedb::{SpacetimeType, table}; + +#[derive(Debug)] +#[table(name = player, public)] +pub struct Player { + #[primary_key] + pub identity: Identity, + + #[unique] + #[auto_inc] + pub id: u32, + + pub name: Option, + + #[index(btree)] + pub lobby_id: u32, + pub hand_id: u32, + pub pond_id: u32, + + pub ready: bool, +} + +#[table(name = bot)] +pub struct Bot { + #[primary_key] + #[auto_inc] + pub id: u32, + + #[index(btree)] + pub lobby_id: u32, + pub hand_id: u32, + pub pond_id: u32, +} + +#[derive(Debug, Clone, SpacetimeType)] +pub enum PlayerOrBot { + Player { id: u32 }, + Bot { id: u32 }, +}