separate submit/judge
This commit is contained in:
parent
55b14944a7
commit
db180a66ed
2 changed files with 29 additions and 31 deletions
|
@ -9,6 +9,11 @@ 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>>>();
|
||||
|
@ -61,9 +66,6 @@ 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 {
|
||||
|
@ -148,33 +150,24 @@ pub fn Game() -> impl IntoView {
|
|||
}
|
||||
});
|
||||
|
||||
let submit_cards = move |_| {
|
||||
let tx = websocket.clone();
|
||||
judge_round.with(move |judge| {
|
||||
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 {
|
||||
let submit_move = move |_| {
|
||||
let msg = to_string(&PlayerMoveRequest {
|
||||
game_id: game_id(),
|
||||
card_ids: selected_cards_ordered(),
|
||||
})
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
.unwrap();
|
||||
|
||||
if let Some(msg) = _message {
|
||||
tx.send(&msg);
|
||||
}
|
||||
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! {
|
||||
|
@ -232,10 +225,15 @@ pub fn Game() -> impl IntoView {
|
|||
/>
|
||||
</div>
|
||||
<div class="w-full inline-flex flex-wrap justify-center">
|
||||
<button type="button" on:click=submit_cards>
|
||||
<button type="button" on:click=submit_move>
|
||||
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">
|
||||
|
|
|
@ -8,7 +8,7 @@ pub struct JudgeDecisionRequest {
|
|||
}
|
||||
|
||||
/// Judge round
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct JudgeRound {
|
||||
pub cards_to_judge: Vec<Vec<WhiteCardMeta>>,
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue