partialy draw a tile

wind assignment and turn ordering
This commit is contained in:
Tao Tien 2026-02-13 06:10:09 -08:00
parent b9c653f3a2
commit 63e21713ab
14 changed files with 189 additions and 38 deletions

View file

@ -1,9 +1,11 @@
use log::info;
use spacetimedb::{ReducerContext, Table, reducer};
use spacetimedb::{ReducerContext, Table, ViewContext, reducer, view};
use crate::tables::{player::player, *};
mod game;
mod reducers {
mod game;
}
mod tables;
#[reducer(client_connected)]
@ -20,6 +22,7 @@ pub fn login_or_add_player(ctx: &ReducerContext) {
sort: true,
hand: vec![],
pond: vec![],
drawn_tile: None,
}) {
info!("added player: {:?}", player);
} else {

View file

@ -1,11 +1,11 @@
use log::{info, trace};
use spacetimedb::{ReducerContext, Table, reducer};
use spacetimedb::{ReducerContext, Table, rand::seq::SliceRandom, reducer};
use crate::tables::{player::player, *};
use crate::tables::{player::player, wall, *};
use jong_types::*;
mod deal;
mod hand;
mod wall;
#[reducer]
pub fn join_or_create_lobby(ctx: &ReducerContext, mut lobby_id: u32) -> Result<(), String> {
@ -67,7 +67,7 @@ pub fn set_ready(ctx: &ReducerContext, ready: bool) {
let mut player = ctx.db.player().identity().find(ctx.sender).unwrap();
player.ready = ready;
let player = ctx.db.player().identity().update(player);
ctx.db.player().identity().update(player);
}
#[reducer]
@ -81,6 +81,7 @@ pub fn start_game(ctx: &ReducerContext) {
})
{
lobby.game_state = GameState::Setup;
lobby.players.shuffle(&mut ctx.rng());
ctx.db.lobby().id().update(lobby);
}
}

View file

@ -26,6 +26,19 @@ pub fn deal_hands(ctx: &ReducerContext, lobby_id: u32) {
}
}
#[reducer]
pub fn draw_tile(ctx: &ReducerContext) {
let mut player = ctx.db.player().identity().find(ctx.sender).unwrap();
let mut wall = ctx.db.wall().lobby_id().find(player.lobby_id).unwrap();
// TODO if no more tiles, exhaust somehow
player.drawn_tile = wall.tiles.pop();
ctx.db.wall().lobby_id().update(wall);
ctx.db.player().id().update(player);
}
// #[view(name = view_player_hand, public)]
// pub fn view_player_hand(ctx: &ViewContext) -> Option<Hand> {
// ctx.db

View file

@ -3,6 +3,7 @@ use spacetimedb::{SpacetimeType, table};
use super::DbTile;
// FIXME this shant be public, use views
#[table(name = player, public)]
#[derive(Debug)]
pub struct Player {
@ -23,6 +24,8 @@ pub struct Player {
pub hand: Vec<DbTile>,
pub pond: Vec<DbTile>,
pub drawn_tile: Option<DbTile>,
}
#[table(name = bot)]