From 66b3a51b8d92d1bbc72e2d1a540e3cd480205e19 Mon Sep 17 00:00:00 2001 From: Adam Doyle Date: Fri, 15 Nov 2024 21:41:21 -0500 Subject: [PATCH] wtf --- clients/leptos/src/components/game/cards.rs | 6 ++++-- .../src/components/game/views/playing.rs | 19 +++++++++++++++++-- lib/src/lib.rs | 15 +++++++++++++-- server/src/game_handler.rs | 16 ++++++++-------- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/clients/leptos/src/components/game/cards.rs b/clients/leptos/src/components/game/cards.rs index 73bdd17..9d301d4 100644 --- a/clients/leptos/src/components/game/cards.rs +++ b/clients/leptos/src/components/game/cards.rs @@ -7,8 +7,10 @@ pub fn BlackCard() -> impl IntoView { view! {
-

{game_meta().unwrap().black.0}

-

Pick: {game_meta().unwrap().black.1}

+

{game_meta().unwrap().black.unwrap().text}

+

+ Pick: {game_meta().unwrap().black.unwrap().pick} +

} diff --git a/clients/leptos/src/components/game/views/playing.rs b/clients/leptos/src/components/game/views/playing.rs index 4239b44..cf73002 100644 --- a/clients/leptos/src/components/game/views/playing.rs +++ b/clients/leptos/src/components/game/views/playing.rs @@ -48,7 +48,14 @@ pub fn PlayingView() -> impl IntoView { Effect::new(move |_| { if card_clicked() != "".to_string() && !submitted() - && submitted_cards().len() < game_state().unwrap().black.1.into() + && submitted_cards().len() + < game_state() + .unwrap() + .black + .unwrap() + .pick + .try_into() + .unwrap() { if let Some(clicked_card) = player_hand .get_untracked() @@ -86,7 +93,15 @@ pub fn PlayingView() -> impl IntoView { } }); - if submitted_cards().len() < game_state().unwrap().black.1.into() { + if submitted_cards().len() + < game_state() + .unwrap() + .black + .unwrap() + .pick + .try_into() + .unwrap() + { return; } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index b21813a..655a326 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -91,10 +91,21 @@ pub struct GameMeta { pub white_discard_count: u32, } +/// Black card meta +#[derive(Clone, Message, Serialize, Deserialize)] +pub struct BlackCardMeta { + #[prost(string, tag = "1")] + pub text: String, + #[prost(uint32, tag = "2")] + pub pick: u32, +} + /// Game state meta -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Message, Serialize, Deserialize)] pub struct GameStateMeta { - pub black: (String, u8), + #[prost(message, tag = "1")] + pub black: Option, // this has to be an option or prost gets cranky + #[prost(message, repeated, tag = "2")] pub white: Vec, } diff --git a/server/src/game_handler.rs b/server/src/game_handler.rs index 5517525..13006ff 100644 --- a/server/src/game_handler.rs +++ b/server/src/game_handler.rs @@ -251,10 +251,10 @@ impl GameHandler { for player in this_game.players.values() { // Create update for user's game view let meta = GameStateMeta { - black: ( - this_game.current_black.text.clone(), - this_game.current_black.pick, - ), + black: Some(BlackCardMeta { + text: this_game.current_black.text.clone(), + pick: this_game.current_black.pick.try_into().unwrap(), + }), white: player .white .iter() @@ -282,10 +282,10 @@ impl GameHandler { if let Some(player) = this_game.players.get(&user_id) { // Create update for user's game view let meta = GameStateMeta { - black: ( - this_game.current_black.text.clone(), - this_game.current_black.pick, - ), + black: Some(BlackCardMeta { + text: this_game.current_black.text.clone(), + pick: this_game.current_black.pick.try_into().unwrap(), + }), white: player .white .iter()