discarding proper now

This commit is contained in:
Tao Tien 2026-02-19 00:00:26 -08:00
parent c3686221aa
commit 875c3fb5bb
7 changed files with 45 additions and 40 deletions

View file

@ -46,17 +46,33 @@ pub fn discard_tile(ctx: &ReducerContext, tile_id: u32) -> Result<(), String> {
let mut player = ctx.db.player().identity().find(ctx.sender).unwrap();
let mut lobby = ctx.db.lobby().id().find(player.lobby_id).unwrap();
let dealt_tile = if let Some(drawn) = player.drawn_tile
&& drawn.id == tile_id
{
drawn
} else if let Some((i, _)) = player
.hand
.iter()
.enumerate()
.find(|(_, t)| t.id == tile_id)
{
player.hand.remove(i)
let dealt_tile = if let Some(dealt) = ctx.db.tile().id().find(tile_id) {
if let Some(drawn) = player.drawn_tile {
if drawn.id == dealt.id {
dealt
} else if let Some((i, _)) = player
.hand
.iter()
.enumerate()
.find(|(_, t)| t.id == tile_id)
{
let dealt = player.hand.remove(i);
player.hand.push(drawn);
player.hand.sort_by_key(|t| t.tile);
dealt
} else {
return Err(format!(
"player {} attempted to deal tile {} not in hand or drawn",
player.id, tile_id
));
}
} else {
return Err(format!(
"player {} attempted to deal tile {} without having drawn",
player.id, tile_id
));
}
} else {
return Err(format!(
"player {} attempted to deal nonexistant tile {}",