streamline token messages by making most fields optional

This commit is contained in:
Iris Lightshard 2023-07-14 17:04:02 -06:00
parent ba3b6a782f
commit 0e72eb09ad
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
5 changed files with 29 additions and 29 deletions

View file

@ -60,4 +60,4 @@ Requirements:
## license
The `felt` code is released under the [MIT license](https://hacklab.nilfm.cc/felt/raw/main/LICENSE); [Leaflet](https://leafletjs.com), the slippy map library used in the frontend, is licensed under a [2-clause BSD license](https://hacklab.nilfm.cc/felt/raw/main/LEAFLET_LICENSE). Basically do what you will but give credit.
The `felt` code (including the websocket server adapted from the [nhooyr.io/websocket](https://github.com/nhooyr/websocket) chat example) is released under the [MIT license](https://hacklab.nilfm.cc/felt/raw/main/LICENSE); [Leaflet](https://leafletjs.com), the slippy map library used in the frontend, is licensed under a [2-clause BSD license](https://hacklab.nilfm.cc/felt/raw/main/LEAFLET_LICENSE). Basically do what you will but give credit.

View file

@ -19,12 +19,12 @@ type DiceRoll struct {
type Token struct {
Id *string `json:"id" bson:"_id"`
Name string `json:"name"`
Sprite string `json:"sprite"`
W int `json:"w"`
H int `json:"h"`
OX int `json:"oX"`
OY int `json:"oY"`
Name *string `json:"name,omitempty"`
Sprite *string `json:"sprite,omitempty"`
W *int `json:"w,omitempty"`
H *int `json:"h,omitempty"`
OX *int `json:"oX,omitempty"`
OY *int `json:"oY,omitempty"`
X *float64 `json:"x"`
Y *float64 `json:"y"`
Active bool `json:"active"`

View file

@ -209,18 +209,8 @@ function createToken() {
const name = tokenName.value;
if (!isNaN(w) && !isNaN(h) && !isNaN(oX) && !isNaN(oY) && img && name) {
console.log("all green");
// create on the frontend for testing
/*
const self = NewToken(w, h, oX, oY, img, name);
tokens.push(self);
self.m.addTo(map);
resizeMarkers();
*/
// really though we have to send it on the websocket and wait for it to come back
const [x, y] = getCascadingPos();
// send it on the websocket and wait for it to come back
const [x, y] = [0, 0];
sendToken({
w: w,
h: h,
@ -232,6 +222,7 @@ function createToken() {
name: name,
active: false}
);
setTokenCreateFormVisible(false);
return;
}
setErr("All token fields are required");

View file

@ -2,6 +2,7 @@ let map = null;
let mapImg = null;
let tokens = [];
const worldBounds = [[180, -180], [-180, 180]];
const cameraBounds = [[270, -270], [-270, 270]];
function initializeMap(mapImgUrl) {
let init = false;
@ -15,7 +16,7 @@ function initializeMap(mapImgUrl) {
}
mapImg = L.imageOverlay(mapImgUrl, worldBounds);
mapImg.addTo(map);
map.setMaxBounds(worldBounds);
map.setMaxBounds(cameraBounds);
if (init) {
map.setView([0,0], 2);
}
@ -82,7 +83,7 @@ function toggleActive(tokenId) {
const self = Object.assign({}, existing.t);
self.active = !self.active;
console.log(self);
publish({token: self});
publish({token: stripToken(self)});
}
}
@ -101,11 +102,21 @@ function moveToken(id) {
const realPos = existing.m.getLatLng();
self.x = realPos.lng;
self.y = realPos.lat;
console.log(self);
publish({token: self});
publish({token: stripToken(self)});
}
}
function stripToken(self) {
delete self.sprite;
delete self.name;
delete self.w;
delete self.h;
delete self.oX;
delete self.oY;
return self;
}
function NewToken(token) {
const marker = L.marker([token.y,token.x], {
icon: L.icon({

View file

@ -208,11 +208,9 @@ function dial() {
joinTblBtn.style.display = "none";
leaveTblBtn.style.display = adminToken ? "none" : "inline";
lagDiv.style.display = "none";
let m = null;
while (m = msgQ.shift()) {
if (m) {
publish(m);
}
while (msgQ.some(m=>m)) {
publish(msgQ[0]);
msgQ.shift();
}
closeErr();
tabletop = document.getElementById("tabletop");