2026-02-11 01:18:24 -08:00
|
|
|
use spacetimedb::{Filter, Identity, SpacetimeType, client_visibility_filter, table};
|
2026-02-08 23:47:57 -08:00
|
|
|
|
|
|
|
|
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<String>,
|
|
|
|
|
|
|
|
|
|
#[index(btree)]
|
|
|
|
|
pub lobby_id: u32,
|
|
|
|
|
pub hand_id: u32,
|
|
|
|
|
pub pond_id: u32,
|
2026-02-10 19:38:41 -08:00
|
|
|
|
|
|
|
|
pub ready: bool,
|
2026-02-08 23:47:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[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 },
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
#[table(name = lobby, public)]
|
|
|
|
|
pub struct Lobby {
|
|
|
|
|
#[primary_key]
|
|
|
|
|
#[auto_inc]
|
|
|
|
|
pub id: u32,
|
|
|
|
|
|
|
|
|
|
#[unique]
|
|
|
|
|
pub host_player_id: u32,
|
|
|
|
|
pub players: Vec<PlayerOrBot>,
|
|
|
|
|
|
|
|
|
|
pub game_state: GameState,
|
2026-02-10 01:40:13 -08:00
|
|
|
pub turn_state: TurnState,
|
2026-02-08 23:47:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[table(name = wall)]
|
|
|
|
|
pub struct Wall {
|
|
|
|
|
#[primary_key]
|
|
|
|
|
pub lobby_id: u32,
|
|
|
|
|
|
|
|
|
|
pub tiles: Vec<Tile>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-11 01:18:24 -08:00
|
|
|
// TODO temp use deprecated RLS instead of view until bevy_spacetimedb supp is better
|
|
|
|
|
#[client_visibility_filter]
|
|
|
|
|
const HAND_FILTER: Filter = Filter::Sql(
|
|
|
|
|
"SELECT h.* FROM hand h
|
|
|
|
|
JOIN player p ON h.id = p.hand_id
|
|
|
|
|
WHERE p.identity = :sender",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
#[table(name = hand, public)]
|
2026-02-08 23:47:57 -08:00
|
|
|
pub struct Hand {
|
|
|
|
|
#[primary_key]
|
|
|
|
|
#[auto_inc]
|
|
|
|
|
pub id: u32,
|
|
|
|
|
|
|
|
|
|
pub owner: PlayerOrBot,
|
|
|
|
|
|
|
|
|
|
pub sort: bool,
|
|
|
|
|
pub tiles: Vec<Tile>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[table(name = pond, public)]
|
|
|
|
|
pub struct Pond {
|
|
|
|
|
#[primary_key]
|
|
|
|
|
#[auto_inc]
|
|
|
|
|
pub id: u32,
|
|
|
|
|
|
|
|
|
|
pub owner: PlayerOrBot,
|
|
|
|
|
|
|
|
|
|
pub tiles: Vec<Tile>,
|
|
|
|
|
}
|