cont... some query invariant isn't upheld once enter lobby, crashes
This commit is contained in:
parent
cc07cc89c6
commit
550ae73287
5 changed files with 243 additions and 136 deletions
|
|
@ -140,36 +140,37 @@ pub struct HandView {
|
|||
#[view(name = view_closed_hands, public)]
|
||||
fn view_closed_hands(ctx: &ViewContext) -> Vec<HandView> {
|
||||
let this_player = ctx.db.player().identity().find(ctx.sender).unwrap();
|
||||
ctx.db
|
||||
.lobby()
|
||||
.id()
|
||||
.find(this_player.lobby_id)
|
||||
.unwrap()
|
||||
.players
|
||||
.iter()
|
||||
.filter_map(|&player| {
|
||||
let (hand_length, drawn) = match player {
|
||||
if let Some(lobby) = ctx.db.lobby().id().find(this_player.lobby_id) {
|
||||
lobby
|
||||
.players
|
||||
.iter()
|
||||
.filter_map(|&player| match player {
|
||||
PlayerOrBot::Player { id } => {
|
||||
let player_hand = ctx.db.player_hand().player_id().find(id).unwrap();
|
||||
(
|
||||
player_hand.hand.len() as u8,
|
||||
player_hand.turn_state == TurnState::Tsumo
|
||||
&& player_hand.working_tile.is_some(),
|
||||
)
|
||||
if let Some(player_hand) = ctx.db.player_hand().player_id().find(id) {
|
||||
Some(HandView {
|
||||
player,
|
||||
hand_length: player_hand.hand.len() as u8,
|
||||
drawn: player_hand.turn_state == TurnState::Tsumo
|
||||
&& player_hand.working_tile.is_some(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
PlayerOrBot::Bot { id } => {
|
||||
let bot = ctx.db.bot().id().find(id).unwrap();
|
||||
(
|
||||
bot.hand.len() as u8,
|
||||
bot.turn_state == TurnState::Tsumo && bot.working_tile.is_some(),
|
||||
)
|
||||
if let Some(bot) = ctx.db.bot().id().find(id) {
|
||||
Some(HandView {
|
||||
player,
|
||||
hand_length: bot.hand.len() as u8,
|
||||
drawn: bot.turn_state == TurnState::Tsumo && bot.working_tile.is_some(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
Some(HandView {
|
||||
player,
|
||||
hand_length,
|
||||
drawn,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
.collect()
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue