fix mismatches
This commit is contained in:
parent
791651a9da
commit
e30de2ac9e
3 changed files with 38 additions and 21 deletions
|
@ -10,6 +10,7 @@ pub fn JudgingView() -> impl IntoView {
|
|||
let websocket = expect_context::<WebSocketContext>();
|
||||
let game_meta = expect_context::<ReadSignal<Option<GameStateMeta>>>();
|
||||
let judge_round = expect_context::<ReadSignal<Option<JudgeRound>>>();
|
||||
let set_judge_round = expect_context::<WriteSignal<Option<JudgeRound>>>();
|
||||
|
||||
// Signals
|
||||
let (selected_cards, set_selected_cards) = create_signal::<Vec<WhiteCardMeta>>(vec![]);
|
||||
|
@ -78,6 +79,8 @@ pub fn JudgingView() -> impl IntoView {
|
|||
set_selected_cards.update(|list| {
|
||||
list.clear();
|
||||
});
|
||||
|
||||
set_judge_round(None);
|
||||
};
|
||||
|
||||
view! {
|
||||
|
|
|
@ -13,7 +13,9 @@ pub fn PlayingView() -> impl IntoView {
|
|||
|
||||
// Signals
|
||||
let (selected_cards, set_selected_cards) = create_signal::<Vec<WhiteCardMeta>>(vec![]);
|
||||
let (submitted_cards, set_submitted_cards) = create_signal::<Vec<WhiteCardMeta>>(vec![]);
|
||||
let (card_clicked, set_card_clicked) = create_signal::<String>(String::new());
|
||||
let (submitted, set_submitted) = create_signal(false);
|
||||
let (player_hand, set_player_hand) =
|
||||
create_signal::<HashMap<String, WhiteCardMeta>>(HashMap::new());
|
||||
|
||||
|
@ -34,33 +36,38 @@ 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
|
||||
if card_clicked() != "".to_string()
|
||||
&& submitted_cards().len() < game_meta().unwrap().black.1.into()
|
||||
{
|
||||
if let Some(clicked_card) = 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
|
||||
.get_untracked()
|
||||
.contains(player_hand.get_untracked().get(&card_clicked()).unwrap())
|
||||
{
|
||||
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
|
||||
<Show when={
|
||||
let id = card.uuid.clone();
|
||||
move || {
|
||||
if let Some(card) = player_hand().get(&id) {
|
||||
!selected_cards().contains(card)
|
||||
&& !submitted_cards().contains(card)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ pub fn Websocket() -> impl IntoView {
|
|||
provide_context::<ReadSignal<Option<UserUpdate>>>(user_update);
|
||||
provide_context::<ReadSignal<Option<ChatUpdate>>>(chat_update);
|
||||
provide_context::<ReadSignal<Option<JudgeRound>>>(judge_round);
|
||||
provide_context::<WriteSignal<Option<JudgeRound>>>(set_judge_round);
|
||||
provide_context::<ReadSignal<Option<ChatMessage>>>(chat_message);
|
||||
provide_context::<ReadSignal<Vec<GameBrowserMeta>>>(active_games);
|
||||
provide_context::<ReadSignal<Option<GameStateMeta>>>(current_game);
|
||||
|
|
Loading…
Add table
Reference in a new issue