skip_calls, discard drawn works

This commit is contained in:
Tao Tien 2026-02-13 08:16:41 -08:00
parent 8c4132e628
commit b6e7635122
16 changed files with 222 additions and 59 deletions

View file

@ -40,44 +40,3 @@ pub fn new_shuffled_wall(ctx: &ReducerContext) -> Vec<DbTile> {
wall
}
// TODO make sure this can't be called or just error here?
#[reducer]
pub fn discard_tile(ctx: &ReducerContext, tile_id: u32) -> Result<(), String> {
trace!("discard_tile");
let mut player = ctx.db.player().identity().find(ctx.sender).unwrap();
let mut lobby = ctx.db.lobby().id().find(player.lobby_id).unwrap();
let tile = if let Some(drawn) = player.drawn_tile
&& drawn.id == tile_id
{
player.hand.push(drawn);
// lobby.dealt_idx = -1;
drawn
} else if let Some((i, &hand)) = player
.hand
.iter()
.enumerate()
.find(|(_, t)| t.id == tile_id)
{
player.hand.remove(i);
// lobby.dealt_idx = 0;
hand
} else {
return Err(format!(
"player {} attempted to deal nonexistant tile {}",
player.id, tile_id
));
};
player.drawn_tile = None;
lobby.turn_state = TurnState::Discard;
ctx.db.player().id().update(player);
ctx.db.lobby().id().update(lobby);
Ok(())
}