comfy tracing
This commit is contained in:
parent
21144d954e
commit
281c32f201
13 changed files with 171 additions and 137 deletions
19
Cargo.lock
generated
19
Cargo.lock
generated
|
@ -285,9 +285,10 @@ dependencies = [
|
||||||
"leptos-use",
|
"leptos-use",
|
||||||
"leptos_meta",
|
"leptos_meta",
|
||||||
"leptos_router",
|
"leptos_router",
|
||||||
"libcards",
|
"lib",
|
||||||
"log",
|
"log",
|
||||||
"serde-lite",
|
"serde-lite",
|
||||||
|
"serde_json",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-test",
|
"wasm-bindgen-test",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
|
@ -1098,13 +1099,7 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "lib"
|
||||||
version = "0.2.155"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libcards"
|
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
@ -1113,6 +1108,12 @@ dependencies = [
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.155"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linear-map"
|
name = "linear-map"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
|
@ -1759,7 +1760,7 @@ dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
"futures",
|
"futures",
|
||||||
"libcards",
|
"lib",
|
||||||
"rand",
|
"rand",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = ["server", "client", "libcards"]
|
members = ["server", "client", "lib"]
|
||||||
default-members = ["server", "libcards"]
|
default-members = ["server", "lib"]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
libcards = { path = "./libcards" }
|
lib = { path = "./lib" }
|
||||||
|
|
||||||
[profile.release.client]
|
[profile.release.client]
|
||||||
opt-level = 'z'
|
opt-level = 'z'
|
||||||
|
|
|
@ -16,6 +16,9 @@ console_error_panic_hook = "0.1"
|
||||||
leptos-use = "0.10.10"
|
leptos-use = "0.10.10"
|
||||||
serde-lite = "0.5.0"
|
serde-lite = "0.5.0"
|
||||||
|
|
||||||
|
lib = { workspace = true }
|
||||||
|
serde_json = "1.0.120"
|
||||||
|
|
||||||
# utils
|
# utils
|
||||||
# strum = { version = "0.25", features = ["derive", "strum_macros"] }
|
# strum = { version = "0.25", features = ["derive", "strum_macros"] }
|
||||||
# strum_macros = "0.25"
|
# strum_macros = "0.25"
|
||||||
|
@ -25,5 +28,3 @@ serde-lite = "0.5.0"
|
||||||
wasm-bindgen = "=0.2.92"
|
wasm-bindgen = "=0.2.92"
|
||||||
wasm-bindgen-test = "0.3"
|
wasm-bindgen-test = "0.3"
|
||||||
web-sys = { version = "0.3", features = ["Document", "Window"] }
|
web-sys = { version = "0.3", features = ["Document", "Window"] }
|
||||||
|
|
||||||
libcards = { workspace = true }
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use html::Textarea;
|
use html::Textarea;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_use::{core::ConnectionReadyState, use_websocket, UseWebsocketReturn};
|
use leptos_use::{core::ConnectionReadyState, use_websocket, UseWebsocketReturn};
|
||||||
|
use lib::models::*;
|
||||||
|
use serde_json::to_string;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Websocket() -> impl IntoView {
|
pub fn Websocket() -> impl IntoView {
|
||||||
|
@ -14,9 +16,9 @@ pub fn Websocket() -> impl IntoView {
|
||||||
} = use_websocket("ws://0.0.0.0:3030/websocket");
|
} = use_websocket("ws://0.0.0.0:3030/websocket");
|
||||||
|
|
||||||
// Websocket stuff
|
// Websocket stuff
|
||||||
let send_message = move |_| {
|
// let send_message = move |_| {
|
||||||
send("Hello, world!");
|
// send("Hello, world!");
|
||||||
};
|
// };
|
||||||
|
|
||||||
let status = move || ready_state.get().to_string();
|
let status = move || ready_state.get().to_string();
|
||||||
|
|
||||||
|
@ -30,6 +32,21 @@ pub fn Websocket() -> impl IntoView {
|
||||||
close();
|
close();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let fake_new_game_request = NewGameRequest {
|
||||||
|
name: String::from("Ligma"),
|
||||||
|
host: CAHPlayer {
|
||||||
|
name: String::from("Adam"),
|
||||||
|
role: PlayerRole::Host,
|
||||||
|
white: vec![],
|
||||||
|
black: vec![],
|
||||||
|
},
|
||||||
|
packs: vec![0],
|
||||||
|
};
|
||||||
|
|
||||||
|
let new_game_test = move |_| {
|
||||||
|
send(&to_string(&fake_new_game_request).unwrap());
|
||||||
|
};
|
||||||
|
|
||||||
// Chat stuff
|
// Chat stuff
|
||||||
let chat_history_ref = create_node_ref::<Textarea>();
|
let chat_history_ref = create_node_ref::<Textarea>();
|
||||||
|
|
||||||
|
@ -39,6 +56,10 @@ pub fn Websocket() -> impl IntoView {
|
||||||
let _ = &history.update(|history: &mut Vec<_>| history.push(message));
|
let _ = &history.update(|history: &mut Vec<_>| history.push(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fn message_handler(message) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
// handle incoming messages
|
// handle incoming messages
|
||||||
create_effect(move |_| {
|
create_effect(move |_| {
|
||||||
message.with(move |message| {
|
message.with(move |message| {
|
||||||
|
@ -64,10 +85,10 @@ pub fn Websocket() -> impl IntoView {
|
||||||
<p class="p-1">"status: " {status}</p>
|
<p class="p-1">"status: " {status}</p>
|
||||||
<div class="p-1">
|
<div class="p-1">
|
||||||
<button on:click=open_connection disabled=connected>
|
<button on:click=open_connection disabled=connected>
|
||||||
"Open"
|
"Connect"
|
||||||
</button>
|
</button>
|
||||||
<button on:click=close_connection disabled=move || !connected()>
|
<button on:click=close_connection disabled=move || !connected()>
|
||||||
"Close"
|
"Disconnect"
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
@ -96,8 +117,12 @@ pub fn Websocket() -> impl IntoView {
|
||||||
placeholder="talk shit..."
|
placeholder="talk shit..."
|
||||||
/>
|
/>
|
||||||
<br/>
|
<br/>
|
||||||
<button on:click=send_message disabled=move || !connected()>
|
// <button on:click=send_message disabled=move || !connected()>
|
||||||
"Send"
|
// "Send"
|
||||||
|
// </button>
|
||||||
|
<br />
|
||||||
|
<button on:click=new_game_test disabled=move || !connected()>
|
||||||
|
"Test New Game"
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
|
@ -27,6 +27,7 @@ pub fn Home() -> impl IntoView {
|
||||||
<div class="container m-auto">
|
<div class="container m-auto">
|
||||||
<h1 class="text-6xl text-slate-300">"Cards For Humanity"</h1>
|
<h1 class="text-6xl text-slate-300">"Cards For Humanity"</h1>
|
||||||
<Websocket/>
|
<Websocket/>
|
||||||
|
<a href="https://git.doordesk.net/adam/cards/">git</a>
|
||||||
</div>
|
</div>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "libcards"
|
name = "lib"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
|
@ -1,117 +1,8 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use rand::prelude::IteratorRandom;
|
use rand::prelude::IteratorRandom;
|
||||||
use rand::thread_rng;
|
use rand::thread_rng;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::net::SocketAddr;
|
|
||||||
|
|
||||||
/// User
|
use crate::models::*;
|
||||||
pub struct User {
|
|
||||||
pub name: String,
|
|
||||||
pub addr: SocketAddr,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// New game request structure
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct NewGameRequest {
|
|
||||||
/// Game name
|
|
||||||
pub name: String,
|
|
||||||
/// Game host
|
|
||||||
pub host: CAHPlayer,
|
|
||||||
/// Chosen packs
|
|
||||||
pub packs: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Game join request structure
|
|
||||||
pub struct GameJoinRequest {
|
|
||||||
/// Game id
|
|
||||||
pub id: u8, // increase later
|
|
||||||
/// Game password
|
|
||||||
pub password: Option<String>,
|
|
||||||
/// Player info
|
|
||||||
pub player: CAHPlayer,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A CAH white card
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct CAHCardWhite {
|
|
||||||
/// Card text
|
|
||||||
pub text: String,
|
|
||||||
/// ID of the pack it came from
|
|
||||||
pack: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A CAH black card
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct CAHCardBlack {
|
|
||||||
/// Card text
|
|
||||||
pub text: String,
|
|
||||||
/// Amount of cards to submit for judging
|
|
||||||
pick: u8,
|
|
||||||
/// ID of the pack it came from
|
|
||||||
pack: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A CAH pack
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct CAHCardSet {
|
|
||||||
/// Name of the pack
|
|
||||||
name: String,
|
|
||||||
/// Pack Description
|
|
||||||
description: Option<String>,
|
|
||||||
/// Whether or not this is an official card pack
|
|
||||||
official: bool,
|
|
||||||
/// White card data
|
|
||||||
white: Option<Vec<CAHCardWhite>>,
|
|
||||||
/// Black card data
|
|
||||||
black: Option<Vec<CAHCardBlack>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Player roles
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub enum PlayerRole {
|
|
||||||
/// Player is host
|
|
||||||
Host,
|
|
||||||
/// Player is a player in a game where another player is host
|
|
||||||
Player,
|
|
||||||
/// Player is just spectating
|
|
||||||
Spectator,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A struct that represents a player
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct CAHPlayer {
|
|
||||||
/// Player's username
|
|
||||||
pub name: String,
|
|
||||||
/// This player's role
|
|
||||||
pub role: PlayerRole,
|
|
||||||
/// The player's hand
|
|
||||||
pub white: Vec<CAHCardWhite>,
|
|
||||||
/// The player's wins
|
|
||||||
pub black: Vec<CAHCardBlack>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The game master
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct CAHGame {
|
|
||||||
/// The name of the game
|
|
||||||
pub name: String,
|
|
||||||
/// White draw pile
|
|
||||||
pub white: Vec<CAHCardWhite>,
|
|
||||||
/// Black draw pile
|
|
||||||
pub black: Vec<CAHCardBlack>,
|
|
||||||
/// White discard pile
|
|
||||||
pub white_discard: Vec<CAHCardWhite>,
|
|
||||||
/// Black discard pile
|
|
||||||
pub black_discard: Vec<CAHCardBlack>,
|
|
||||||
/// Indicates game active/game over
|
|
||||||
pub game_active: bool,
|
|
||||||
/// List of current players
|
|
||||||
pub players: Vec<CAHPlayer>,
|
|
||||||
// /// Reference to current card czar
|
|
||||||
// czar: &CAHPlayer,
|
|
||||||
/// Black card for the current round
|
|
||||||
pub current_black: Option<CAHCardBlack>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CAHGame {
|
impl CAHGame {
|
||||||
/// Build game decks from input data for game start.
|
/// Build game decks from input data for game start.
|
2
lib/src/lib.rs
Normal file
2
lib/src/lib.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod game_master;
|
||||||
|
pub mod models;
|
113
lib/src/models.rs
Normal file
113
lib/src/models.rs
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
|
/// User
|
||||||
|
pub struct User {
|
||||||
|
pub name: String,
|
||||||
|
pub addr: SocketAddr,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// New game request structure
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct NewGameRequest {
|
||||||
|
/// Game name
|
||||||
|
pub name: String,
|
||||||
|
/// Game host
|
||||||
|
pub host: CAHPlayer,
|
||||||
|
/// Chosen packs
|
||||||
|
pub packs: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Game join request structure
|
||||||
|
pub struct GameJoinRequest {
|
||||||
|
/// Game id
|
||||||
|
pub id: u8, // increase later
|
||||||
|
/// Game password
|
||||||
|
pub password: Option<String>,
|
||||||
|
/// Player info
|
||||||
|
pub player: CAHPlayer,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A CAH white card
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct CAHCardWhite {
|
||||||
|
/// Card text
|
||||||
|
pub text: String,
|
||||||
|
/// ID of the pack it came from
|
||||||
|
pub pack: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A CAH black card
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct CAHCardBlack {
|
||||||
|
/// Card text
|
||||||
|
pub text: String,
|
||||||
|
/// Amount of cards to submit for judging
|
||||||
|
pub pick: u8,
|
||||||
|
/// ID of the pack it came from
|
||||||
|
pub pack: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A CAH pack
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct CAHCardSet {
|
||||||
|
/// Name of the pack
|
||||||
|
name: String,
|
||||||
|
/// Pack Description
|
||||||
|
description: Option<String>,
|
||||||
|
/// Whether or not this is an official card pack
|
||||||
|
official: bool,
|
||||||
|
/// White card data
|
||||||
|
pub white: Option<Vec<CAHCardWhite>>,
|
||||||
|
/// Black card data
|
||||||
|
pub black: Option<Vec<CAHCardBlack>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Player roles
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub enum PlayerRole {
|
||||||
|
/// Player is host
|
||||||
|
Host,
|
||||||
|
/// Player is a player in a game where another player is host
|
||||||
|
Player,
|
||||||
|
/// Player is just spectating
|
||||||
|
Spectator,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A struct that represents a player
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct CAHPlayer {
|
||||||
|
/// Player's username
|
||||||
|
pub name: String,
|
||||||
|
/// This player's role
|
||||||
|
pub role: PlayerRole,
|
||||||
|
/// The player's hand
|
||||||
|
pub white: Vec<CAHCardWhite>,
|
||||||
|
/// The player's wins
|
||||||
|
pub black: Vec<CAHCardBlack>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The game master
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct CAHGame {
|
||||||
|
/// The name of the game
|
||||||
|
pub name: String,
|
||||||
|
/// White draw pile
|
||||||
|
pub white: Vec<CAHCardWhite>,
|
||||||
|
/// Black draw pile
|
||||||
|
pub black: Vec<CAHCardBlack>,
|
||||||
|
/// White discard pile
|
||||||
|
pub white_discard: Vec<CAHCardWhite>,
|
||||||
|
/// Black discard pile
|
||||||
|
pub black_discard: Vec<CAHCardBlack>,
|
||||||
|
/// Indicates game active/game over
|
||||||
|
pub game_active: bool,
|
||||||
|
/// List of current players
|
||||||
|
pub players: Vec<CAHPlayer>,
|
||||||
|
// /// Reference to current card czar
|
||||||
|
// czar: &CAHPlayer,
|
||||||
|
/// Black card for the current round
|
||||||
|
pub current_black: Option<CAHCardBlack>,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,4 +18,4 @@ anyhow = "1.0.82"
|
||||||
axum-extra = "0.9.3"
|
axum-extra = "0.9.3"
|
||||||
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
||||||
|
|
||||||
libcards = { workspace = true }
|
lib = { workspace = true }
|
||||||
|
|
|
@ -7,8 +7,8 @@ use axum::{
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
};
|
};
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures::{SinkExt, StreamExt};
|
||||||
|
use lib::models::*;
|
||||||
use std::{net::SocketAddr, sync::Arc};
|
use std::{net::SocketAddr, sync::Arc};
|
||||||
use libcards::*;
|
|
||||||
|
|
||||||
pub mod message_handler;
|
pub mod message_handler;
|
||||||
use crate::message_handler::*;
|
use crate::message_handler::*;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::api::{greeting, Message, User};
|
use crate::api::{greeting, Message, User};
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use crate::Arc;
|
use crate::Arc;
|
||||||
use libcards::*;
|
use lib::models::*;
|
||||||
|
|
||||||
pub async fn message_handler(message: Message, state: &Arc<AppState>, who: &User) {
|
pub async fn message_handler(message: Message, state: &Arc<AppState>, who: &User) {
|
||||||
let tx = &state.tx;
|
let tx = &state.tx;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use axum::{response::Html, routing::get, Router};
|
use axum::{response::Html, routing::get, Router};
|
||||||
use axum_extra::response::Css;
|
use axum_extra::response::Css;
|
||||||
use libcards::*;
|
use lib::models::*;
|
||||||
use std::{
|
use std::{
|
||||||
// collections::HashSet,
|
// collections::HashSet,
|
||||||
fs,
|
fs,
|
||||||
|
@ -107,7 +107,7 @@ async fn main() -> Result<()> {
|
||||||
tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(
|
.with(
|
||||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||||
.unwrap_or_else(|_| "server=trace,tower_http=trace".into()),
|
.unwrap_or_else(|_| "server=trace,tower_http=trace,lib=trace".into()),
|
||||||
)
|
)
|
||||||
.with(tracing_subscriber::fmt::layer())
|
.with(tracing_subscriber::fmt::layer())
|
||||||
.init();
|
.init();
|
||||||
|
|
Loading…
Add table
Reference in a new issue