summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstale <redkugelblitzin@gmail.com>2022-05-29 05:34:16 -0300
committerstale <redkugelblitzin@gmail.com>2022-05-29 05:34:16 -0300
commit8e8fb7c45e8088843b71cb55fede723b2f9c7ff2 (patch)
treea6fbcb4cb3ea575cac0dddb45d88ed103301dfbf
parent2826d78bbfab50eab90e5a1611576f33e752b7d8 (diff)
*really* basic public lobby
-rw-r--r--Cargo.lock15
-rw-r--r--Cargo.toml1
-rw-r--r--assets/client.js5
-rw-r--r--assets/index.html19
-rw-r--r--assets/room.html2
-rw-r--r--assets/style.css8
-rw-r--r--src/main.rs11
-rw-r--r--src/types.rs7
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 @@
<link rel="stylesheet" type="text/css" href="s.css">
</head>
<body>
- <form method="post" action="r">
+ <div id="rlist" class="cent"></div>
+ <script>
+ let rlist = document.getElementById('rlist');
+ fetch('rlist').then(r => r.json()).then(rooms => {
+ rooms.forEach(x => {
+ let a = document.createElement('a');
+ a.appendChild(document.createTextNode(x));
+ a.href = 'room/' + x;
+ rlist.append(a);
+ rlist.append(document.createElement('br'));
+ });
+ });
+ </script>
+ <form method="post" action="r" class="cent">
<fieldset>
<legend>-={ Create a new room }=-</legend>
<label>room name<input name="rname" type="text" autofocus></label><br>
@@ -19,8 +32,8 @@
in every<input name="rratiod" type="number" value="8" required>
tiles are mines
</label><br>
- <label>public, ie. shown in the lobby <input name="raccess" type="checkbox"></label><br>
- <label>always safe first move <input name="ralwayssafe1move" type="checkbox"></label><br>
+ <label>public, ie. shown in the lobby <input name="raccess" type="checkbox" checked></label><br>
+ <label>always safe first move <input name="ralwayssafe1move" type="checkbox" checked></label><br>
<label>player limit<input name="rlimit" type="number" value="32"></label><br>
<button>create</button>
</fieldset>
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 @@
<link rel="stylesheet" type="text/css" href="/s.css">
</head>
<body>
- <div>
+ <div class="cent">
<div id="board-container">
<span id="board"></span>
</div>
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<dyn Error>> {
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<str> for RoomId {
+ fn borrow(&self) -> &str {
+ self.0.borrow()
+ }
+}
impl RoomId {
pub fn new_in<T>(map: &HashMap<RoomId, T>) -> Self {