This commit is contained in:
Adam 2024-11-15 21:41:21 -05:00
parent 59214e4d12
commit 66b3a51b8d
4 changed files with 42 additions and 14 deletions

View file

@ -7,8 +7,10 @@ pub fn BlackCard() -> impl IntoView {
view! { view! {
<Show when=move || { game_meta().is_some() }> <Show when=move || { game_meta().is_some() }>
<div class="relative m-2 w-36 h-56 shrink-0 text-white bg-black rounded-lg shadow-black shadow-md"> <div class="relative m-2 w-36 h-56 shrink-0 text-white bg-black rounded-lg shadow-black shadow-md">
<p class="p-4">{game_meta().unwrap().black.0}</p> <p class="p-4">{game_meta().unwrap().black.unwrap().text}</p>
<p class="absolute right-4 bottom-4">Pick: {game_meta().unwrap().black.1}</p> <p class="absolute right-4 bottom-4">
Pick: {game_meta().unwrap().black.unwrap().pick}
</p>
</div> </div>
</Show> </Show>
} }

View file

@ -48,7 +48,14 @@ pub fn PlayingView() -> impl IntoView {
Effect::new(move |_| { Effect::new(move |_| {
if card_clicked() != "".to_string() if card_clicked() != "".to_string()
&& !submitted() && !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 if let Some(clicked_card) = player_hand
.get_untracked() .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; return;
} }

View file

@ -91,10 +91,21 @@ pub struct GameMeta {
pub white_discard_count: u32, 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 /// Game state meta
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Message, Serialize, Deserialize)]
pub struct GameStateMeta { pub struct GameStateMeta {
pub black: (String, u8), #[prost(message, tag = "1")]
pub black: Option<BlackCardMeta>, // this has to be an option or prost gets cranky
#[prost(message, repeated, tag = "2")]
pub white: Vec<WhiteCardMeta>, pub white: Vec<WhiteCardMeta>,
} }

View file

@ -251,10 +251,10 @@ impl GameHandler {
for player in this_game.players.values() { for player in this_game.players.values() {
// Create update for user's game view // Create update for user's game view
let meta = GameStateMeta { let meta = GameStateMeta {
black: ( black: Some(BlackCardMeta {
this_game.current_black.text.clone(), text: this_game.current_black.text.clone(),
this_game.current_black.pick, pick: this_game.current_black.pick.try_into().unwrap(),
), }),
white: player white: player
.white .white
.iter() .iter()
@ -282,10 +282,10 @@ impl GameHandler {
if let Some(player) = this_game.players.get(&user_id) { if let Some(player) = this_game.players.get(&user_id) {
// Create update for user's game view // Create update for user's game view
let meta = GameStateMeta { let meta = GameStateMeta {
black: ( black: Some(BlackCardMeta {
this_game.current_black.text.clone(), text: this_game.current_black.text.clone(),
this_game.current_black.pick, pick: this_game.current_black.pick.try_into().unwrap(),
), }),
white: player white: player
.white .white
.iter() .iter()