integrate

This commit is contained in:
Tao Tien 2026-02-07 22:45:43 -08:00
parent 004aafd4ba
commit 655123b055
37 changed files with 765 additions and 1385 deletions

View file

@ -2,29 +2,55 @@ use spacetimedb::{rand::seq::SliceRandom, reducer, table, Identity, ReducerConte
use jong_types::*;
#[table(name = player, public)]
#[table(name = player)]
pub struct Player {
#[primary_key]
identity: Identity,
name: Option<String>,
lobby_id: u32,
}
#[table(name = lobby, public)]
pub struct Lobby {
#[primary_key]
#[auto_inc]
id: u32,
name: Option<String>,
host: bool,
host: Identity,
}
#[table(name = wall)]
pub struct Wall {
#[primary_key]
#[auto_inc]
id: u32,
tiles: Vec<Tile>,
}
#[table(name = hand)]
pub struct Hand {
player_id: u32,
#[primary_key]
player_ident: Identity,
tiles: Vec<Tile>,
}
#[table(name = pond, public)]
pub struct Pond {
tiles: Vec<Tile>,
}
#[reducer]
pub fn add_player(ctx: &ReducerContext, name: Option<String>) {}
pub fn add_player(ctx: &ReducerContext, name: Option<String>) {
let identity = ctx.identity();
ctx.db.player().insert(Player {
identity,
name,
lobby_id: 0,
});
}
#[reducer]
pub fn set_name(ctx: &ReducerContext, name: String) -> Result<(), String> {
@ -42,12 +68,27 @@ pub fn set_name(ctx: &ReducerContext, name: String) -> Result<(), String> {
}
}
#[reducer]
pub fn join_or_create_lobby(ctx: &ReducerContext, lobby: Option<u32>) -> Result<(), String> {
let player = ctx.db.player().identity().find(ctx.sender).unwrap();
todo!()
}
#[reducer]
pub fn insert_wall(ctx: &ReducerContext, player_ids: Vec<u32>) {
let tiles: Vec<Tile> = tiles();
ctx.db.wall().insert(Wall { id: 0, tiles });
}
#[reducer]
pub fn shuffle_wall(ctx: &ReducerContext) {
let mut rng = ctx.rng();
let mut tiles: Vec<Tile> = tiles();
tiles.shuffle(&mut rng);
ctx.db.wall().insert(Wall { tiles });
todo!()
}
#[reducer]
pub fn deal_hands(ctx: &ReducerContext) {
todo!()
}
#[reducer]