jong/spacetimedb/src/tables.rs

96 lines
1.6 KiB
Rust
Raw Normal View History

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<String>,
#[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<PlayerOrBot>,
pub game_state: GameState,
2026-02-10 01:40:13 -08:00
pub turn_state: TurnState,
}
#[table(name = wall)]
pub struct Wall {
#[primary_key]
pub lobby_id: u32,
pub tiles: Vec<Tile>,
}
// 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<Tile>,
}
#[table(name = pond, public)]
pub struct Pond {
#[primary_key]
#[auto_inc]
pub id: u32,
pub owner: PlayerOrBot,
pub tiles: Vec<Tile>,
}