hook it up
This commit is contained in:
parent
1ca31b78c6
commit
7b7044f4cf
4 changed files with 53 additions and 39 deletions
|
@ -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 {
|
|||
<div class="p-1">
|
||||
<h2 class="text-2xl">Game</h2>
|
||||
<p>Name: {move || game_name}</p>
|
||||
<p>Host:</p>
|
||||
<p>Players:</p>
|
||||
<p>Czar:</p>
|
||||
<p>Black Card:</p>
|
||||
<p>Your Cards:</p>
|
||||
<p>Host: {move || game_host}</p>
|
||||
<p>Players: {move || game_players}</p>
|
||||
<p>Czar: {move || game_czar}</p>
|
||||
<p>Black Card: {move || game_black}</p>
|
||||
<p>Your Cards: {move || game_white}</p>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String>,
|
||||
// pub czar: String,
|
||||
// pub black: String,
|
||||
// pub white: Vec<String>,
|
||||
pub host: String,
|
||||
pub players: Vec<String>,
|
||||
pub czar: String,
|
||||
pub black: String,
|
||||
pub white: Vec<String>,
|
||||
}
|
||||
|
||||
/// Card Pack Meta
|
||||
|
|
|
@ -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,28 +74,34 @@ impl GameHandler {
|
|||
.tx
|
||||
.clone();
|
||||
|
||||
tx.send(
|
||||
serde_json::to_string(&GameMeta {
|
||||
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)
|
||||
// .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(),
|
||||
)
|
||||
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(
|
||||
|
|
|
@ -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<AppState>,
|
||||
|
|
Loading…
Add table
Reference in a new issue