HIV aka pre-AIDS
This commit is contained in:
parent
22b2b58079
commit
1ca31b78c6
5 changed files with 72 additions and 4 deletions
|
@ -17,9 +17,9 @@ pub fn Browser() -> impl IntoView {
|
||||||
|
|
||||||
let new_game_name_ref = create_node_ref::<Input>();
|
let new_game_name_ref = create_node_ref::<Input>();
|
||||||
let (selected_packs, set_selected_packs) = create_signal::<BTreeSet<u8>>(BTreeSet::new());
|
let (selected_packs, set_selected_packs) = create_signal::<BTreeSet<u8>>(BTreeSet::new());
|
||||||
create_effect(move |_| {
|
// create_effect(move |_| {
|
||||||
logging::log!("{:#?}", selected_packs().iter().collect::<Vec<_>>());
|
// logging::log!("{:#?}", selected_packs().iter().collect::<Vec<_>>());
|
||||||
});
|
// });
|
||||||
|
|
||||||
// Game stuff
|
// Game stuff
|
||||||
let new_game = move |_| {
|
let new_game = move |_| {
|
||||||
|
|
|
@ -1,11 +1,26 @@
|
||||||
|
use crate::components::websocket::WebSocketContext;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
use lib::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Game() -> impl IntoView {
|
pub fn Game() -> impl IntoView {
|
||||||
|
let websocket = expect_context::<WebSocketContext>();
|
||||||
|
let game_meta = expect_context::<ReadSignal<Option<GameMeta>>>();
|
||||||
|
|
||||||
|
let (game_name, set_game_name) = create_signal("".to_string());
|
||||||
|
let (game_host, set_game_host) = create_signal("".to_string());
|
||||||
|
|
||||||
|
create_effect(move |_| {
|
||||||
|
if let Some(game) = game_meta() {
|
||||||
|
set_game_name(game.name.clone())
|
||||||
|
set_game_name(game.host.clone())
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<div class="p-1">
|
<div class="p-1">
|
||||||
<h2 class="text-2xl">Game</h2>
|
<h2 class="text-2xl">Game</h2>
|
||||||
<p>Name:</p>
|
<p>Name: {move || game_name}</p>
|
||||||
<p>Host:</p>
|
<p>Host:</p>
|
||||||
<p>Players:</p>
|
<p>Players:</p>
|
||||||
<p>Czar:</p>
|
<p>Czar:</p>
|
||||||
|
|
|
@ -73,6 +73,7 @@ pub fn Websocket() -> impl IntoView {
|
||||||
let (chat_update, set_chat_update) = create_signal::<Option<ChatUpdate>>(Option::None);
|
let (chat_update, set_chat_update) = create_signal::<Option<ChatUpdate>>(Option::None);
|
||||||
let (chat_message, set_chat_message) = create_signal::<Option<ChatMessage>>(Option::None);
|
let (chat_message, set_chat_message) = create_signal::<Option<ChatMessage>>(Option::None);
|
||||||
let (active_games, set_active_games) = create_signal::<Option<GamesUpdate>>(Option::None);
|
let (active_games, set_active_games) = create_signal::<Option<GamesUpdate>>(Option::None);
|
||||||
|
let (current_game, set_current_game) = create_signal::<Option<GameMeta>>(Option::None);
|
||||||
let (card_packs_meta, set_card_packs_meta) = create_signal::<CardPacksMeta>(CardPacksMeta {
|
let (card_packs_meta, set_card_packs_meta) = create_signal::<CardPacksMeta>(CardPacksMeta {
|
||||||
official_meta: vec![],
|
official_meta: vec![],
|
||||||
unofficial_meta: vec![],
|
unofficial_meta: vec![],
|
||||||
|
@ -83,6 +84,7 @@ pub fn Websocket() -> impl IntoView {
|
||||||
provide_context::<ReadSignal<Option<ChatUpdate>>>(chat_update);
|
provide_context::<ReadSignal<Option<ChatUpdate>>>(chat_update);
|
||||||
provide_context::<ReadSignal<Option<ChatMessage>>>(chat_message);
|
provide_context::<ReadSignal<Option<ChatMessage>>>(chat_message);
|
||||||
provide_context::<ReadSignal<Option<GamesUpdate>>>(active_games);
|
provide_context::<ReadSignal<Option<GamesUpdate>>>(active_games);
|
||||||
|
provide_context::<ReadSignal<Option<GameMeta>>>(current_game);
|
||||||
provide_context::<ReadSignal<CardPacksMeta>>(card_packs_meta);
|
provide_context::<ReadSignal<CardPacksMeta>>(card_packs_meta);
|
||||||
provide_context::<ReadSignal<Option<ServerStateSummary>>>(state_summary);
|
provide_context::<ReadSignal<Option<ServerStateSummary>>>(state_summary);
|
||||||
|
|
||||||
|
@ -105,6 +107,8 @@ pub fn Websocket() -> impl IntoView {
|
||||||
set_chat_update(Some(chat_update));
|
set_chat_update(Some(chat_update));
|
||||||
} else if let Ok(games_update) = from_str::<GamesUpdate>(message) {
|
} else if let Ok(games_update) = from_str::<GamesUpdate>(message) {
|
||||||
set_active_games(Some(games_update));
|
set_active_games(Some(games_update));
|
||||||
|
} else if let Ok(game_update) = from_str::<GameMeta>(message) {
|
||||||
|
set_current_game(Some(game_update));
|
||||||
} else if let Ok(packs_meta_update) = from_str::<CardPacksMeta>(message) {
|
} else if let Ok(packs_meta_update) = from_str::<CardPacksMeta>(message) {
|
||||||
set_card_packs_meta(packs_meta_update);
|
set_card_packs_meta(packs_meta_update);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Game meta
|
||||||
|
#[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>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Card Pack Meta
|
/// Card Pack Meta
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct CardPackMeta {
|
pub struct CardPackMeta {
|
||||||
|
|
|
@ -4,6 +4,7 @@ use crate::Game;
|
||||||
use crate::NewGameManifest;
|
use crate::NewGameManifest;
|
||||||
use crate::NewGameRequest;
|
use crate::NewGameRequest;
|
||||||
use crate::User;
|
use crate::User;
|
||||||
|
use lib::*;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
|
@ -61,6 +62,43 @@ 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
|
||||||
|
.state
|
||||||
|
.online_users
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.get(&addr)
|
||||||
|
.unwrap()
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.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();
|
||||||
self.state.games.write().unwrap().insert(
|
self.state.games.write().unwrap().insert(
|
||||||
new_game_object.name.clone(),
|
new_game_object.name.clone(),
|
||||||
Arc::new(RwLock::new(new_game_object)),
|
Arc::new(RwLock::new(new_game_object)),
|
||||||
|
|
Loading…
Add table
Reference in a new issue