yee big sloppy

This commit is contained in:
Adam 2024-05-03 21:12:23 -04:00
parent 302efad4c9
commit e595bd2d1b
5 changed files with 64 additions and 54 deletions

View file

@ -2,15 +2,31 @@
<html lang="en"> <html lang="en">
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Cards For Humanity Test Clients</title> <title>Cards For Humanity Test Clients</title>
<style>
body, html {
margin: 0;
padding: 0;
background-color: #000;
overflow: hidden;
}
iframe {
width: 49%;
height: 49vh;
border-style: none;
}
.container {
width: 100vw;
height: 100vh;
display: flex;
}
</style>
</head> </head>
<body style="background-color: #000"> <body>
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe> <div id="container">
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe> <iframe src="http://localhost:3030"></iframe>
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe> <iframe src="http://localhost:3030"></iframe>
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe> <iframe src="http://localhost:3030"></iframe>
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe> <iframe src="http://localhost:3030"></iframe>
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe> </div>
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe>
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe>
</body> </body>
</html> </html>

View file

@ -1,5 +1,5 @@
use crate::AppState; use crate::AppState;
use crate::CAHd_game::*; use crate::gamemaster::*;
use axum::{ use axum::{
extract::{ extract::{
ws::{Message, WebSocket, WebSocketUpgrade}, ws::{Message, WebSocket, WebSocketUpgrade},
@ -61,7 +61,14 @@ pub async fn websocket(stream: WebSocket, state: Arc<AppState>) {
if let Ok(new_game) = serde_json::from_str::<NewGameRequest>(&text) { if let Ok(new_game) = serde_json::from_str::<NewGameRequest>(&text) {
tracing::debug!("{:#?}", &new_game); tracing::debug!("{:#?}", &new_game);
state.games.lock().unwrap().push(CAHGame::new(new_game).expect("error creating game")); // create game
if let Ok(new_game_object) = CAHGame::new(new_game) {
state.games.lock().unwrap().push(new_game_object);
} else {
let _res = sender
.send(Message::Text(format!("error creating game")))
.await;
}
} else { } else {
// just echo // just echo
let _res = sender.send(Message::Text(text)).await; let _res = sender.send(Message::Text(text)).await;

View file

@ -105,7 +105,7 @@ impl CAHGame {
let mut game = CAHGame { let mut game = CAHGame {
..Default::default() ..Default::default()
}; };
println!("Creating game {}", &request.name); tracing::debug!("Creating game {}", &request.name);
game.name = request.name; game.name = request.name;
// game.build_decks(request.packs)?; // game.build_decks(request.packs)?;
@ -120,7 +120,7 @@ impl CAHGame {
/// Log counts of current drawable cards /// Log counts of current drawable cards
/// For testing /// For testing
pub fn deck_counts(&self) { pub fn deck_counts(&self) {
println!( tracing::debug!(
"Deck Counts:\n {} White cards\n {} Black cards", "Deck Counts:\n {} White cards\n {} Black cards",
self.white.len(), self.white.len(),
self.black.len() self.black.len()
@ -167,13 +167,13 @@ impl CAHGame {
/// Create a new player and add them to the game. /// Create a new player and add them to the game.
pub fn create_player(&mut self, mut player: CAHPlayer) -> Result<()> { pub fn create_player(&mut self, mut player: CAHPlayer) -> Result<()> {
println!("Creating player {} as {:?}", &player.name, &player.role); tracing::debug!("Creating player {} as {:?}", &player.name, &player.role);
let mut hand_buf = vec![]; let mut hand_buf = vec![];
for _ in 0..10 { for _ in 0..10 {
hand_buf.push(self.draw_one_white()?); hand_buf.push(self.draw_one_white()?);
} }
println!("Dealing hand for {}", &player.name); tracing::debug!("Dealing hand to {}", &player.name);
player.white.extend(hand_buf); player.white.extend(hand_buf);
self.players.push(player); self.players.push(player);
@ -183,12 +183,12 @@ impl CAHGame {
pub fn game_start(&mut self) -> Result<()> { pub fn game_start(&mut self) -> Result<()> {
self.game_active = true; self.game_active = true;
println!("Game Active!"); tracing::debug!("Game Active!");
if let Some(black) = &self.current_black { if let Some(black) = &self.current_black {
println!("{}", black.text); tracing::debug!("{}", black.text);
} else { } else {
println!("YOU DONE FUCKED UP (no current black card)"); tracing::debug!("YOU DONE FUCKED UP (no current black card)");
} }
Ok(()) Ok(())

View file

@ -7,9 +7,8 @@ use std::{error::Error, fs, result::Result};
use tokio::sync::broadcast; use tokio::sync::broadcast;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
#[allow(non_snake_case)] pub mod gamemaster;
pub mod CAHd_game; use crate::gamemaster::*;
use crate::CAHd_game::*;
pub mod api; pub mod api;
use crate::api::*; use crate::api::*;

View file

@ -6,12 +6,17 @@
<style> <style>
html, body, input, textarea, button { html, body, input, textarea, button {
font-family: monospace; font-family: monospace;
background-color: #111; background-color: #111;
color: #DDD; color: #DDD;
margin: 0;
parring: 0;
} }
div { div {
margin-top: 1rem; margin-top: 1rem;
} }
span {
padding-left: 1rem;
}
p { p {
margin: 0; margin: 0;
padding: 0; padding: 0;
@ -26,10 +31,23 @@
<body> <body>
<h1>Cards For Humanity Test Client</h1> <h1>Cards For Humanity Test Client</h1>
<hr /> <hr />
<h3>Status</h3>
<div id="status"> <div id="status">
<p><em>Disconnected...</em></p> <p><em>Disconnected...</em></p>
</div> </div>
<div id="chat">
<form id="chat" onsubmit="chatSubmit();return false">
<textarea id="chat-history" readonly="true" wrap="soft" style="display:block; width:30rem; height:10rem; box-sizing: border-box" cols="30" rows="10"></textarea>
<input id="chat-input" type="text" style="width: 30rem;" placeholder="chat" />
</form>
</div>
<hr />
<form id="new-game" onsubmit="createGame(); return false">
<p>Username:</p>
<input id="username" type="text" placeholder="username" />
<p>Game Name:</p>
<input id="gamename" type="text" placeholder="game name" />
<button id="create-game" type="submit">Create Game</button>
</form>
<hr /> <hr />
<div id="socketTest"> <div id="socketTest">
<h3>Socket Test</h3> <h3>Socket Test</h3>
@ -41,36 +59,6 @@
<button id="close" type="submit">Close Connection</button> <button id="close" type="submit">Close Connection</button>
</form> </form>
</div> </div>
<hr />
<div id="newGame">
<h3>Create Game</h3>
<form id="new-game" onsubmit="createGame(); return false">
<p>Username:</p>
<input id="username" type="text" placeholder="username" />
<p>Game Name:</p>
<input id="gamename" type="text" placeholder="game name" />
<button id="create-game" type="submit">Create Game</button>
</form>
</div>
<hr />
<div id="joinGame">
<h3>Join Game</h3>
<form id="new-game" onsubmit="joinGame(); return false">
<p>Username:</p>
<input id="username" type="text" placeholder="username" />
<p>Game Name:</p>
<input id="gamename" type="text" placeholder="game name" />
<button id="create-game" type="submit">Create Game</button>
</form>
</div>
<hr />
<div id="chat">
<h3>Chat</h3>
<form id="chat" onsubmit="chatSubmit();return false">
<textarea id="chat-history" readonly="true" wrap="soft" style="display:block; width:30rem; height:10rem; box-sizing: border-box" cols="30" rows="10"></textarea>
<input id="chat-input" type="text" style="width: 30rem;" placeholder="chat" />
</form>
</div>
<script type="text/javascript"> <script type="text/javascript">
socket = new WebSocket("ws://localhost:3030/websocket"); socket = new WebSocket("ws://localhost:3030/websocket");
socket.binaryType = "ArrayBuffer"; socket.binaryType = "ArrayBuffer";