From 5979e53d91496603b246837b341c4fda4b924512 Mon Sep 17 00:00:00 2001 From: Rusty Striker Date: Thu, 17 Jul 2025 20:05:30 +0300 Subject: [PATCH] hmmm, stuff --- assets/web/app.js | 18 +++++++++++------- readme.md | 2 +- src/lib.rs | 35 ++++++++++++++++++++--------------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/assets/web/app.js b/assets/web/app.js index 3a67656..0d11b79 100644 --- a/assets/web/app.js +++ b/assets/web/app.js @@ -192,19 +192,23 @@ tavern.onmovetoken = (m) => { } tavern.onshowscene = (show) => { let map = document.getElementById('map'); + map.style.visibility = show.background == undefined ? 'hidden' : 'visible'; // Remove existing tokens Array.from(map.children).filter(c => c.classList.contains('token')).forEach(c => map.removeChild(c)); let background = document.getElementById('map-background'); gridOffset = show.grid_offset; - Array.from(document.getElementsByClassName('token')).forEach(t => { - t.children[0].style.width = `${gridSize}px`; - t.children[0].style.height = `${gridSize}px`; - }); + // I think this is pointless as we remove all the tokens just a couple of lines above + // Array.from(document.getElementsByClassName('token')).forEach(t => { + // t.children[0].style.width = `${gridSize}px`; + // t.children[0].style.height = `${gridSize}px`; + // }); gridSize = show.grid_cell_size; - background.src = show.background ?? ''; - for (let token of show.tokens) { - tavern.onspawntoken(token); + if (show.background != undefined) { + background.src = show.background; + for (let token of show.tokens) { + tavern.onspawntoken(token); + } } } tavern.onscenelist = (list) => { diff --git a/readme.md b/readme.md index 8847d47..b409f89 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,7 @@ FOSS Virtual Table Top that will be fully featured eventually [ ] change map [x] show grid [x] multiple maps - [ ] Edit map grid (and save it) + [x] Edit map grid (and save it) [ ] Chat actions [x] Define chat action [x] show roll dialog on chat aciton diff --git a/src/lib.rs b/src/lib.rs index 1dd79ff..d2bf8f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -94,7 +94,8 @@ impl GameServer { .map(|p| p == &login.password) .unwrap_or(false) { - self.users.insert(login.username.clone(), login.username == "rusty"); // rusty will be admin for now :) + let admin = login.username == "rusty"; // rusty will be admin for now :) + self.users.insert(login.username.clone(), admin); // Send login confirmation _ = broadcast.send(( Some(id.clone()), @@ -104,7 +105,6 @@ impl GameServer { }), )); // Send the list of scenes and chat history and such - let admin = *self.users.get(&id).unwrap_or(&false); _ = broadcast.send((Some(login.username.clone()), self.get_scene_list(admin))); _ = broadcast.send((Some(login.username.clone()), self.get_last_messages(50))); } else { @@ -175,10 +175,14 @@ impl GameServer { scene, } => { if *self.users.get(&id).unwrap_or(&false) { - if let Some(scene) = self.game.get_scene_mut(scene) { - if let Some(map) = scene.map.as_mut() { + if let Some(s) = self.game.get_scene_mut(scene) { + if let Some(map) = s.map.as_mut() { map.grid_cell_size = grid_cell_size; map.grid_offset = grid_offset; + let return_id = if s.visible_to_users { None } else { Some(id.clone()) }; + if let Some(scene) = self.get_scene(&id, scene) { + _ = broadcast.send((return_id, scene)); + } } } } @@ -201,17 +205,18 @@ impl GameServer { y, img_path, } => { - // TODO: Make sure the user is an admin - let token_id = self.game.create_token(map_id, character, img_path.clone(), x, y); - _ = broadcast.send(( - None, // TODO: add the option to spawn the token hidden - api::Response::SpawnToken(SpawnToken { - token_id, - x, - y, - img: img_path.clone(), - }), - )); + if *self.users.get(&id).unwrap_or(&false) { + let token_id = self.game.create_token(map_id, character, img_path.clone(), x, y); + _ = broadcast.send(( + None, // TODO: add the option to spawn the token hidden + api::Response::SpawnToken(SpawnToken { + token_id, + x, + y, + img: img_path.clone(), + }), + )); + } } api::Request::MoveToken { token_id, x, y } => { // TODO: add check to make sure the actor is authorized to move the token