partialy draw a tile
wind assignment and turn ordering
This commit is contained in:
parent
b9c653f3a2
commit
63e21713ab
14 changed files with 189 additions and 38 deletions
|
|
@ -1,42 +0,0 @@
|
|||
use log::debug;
|
||||
use spacetimedb::{ReducerContext, Table, rand::seq::SliceRandom, reducer};
|
||||
|
||||
use super::hand::deal_hands;
|
||||
use crate::tables::*;
|
||||
use jong_types::*;
|
||||
|
||||
#[reducer]
|
||||
pub fn shuffle_deal(ctx: &ReducerContext, lobby_id: u32) {
|
||||
debug!("lobby_id: {lobby_id}");
|
||||
let mut lobby = ctx.db.lobby().id().find(lobby_id).unwrap();
|
||||
|
||||
if lobby.game_state == GameState::Setup {
|
||||
lobby.game_state = GameState::Deal;
|
||||
lobby = ctx.db.lobby().id().update(lobby);
|
||||
|
||||
let tiles = new_shuffled_wall(ctx);
|
||||
|
||||
ctx.db.wall().insert(DbWall {
|
||||
// id: 0,
|
||||
lobby_id,
|
||||
tiles,
|
||||
});
|
||||
|
||||
deal_hands(ctx, lobby_id);
|
||||
|
||||
lobby.game_state = GameState::Play;
|
||||
lobby.turn_state = TurnState::Tsumo;
|
||||
ctx.db.lobby().id().update(lobby);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_shuffled_wall(ctx: &ReducerContext) -> Vec<DbTile> {
|
||||
let mut rng = ctx.rng();
|
||||
let mut wall: Vec<_> = tiles()
|
||||
.into_iter()
|
||||
.map(|tile| ctx.db.tile().insert(DbTile { id: 0, tile }))
|
||||
.collect();
|
||||
wall.shuffle(&mut rng);
|
||||
|
||||
wall
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue