yee big sloppy
This commit is contained in:
parent
302efad4c9
commit
e595bd2d1b
5 changed files with 64 additions and 54 deletions
|
@ -2,15 +2,31 @@
|
|||
<html lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<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>
|
||||
<body style="background-color: #000">
|
||||
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe>
|
||||
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe>
|
||||
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe>
|
||||
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe>
|
||||
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe>
|
||||
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe>
|
||||
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe>
|
||||
<iframe src="http://localhost:3030" style="width: 500px; height: 500px"></iframe>
|
||||
<body>
|
||||
<div id="container">
|
||||
<iframe src="http://localhost:3030"></iframe>
|
||||
<iframe src="http://localhost:3030"></iframe>
|
||||
<iframe src="http://localhost:3030"></iframe>
|
||||
<iframe src="http://localhost:3030"></iframe>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
11
src/api.rs
11
src/api.rs
|
@ -1,5 +1,5 @@
|
|||
use crate::AppState;
|
||||
use crate::CAHd_game::*;
|
||||
use crate::gamemaster::*;
|
||||
use axum::{
|
||||
extract::{
|
||||
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) {
|
||||
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 {
|
||||
// just echo
|
||||
let _res = sender.send(Message::Text(text)).await;
|
||||
|
|
|
@ -105,7 +105,7 @@ impl CAHGame {
|
|||
let mut game = CAHGame {
|
||||
..Default::default()
|
||||
};
|
||||
println!("Creating game {}", &request.name);
|
||||
tracing::debug!("Creating game {}", &request.name);
|
||||
game.name = request.name;
|
||||
|
||||
// game.build_decks(request.packs)?;
|
||||
|
@ -120,7 +120,7 @@ impl CAHGame {
|
|||
/// Log counts of current drawable cards
|
||||
/// For testing
|
||||
pub fn deck_counts(&self) {
|
||||
println!(
|
||||
tracing::debug!(
|
||||
"Deck Counts:\n {} White cards\n {} Black cards",
|
||||
self.white.len(),
|
||||
self.black.len()
|
||||
|
@ -167,13 +167,13 @@ impl CAHGame {
|
|||
|
||||
/// Create a new player and add them to the game.
|
||||
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![];
|
||||
for _ in 0..10 {
|
||||
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);
|
||||
|
||||
self.players.push(player);
|
||||
|
@ -183,12 +183,12 @@ impl CAHGame {
|
|||
|
||||
pub fn game_start(&mut self) -> Result<()> {
|
||||
self.game_active = true;
|
||||
println!("Game Active!");
|
||||
tracing::debug!("Game Active!");
|
||||
|
||||
if let Some(black) = &self.current_black {
|
||||
println!("{}", black.text);
|
||||
tracing::debug!("{}", black.text);
|
||||
} else {
|
||||
println!("YOU DONE FUCKED UP (no current black card)");
|
||||
tracing::debug!("YOU DONE FUCKED UP (no current black card)");
|
||||
}
|
||||
|
||||
Ok(())
|
|
@ -7,9 +7,8 @@ use std::{error::Error, fs, result::Result};
|
|||
use tokio::sync::broadcast;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub mod CAHd_game;
|
||||
use crate::CAHd_game::*;
|
||||
pub mod gamemaster;
|
||||
use crate::gamemaster::*;
|
||||
|
||||
pub mod api;
|
||||
use crate::api::*;
|
||||
|
|
|
@ -6,12 +6,17 @@
|
|||
<style>
|
||||
html, body, input, textarea, button {
|
||||
font-family: monospace;
|
||||
background-color: #111;
|
||||
color: #DDD;
|
||||
background-color: #111;
|
||||
color: #DDD;
|
||||
margin: 0;
|
||||
parring: 0;
|
||||
}
|
||||
div {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
span {
|
||||
padding-left: 1rem;
|
||||
}
|
||||
p {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
@ -26,10 +31,23 @@
|
|||
<body>
|
||||
<h1>Cards For Humanity Test Client</h1>
|
||||
<hr />
|
||||
<h3>Status</h3>
|
||||
<div id="status">
|
||||
<p><em>Disconnected...</em></p>
|
||||
</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 />
|
||||
<div id="socketTest">
|
||||
<h3>Socket Test</h3>
|
||||
|
@ -41,36 +59,6 @@
|
|||
<button id="close" type="submit">Close Connection</button>
|
||||
</form>
|
||||
</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">
|
||||
socket = new WebSocket("ws://localhost:3030/websocket");
|
||||
socket.binaryType = "ArrayBuffer";
|
||||
|
|
Loading…
Add table
Reference in a new issue