Compare commits
No commits in common. "1da5606dd6e9237fc255a92eb5420986f10e7047" and "55b14944a7d912e63940c3b7e39033321a501163" have entirely different histories.
1da5606dd6
...
55b14944a7
3 changed files with 33 additions and 35 deletions
|
@ -9,11 +9,6 @@ use std::collections::HashMap;
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Game() -> impl IntoView {
|
pub fn Game() -> impl IntoView {
|
||||||
let websocket = expect_context::<WebSocketContext>();
|
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 connected = move || websocket.ready_state.get() == ConnectionReadyState::Open;
|
||||||
let game_meta = expect_context::<ReadSignal<Option<GameStateMeta>>>();
|
let game_meta = expect_context::<ReadSignal<Option<GameStateMeta>>>();
|
||||||
let judge_round = expect_context::<ReadSignal<Option<JudgeRound>>>();
|
let judge_round = expect_context::<ReadSignal<Option<JudgeRound>>>();
|
||||||
|
@ -66,6 +61,9 @@ pub fn Game() -> impl IntoView {
|
||||||
set_card_clicked.update(|list| {
|
set_card_clicked.update(|list| {
|
||||||
list.clear();
|
list.clear();
|
||||||
});
|
});
|
||||||
|
set_selected_cards_ordered.update(|list| {
|
||||||
|
list.clear();
|
||||||
|
});
|
||||||
|
|
||||||
// Load hand
|
// Load hand
|
||||||
if let Some(judge) = judge_round {
|
if let Some(judge) = judge_round {
|
||||||
|
@ -150,24 +148,33 @@ pub fn Game() -> impl IntoView {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let submit_move = move |_| {
|
let submit_cards = move |_| {
|
||||||
let msg = to_string(&PlayerMoveRequest {
|
let tx = websocket.clone();
|
||||||
game_id: game_id(),
|
judge_round.with(move |judge| {
|
||||||
card_ids: selected_cards_ordered(),
|
let mut _message: Option<String> = None;
|
||||||
|
|
||||||
|
if judge.is_some() {
|
||||||
|
_message = Some(
|
||||||
|
to_string(&JudgeDecisionRequest {
|
||||||
|
game_id: game_id(),
|
||||||
|
winning_cards: selected_cards_ordered(),
|
||||||
|
})
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
_message = Some(
|
||||||
|
to_string(&PlayerMoveRequest {
|
||||||
|
game_id: game_id(),
|
||||||
|
card_ids: selected_cards_ordered(),
|
||||||
|
})
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(msg) = _message {
|
||||||
|
tx.send(&msg);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
set_websocket_send(msg);
|
|
||||||
};
|
|
||||||
|
|
||||||
let submit_judge = move |_| {
|
|
||||||
let msg = to_string(&JudgeDecisionRequest {
|
|
||||||
game_id: game_id(),
|
|
||||||
winning_cards: selected_cards_ordered(),
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
set_websocket_send(msg);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
|
@ -225,15 +232,10 @@ pub fn Game() -> impl IntoView {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full inline-flex flex-wrap justify-center">
|
<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
|
Submit
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full inline-flex flex-wrap justify-center">
|
|
||||||
<button type="button" on:click=submit_judge>
|
|
||||||
Judge
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
// Player cards
|
// Player cards
|
||||||
<div class="inline-flex flex-wrap justify-center">
|
<div class="inline-flex flex-wrap justify-center">
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub struct JudgeDecisionRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Judge round
|
/// Judge round
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct JudgeRound {
|
pub struct JudgeRound {
|
||||||
pub cards_to_judge: Vec<Vec<WhiteCardMeta>>,
|
pub cards_to_judge: Vec<Vec<WhiteCardMeta>>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,13 +148,9 @@ impl Game {
|
||||||
tracing::debug!("Player is czar");
|
tracing::debug!("Player is czar");
|
||||||
Err("You can't submit cards to judge, you ARE the judge!".to_string())
|
Err("You can't submit cards to judge, you ARE the judge!".to_string())
|
||||||
} else {
|
} 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
|
// Ignore extra cards
|
||||||
let trimmed = request.card_ids[..self.current_black.pick.into()].to_vec();
|
let trimmed = request.card_ids[..self.current_black.pick.into()].to_vec();
|
||||||
|
// TODO: handle not enough cards
|
||||||
tracing::debug!("Trimmed: {:#?}", trimmed);
|
tracing::debug!("Trimmed: {:#?}", trimmed);
|
||||||
|
|
||||||
// Move card from player's hand to judge pile
|
// Move card from player's hand to judge pile
|
||||||
|
@ -247,7 +243,7 @@ impl Game {
|
||||||
tracing::debug!("{:#?}", self.rotation);
|
tracing::debug!("{:#?}", self.rotation);
|
||||||
tracing::debug!("{:#?}", self.rotation_index);
|
tracing::debug!("{:#?}", self.rotation_index);
|
||||||
// Choose new czar
|
// Choose new czar
|
||||||
if self.rotation_index == self.rotation.len() - 1 {
|
if self.rotation_index == self.rotation.len() {
|
||||||
self.rotation_index = 0;
|
self.rotation_index = 0;
|
||||||
} else {
|
} else {
|
||||||
self.rotation_index += 1;
|
self.rotation_index += 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue