hack for player-lobby and Res<Player> race?
This commit is contained in:
parent
9f6a5b6423
commit
47735931b4
34 changed files with 536 additions and 1340 deletions
36
spacetimedb/src/game/wall.rs
Normal file
36
spacetimedb/src/game/wall.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
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();
|
||||
|
||||
lobby.game_state = GameState::Deal;
|
||||
let mut lobby = ctx.db.lobby().id().update(lobby);
|
||||
|
||||
|
||||
let tiles = new_shuffled_wall(ctx);
|
||||
ctx.db.wall().insert(Wall {
|
||||
// id: 0,
|
||||
lobby_id,
|
||||
tiles,
|
||||
});
|
||||
|
||||
deal_hands(ctx, lobby_id);
|
||||
|
||||
lobby.game_state = GameState::Play;
|
||||
ctx.db.lobby().id().update(lobby);
|
||||
}
|
||||
|
||||
pub fn new_shuffled_wall(ctx: &ReducerContext) -> Vec<Tile> {
|
||||
let mut rng = ctx.rng();
|
||||
let mut wall = tiles();
|
||||
wall.shuffle(&mut rng);
|
||||
|
||||
wall
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue