From 8e8fb7c45e8088843b71cb55fede723b2f9c7ff2 Mon Sep 17 00:00:00 2001 From: stale Date: Sun, 29 May 2022 05:34:16 -0300 Subject: *really* basic public lobby --- Cargo.lock | 15 +++++++++++++++ Cargo.toml | 1 + assets/client.js | 5 +++-- assets/index.html | 19 ++++++++++++++++--- assets/room.html | 2 +- assets/style.css | 8 +++++--- src/main.rs | 11 ++++++++++- src/types.rs | 7 ++++++- 8 files changed, 57 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4e24412..ca41240 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -808,6 +808,20 @@ name = "serde" version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "serde_json" @@ -1363,6 +1377,7 @@ dependencies = [ "ammonia", "futures-util", "rand", + "serde", "tokio", "warp", ] diff --git a/Cargo.toml b/Cargo.toml index 3a9c24e..c825273 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [dependencies] tokio = { version = "1", features = ["full"] } +serde = { version = "1", features = ["derive"] } warp = { version = "0.3", features = ["tls", "websocket"] } rand = "0.8" futures-util = "0.3" diff --git a/assets/client.js b/assets/client.js index f888104..b23222c 100644 --- a/assets/client.js +++ b/assets/client.js @@ -156,14 +156,15 @@ function createCursor(id, name, clr) { return cursor; } function movSelWin(win, x, y) { + let anch = board_elem.getBoundingClientRect(); let tpos = tilepos(x, y); if (tpos.x > (bwidth - 1) || tpos.x < 0 || tpos.y > (bheight - 1) || tpos.y < 0) { win.style.display = "none"; } else { win.style.display = ""; } - win.style.left = ((tpos.x + 0.5) * tile_w) + 'px'; - win.style.top = ((tpos.y + 0.5) * tile_h) + 'px'; + win.style.left = (anch.x + (tpos.x * tile_w)) + 'px'; + win.style.top = (anch.y + ((tpos.y + 0.35) * tile_h)) + 'px'; win.style.width = tile_w + 'px'; win.style.height = tile_h + 'px'; } diff --git a/assets/index.html b/assets/index.html index 4571428..6fc9c46 100644 --- a/assets/index.html +++ b/assets/index.html @@ -7,7 +7,20 @@ -
+
+ +
-={ Create a new room }=-
@@ -19,8 +32,8 @@ in every tiles are mines
-
-
+
+

diff --git a/assets/room.html b/assets/room.html index e3e6ff9..27f9ae1 100644 --- a/assets/room.html +++ b/assets/room.html @@ -7,7 +7,7 @@ -
+
diff --git a/assets/style.css b/assets/style.css index a8936e6..d217b8d 100644 --- a/assets/style.css +++ b/assets/style.css @@ -6,14 +6,16 @@ font-size: 36px; line-height: 22px; } +.cent { + width: 80vmin; + margin: 0 auto; +} + body { font-family: vt323, monospace; background-color: black; color: white; } -form { - margin: 0 auto; -} .unsel { -webkit-touch-callout: none; -webkit-user-select: none; diff --git a/src/main.rs b/src/main.rs index 2b5f9b1..2f7d52c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,16 @@ async fn tokio_main(conf: Config) -> Result<(), Box> { let style = path!("s.css").and(fs::file(conf.stylesheet.clone())); let code = path!("c.js").and(fs::file(conf.client_code.clone())); let font = path!("f.ttf").map(|| FONT_FILE); - let listing = path!("rlist").map(|| "placeholder'em"); + let listing = { + let pubs = public_rooms.clone(); + path!("rlist").and_then(move || { + let pubs = pubs.clone(); + async move { + Ok::<_,std::convert::Infallible>( + reply::json(&pubs.read().await.as_slice()) + ) + }}) + }; let rform_recv = { let rooms = rooms.clone(); let pubs = public_rooms.clone(); diff --git a/src/types.rs b/src/types.rs index 1c9ae89..84e7d46 100644 --- a/src/types.rs +++ b/src/types.rs @@ -62,13 +62,18 @@ impl Display for Player { } } -#[derive(Eq, PartialEq, Hash, Debug, Clone)] +#[derive(Eq, PartialEq, Hash, Debug, Clone, serde::Serialize)] pub struct RoomId(pub String); impl Display for RoomId { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) } } +impl std::borrow::Borrow for RoomId { + fn borrow(&self) -> &str { + self.0.borrow() + } +} impl RoomId { pub fn new_in(map: &HashMap) -> Self { -- cgit v1.2.3