hmmm, stuff
This commit is contained in:
parent
2ed7602595
commit
5979e53d91
3 changed files with 32 additions and 23 deletions
|
@ -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) => {
|
||||
|
|
|
@ -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
|
||||
|
|
35
src/lib.rs
35
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue