use spacetimedb::{Filter, Identity, 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 }, } #[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, pub game_state: GameState, pub turn_state: TurnState, } #[table(name = wall)] pub struct Wall { #[primary_key] pub lobby_id: u32, pub tiles: Vec, } // 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)] pub struct Hand { #[primary_key] #[auto_inc] pub id: u32, pub owner: PlayerOrBot, pub sort: bool, pub tiles: Vec, } #[table(name = pond, public)] pub struct Pond { #[primary_key] #[auto_inc] pub id: u32, pub owner: PlayerOrBot, pub tiles: Vec, }