From e30de2ac9e10f87341e28a4d1e6f3a1d4c2988bf Mon Sep 17 00:00:00 2001 From: Adam <24621027+adoyle0@users.noreply.github.com> Date: Thu, 29 Aug 2024 01:11:49 -0400 Subject: [PATCH] fix mismatches --- client/src/components/game/views/judging.rs | 3 ++ client/src/components/game/views/playing.rs | 55 +++++++++++++-------- client/src/components/websocket.rs | 1 + 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/client/src/components/game/views/judging.rs b/client/src/components/game/views/judging.rs index 5701f56..fc25152 100644 --- a/client/src/components/game/views/judging.rs +++ b/client/src/components/game/views/judging.rs @@ -10,6 +10,7 @@ pub fn JudgingView() -> impl IntoView { let websocket = expect_context::(); let game_meta = expect_context::>>(); let judge_round = expect_context::>>(); + let set_judge_round = expect_context::>>(); // Signals let (selected_cards, set_selected_cards) = create_signal::>(vec![]); @@ -78,6 +79,8 @@ pub fn JudgingView() -> impl IntoView { set_selected_cards.update(|list| { list.clear(); }); + + set_judge_round(None); }; view! { diff --git a/client/src/components/game/views/playing.rs b/client/src/components/game/views/playing.rs index 29f94b3..e1cf0cb 100644 --- a/client/src/components/game/views/playing.rs +++ b/client/src/components/game/views/playing.rs @@ -13,7 +13,9 @@ pub fn PlayingView() -> impl IntoView { // Signals let (selected_cards, set_selected_cards) = create_signal::>(vec![]); + let (submitted_cards, set_submitted_cards) = create_signal::>(vec![]); let (card_clicked, set_card_clicked) = create_signal::(String::new()); + let (submitted, set_submitted) = create_signal(false); let (player_hand, set_player_hand) = create_signal::>(HashMap::new()); @@ -34,32 +36,37 @@ pub fn PlayingView() -> impl IntoView { set_selected_cards.update(|list| { list.clear(); }); + set_submitted_cards.update(|list| { + list.clear(); + }); + set_submitted(false); }); - // Card selection // + // Card selection // Toggle selected status of cards create_effect(move |_| { - if card_clicked() != "".to_string() { - if !selected_cards.get_untracked().contains( - player_hand - .get_untracked() - .get(&card_clicked.get_untracked()) - .unwrap(), - ) { - set_selected_cards - .update(|cards| cards.push(player_hand().get(&card_clicked()).unwrap().clone())) - } else if selected_cards + if card_clicked() != "".to_string() + && submitted_cards().len() < game_meta().unwrap().black.1.into() + { + if let Some(clicked_card) = player_hand .get_untracked() - .contains(player_hand.get_untracked().get(&card_clicked()).unwrap()) + .get(&card_clicked.get_untracked()) { - set_selected_cards.update(|cards| { - cards.remove( - cards - .iter() - .position(|card| card == player_hand().get(&card_clicked()).unwrap()) - .unwrap(), + if !selected_cards.get_untracked().contains(clicked_card) { + set_selected_cards.update(|cards| cards.push(clicked_card.to_owned())) + } else if selected_cards.get_untracked().contains(clicked_card) + && !submitted_cards.get_untracked().contains(clicked_card) + { + logging::log!( + "{:#?}\n{:#?}\n{:#?}", + clicked_card, + selected_cards(), + submitted_cards() ); - }) + set_selected_cards.update(|cards| { + cards.remove(cards.iter().position(|card| card == clicked_card).unwrap()); + }) + } } // Clear the signal otherwise it selects the last selected card again set_card_clicked.update_untracked(|value| value.clear()); @@ -77,10 +84,15 @@ pub fn PlayingView() -> impl IntoView { }) .unwrap(); + set_submitted_cards.update_untracked(|cards| { + cards.extend(selected_cards.get_untracked()); + }); + websocket.send(&msg); - set_selected_cards.update(|list| { + set_selected_cards.update_untracked(|list| { list.clear(); }); + set_submitted(true); }; view! { @@ -111,12 +123,13 @@ pub fn PlayingView() -> impl IntoView { key=move |card| card.uuid.clone() children=move |card| { view! { - // Hide cards from hand view when they exist as selected + // Hide cards from hand view when they exist as selected or submitted impl IntoView { provide_context::>>(user_update); provide_context::>>(chat_update); provide_context::>>(judge_round); + provide_context::>>(set_judge_round); provide_context::>>(chat_message); provide_context::>>(active_games); provide_context::>>(current_game);