Compare commits

..

No commits in common. "1da5606dd6e9237fc255a92eb5420986f10e7047" and "55b14944a7d912e63940c3b7e39033321a501163" have entirely different histories.

3 changed files with 33 additions and 35 deletions

View file

@ -9,11 +9,6 @@ use std::collections::HashMap;
#[component]
pub fn Game() -> impl IntoView {
let websocket = expect_context::<WebSocketContext>();
let tx = websocket.clone();
let (websocket_send, set_websocket_send) = create_signal("".to_string());
create_effect(move |_| {
tx.send(&websocket_send());
});
let connected = move || websocket.ready_state.get() == ConnectionReadyState::Open;
let game_meta = expect_context::<ReadSignal<Option<GameStateMeta>>>();
let judge_round = expect_context::<ReadSignal<Option<JudgeRound>>>();
@ -66,6 +61,9 @@ pub fn Game() -> impl IntoView {
set_card_clicked.update(|list| {
list.clear();
});
set_selected_cards_ordered.update(|list| {
list.clear();
});
// Load hand
if let Some(judge) = judge_round {
@ -150,24 +148,33 @@ pub fn Game() -> impl IntoView {
}
});
let submit_move = move |_| {
let msg = to_string(&PlayerMoveRequest {
game_id: game_id(),
card_ids: selected_cards_ordered(),
})
.unwrap();
let submit_cards = move |_| {
let tx = websocket.clone();
judge_round.with(move |judge| {
let mut _message: Option<String> = None;
set_websocket_send(msg);
};
let submit_judge = move |_| {
let msg = to_string(&JudgeDecisionRequest {
if judge.is_some() {
_message = Some(
to_string(&JudgeDecisionRequest {
game_id: game_id(),
winning_cards: selected_cards_ordered(),
})
.unwrap();
.unwrap(),
);
} else {
_message = Some(
to_string(&PlayerMoveRequest {
game_id: game_id(),
card_ids: selected_cards_ordered(),
})
.unwrap(),
);
}
set_websocket_send(msg);
if let Some(msg) = _message {
tx.send(&msg);
}
})
};
view! {
@ -225,15 +232,10 @@ pub fn Game() -> impl IntoView {
/>
</div>
<div class="w-full inline-flex flex-wrap justify-center">
<button type="button" on:click=submit_move>
<button type="button" on:click=submit_cards>
Submit
</button>
</div>
<div class="w-full inline-flex flex-wrap justify-center">
<button type="button" on:click=submit_judge>
Judge
</button>
</div>
// Player cards
<div class="inline-flex flex-wrap justify-center">

View file

@ -8,7 +8,7 @@ pub struct JudgeDecisionRequest {
}
/// Judge round
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub struct JudgeRound {
pub cards_to_judge: Vec<Vec<WhiteCardMeta>>,
}

View file

@ -148,13 +148,9 @@ impl Game {
tracing::debug!("Player is czar");
Err("You can't submit cards to judge, you ARE the judge!".to_string())
} else {
// Error if not enough cards
if request.card_ids.len() < self.current_black.pick.into() {
return Err("You didn't pick enough cards!".to_string());
}
// Ignore extra cards
let trimmed = request.card_ids[..self.current_black.pick.into()].to_vec();
// TODO: handle not enough cards
tracing::debug!("Trimmed: {:#?}", trimmed);
// Move card from player's hand to judge pile
@ -247,7 +243,7 @@ impl Game {
tracing::debug!("{:#?}", self.rotation);
tracing::debug!("{:#?}", self.rotation_index);
// Choose new czar
if self.rotation_index == self.rotation.len() - 1 {
if self.rotation_index == self.rotation.len() {
self.rotation_index = 0;
} else {
self.rotation_index += 1;