From 4ebe819106d82459def54561cf8dc71ec22ba6e4 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 4 Jun 2024 20:48:43 +0200 Subject: save creds --- src/spectate/index.html | 35 +++++++++++++++++++++++++++++++++++ src/spectate/main.ts | 3 +-- src/spectate/server.rs | 21 ++++++++++++++------- src/spectate/style.css | 43 +++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 91 insertions(+), 11 deletions(-) (limited to 'src/spectate') diff --git a/src/spectate/index.html b/src/spectate/index.html index 394b780..5b9dc5a 100644 --- a/src/spectate/index.html +++ b/src/spectate/index.html @@ -12,5 +12,40 @@ This is the GPN-Tron spectator application. You need JavaScript to run it. +
+
+

GPN-Tron

+

+ This is the GPN-Tron Rust rewrite. It should be compatible + with the original. Connect via TCP and join the fun! +

+
    +
  • + Spectator: + +
  • +
  • + Player: + +
  • +
+ + Source code + +
+
+

Scoreboard

+
+
+

Chat

+
+
+
diff --git a/src/spectate/main.ts b/src/spectate/main.ts index ea84924..508ca30 100644 --- a/src/spectate/main.ts +++ b/src/spectate/main.ts @@ -35,7 +35,7 @@ let ctx: CanvasRenderingContext2D document.addEventListener("DOMContentLoaded", () => { canvas = document.createElement("canvas") ctx = canvas.getContext("2d")! - document.body.append(canvas) + document.getElementById("board")?.append(canvas) canvas.width = 1000; canvas.height = 1000; redraw() @@ -122,7 +122,6 @@ function name_color(name: string): string { ws.onerror = console.error ws.onmessage = message => { const p = JSON.parse(message.data) as Packet - console.log(p); if (p == "tick") { tick_anim = 0 const d = [] diff --git a/src/spectate/server.rs b/src/spectate/server.rs index da18a77..11c4d5a 100644 --- a/src/spectate/server.rs +++ b/src/spectate/server.rs @@ -47,6 +47,19 @@ pub async fn spectate_server(config: Config, state: Arc) -> Result<()> { Ok(()) } +#[cfg(debug_assertions)] +async fn index() -> Html { + use tokio::fs::read_to_string; + Html( + read_to_string(concat!( + env!("CARGO_MANIFEST_DIR"), + "/src/spectate/index.html" + )) + .await + .unwrap(), + ) +} +#[cfg(not(debug_assertions))] async fn index() -> Html<&'static str> { Html(include_str!("index.html")) } @@ -91,13 +104,7 @@ async fn css() -> (HeaderMap, &'static str) { use headers::HeaderMapExt; let mut hm = HeaderMap::new(); hm.typed_insert(ContentType::from_str("text/css").unwrap()); - ( - hm, - include_str!(concat!( - env!("CARGO_MANIFEST_DIR"), - "/src/spectate/style.css" - )), - ) + (hm, include_str!("style.css")) } async fn broadcaster(sstate: Arc, state: Arc) { diff --git a/src/spectate/style.css b/src/spectate/style.css index 52711d0..c391020 100644 --- a/src/spectate/style.css +++ b/src/spectate/style.css @@ -1,4 +1,43 @@ +* { + color: white; +} +body { + padding: 0px; + margin: 0px; + background-color: black; + + width: 100dvw; + height: 100dvh; + display: flex; + flex-direction: row; + overflow-y: hidden; +} + canvas { - height: min(100dvh, 70dvw); - float: left; + object-fit: contain; + width: 100%; + height: 100%; +} +#board { + width: 60%; + height: 100%; +} +#side { + width: 30%; + height: 100%; +} +#info { + width: 100%; + height: 30%; + overflow-y: scroll; +} +#scoreboard { + width: 100%; + height: 30%; + overflow-y: scroll; +} +#chat { + width: 100%; + height: 40%; + overflow-y: scroll; } -- cgit v1.2.3-70-g09d2