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_name, set_game_name) = create_signal("".to_string());
|
||||||
let (game_host, set_game_host) = 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 |_| {
|
create_effect(move |_| {
|
||||||
if let Some(game) = game_meta() {
|
if let Some(game) = game_meta() {
|
||||||
set_game_name(game.name.clone())
|
set_game_name(game.name.clone());
|
||||||
set_game_name(game.host.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">
|
<div class="p-1">
|
||||||
<h2 class="text-2xl">Game</h2>
|
<h2 class="text-2xl">Game</h2>
|
||||||
<p>Name: {move || game_name}</p>
|
<p>Name: {move || game_name}</p>
|
||||||
<p>Host:</p>
|
<p>Host: {move || game_host}</p>
|
||||||
<p>Players:</p>
|
<p>Players: {move || game_players}</p>
|
||||||
<p>Czar:</p>
|
<p>Czar: {move || game_czar}</p>
|
||||||
<p>Black Card:</p>
|
<p>Black Card: {move || game_black}</p>
|
||||||
<p>Your Cards:</p>
|
<p>Your Cards: {move || game_white}</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,11 @@ use serde::{Deserialize, Serialize};
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct GameMeta {
|
pub struct GameMeta {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
// pub host: String,
|
pub host: String,
|
||||||
// pub players: Vec<String>,
|
pub players: Vec<String>,
|
||||||
// pub czar: String,
|
pub czar: String,
|
||||||
// pub black: String,
|
pub black: String,
|
||||||
// pub white: Vec<String>,
|
pub white: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Card Pack Meta
|
/// Card Pack Meta
|
||||||
|
|
|
@ -8,7 +8,7 @@ use lib::*;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
/// Handle incoming messages over the WebSocket
|
// This file is disgusting, don't look at it
|
||||||
|
|
||||||
pub enum GameHandlerMessage {
|
pub enum GameHandlerMessage {
|
||||||
NewGame {
|
NewGame {
|
||||||
|
@ -62,7 +62,6 @@ impl GameHandler {
|
||||||
|
|
||||||
// create game
|
// create game
|
||||||
if let Ok(new_game_object) = Game::new(manifest) {
|
if let Ok(new_game_object) = Game::new(manifest) {
|
||||||
tracing::debug!("{:#?}", &new_game_object);
|
|
||||||
let tx = self
|
let tx = self
|
||||||
.state
|
.state
|
||||||
.online_users
|
.online_users
|
||||||
|
@ -75,28 +74,34 @@ impl GameHandler {
|
||||||
.tx
|
.tx
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
tx.send(
|
tracing::debug!("{:#?}", &new_game_object);
|
||||||
serde_json::to_string(&GameMeta {
|
|
||||||
|
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(),
|
name: new_game_object.name.clone(),
|
||||||
// host: new_game_object.host.read().unwrap().name.clone(),
|
host: new_game_object.host.read().unwrap().name.clone(),
|
||||||
// players: new_game_object
|
players: new_game_object
|
||||||
// .players
|
.players
|
||||||
// .iter()
|
.iter()
|
||||||
// .map(|player| player.user.read().unwrap().name)
|
.map(|player| player.user.read().unwrap().name.clone())
|
||||||
// .collect(),
|
.collect(),
|
||||||
// czar: new_game_object.host.read().unwrap().name.clone(),
|
czar: new_game_object.host.read().unwrap().name.clone(),
|
||||||
// black: new_game_object
|
black: black_text,
|
||||||
// .current_black
|
white: new_game_object
|
||||||
// .clone()
|
.white
|
||||||
// .unwrap()
|
.iter()
|
||||||
// .text
|
.map(|card| card.text.clone())
|
||||||
// .clone()
|
.collect(),
|
||||||
// .to_string()
|
};
|
||||||
// .clone(),
|
|
||||||
// white: new_game_object.white.iter().map(|card| card.text).collect(),
|
tracing::debug!("{:#?}", &meta);
|
||||||
})
|
tx.send(serde_json::to_string(&meta).unwrap())
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.state.games.write().unwrap().insert(
|
self.state.games.write().unwrap().insert(
|
||||||
|
|
|
@ -7,7 +7,8 @@ use serde_json::{from_str, to_string};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::Arc;
|
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 {
|
pub struct MessageHandler {
|
||||||
state: Arc<AppState>,
|
state: Arc<AppState>,
|
||||||
|
|
Loading…
Add table
Reference in a new issue