diff --git a/client/src/components/game.rs b/client/src/components/game.rs index 3b0961c..50514d9 100644 --- a/client/src/components/game.rs +++ b/client/src/components/game.rs @@ -9,11 +9,19 @@ pub fn Game() -> impl IntoView { let (game_name, set_game_name) = create_signal("".to_string()); let (game_host, set_game_host) = create_signal("".to_string()); + let (game_players, set_game_players) = create_signal(vec![]); + let (game_czar, set_game_czar) = create_signal("".to_string()); + let (game_black, set_game_black) = create_signal("".to_string()); + let (game_white, set_game_white) = create_signal(vec![]); create_effect(move |_| { if let Some(game) = game_meta() { - set_game_name(game.name.clone()) - set_game_name(game.host.clone()) + set_game_name(game.name.clone()); + set_game_host(game.host.clone()); + set_game_players(game.players.clone()); + set_game_czar(game.czar.clone()); + set_game_black(game.black.clone()); + set_game_white(game.white.clone()); } }); @@ -21,11 +29,11 @@ pub fn Game() -> impl IntoView {

Game

Name: {move || game_name}

-

Host:

-

Players:

-

Czar:

-

Black Card:

-

Your Cards:

+

Host: {move || game_host}

+

Players: {move || game_players}

+

Czar: {move || game_czar}

+

Black Card: {move || game_black}

+

Your Cards: {move || game_white}

} } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 06ff978..02a2fc8 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -4,11 +4,11 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct GameMeta { pub name: String, - // pub host: String, - // pub players: Vec, - // pub czar: String, - // pub black: String, - // pub white: Vec, + pub host: String, + pub players: Vec, + pub czar: String, + pub black: String, + pub white: Vec, } /// Card Pack Meta diff --git a/server/src/game_handler.rs b/server/src/game_handler.rs index 025e7b7..cb84873 100644 --- a/server/src/game_handler.rs +++ b/server/src/game_handler.rs @@ -8,7 +8,7 @@ use lib::*; use std::net::SocketAddr; use std::sync::{Arc, RwLock}; -/// Handle incoming messages over the WebSocket +// This file is disgusting, don't look at it pub enum GameHandlerMessage { NewGame { @@ -62,7 +62,6 @@ impl GameHandler { // create game if let Ok(new_game_object) = Game::new(manifest) { - tracing::debug!("{:#?}", &new_game_object); let tx = self .state .online_users @@ -75,30 +74,36 @@ impl GameHandler { .tx .clone(); - tx.send( - serde_json::to_string(&GameMeta { - name: new_game_object.name.clone(), - // host: new_game_object.host.read().unwrap().name.clone(), - // players: new_game_object - // .players - // .iter() - // .map(|player| player.user.read().unwrap().name) - // .collect(), - // czar: new_game_object.host.read().unwrap().name.clone(), - // black: new_game_object - // .current_black - // .clone() - // .unwrap() - // .text - // .clone() - // .to_string() - // .clone(), - // white: new_game_object.white.iter().map(|card| card.text).collect(), - }) - .unwrap(), - ) - .await - .unwrap(); + tracing::debug!("{:#?}", &new_game_object); + + let mut black_text = "Error".to_string(); + if let Some(ref current_black) = new_game_object.current_black { + black_text = current_black.text.to_owned() + } + + tracing::debug!("{:#?}", &new_game_object.white); + + let meta = GameMeta { + name: new_game_object.name.clone(), + host: new_game_object.host.read().unwrap().name.clone(), + players: new_game_object + .players + .iter() + .map(|player| player.user.read().unwrap().name.clone()) + .collect(), + czar: new_game_object.host.read().unwrap().name.clone(), + black: black_text, + white: new_game_object + .white + .iter() + .map(|card| card.text.clone()) + .collect(), + }; + + tracing::debug!("{:#?}", &meta); + tx.send(serde_json::to_string(&meta).unwrap()) + .await + .unwrap(); self.state.games.write().unwrap().insert( new_game_object.name.clone(), Arc::new(RwLock::new(new_game_object)), diff --git a/server/src/message_handler.rs b/server/src/message_handler.rs index 3cc6f02..20b5915 100644 --- a/server/src/message_handler.rs +++ b/server/src/message_handler.rs @@ -7,7 +7,8 @@ use serde_json::{from_str, to_string}; use std::net::SocketAddr; use std::sync::Arc; -/// Handle incoming messages over the WebSocket +// Handle incoming messages over the WebSocket, and probably do more than we should. +// Also with lots of unwrapping pub struct MessageHandler { state: Arc,