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: nilix
GPG key ID: 3B7FBC22144E6398
5 changed files with 29 additions and 29 deletions

View file

@ -60,4 +60,4 @@ Requirements:
## license ## 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 { type Token struct {
Id *string `json:"id" bson:"_id"` Id *string `json:"id" bson:"_id"`
Name string `json:"name"` Name *string `json:"name,omitempty"`
Sprite string `json:"sprite"` Sprite *string `json:"sprite,omitempty"`
W int `json:"w"` W *int `json:"w,omitempty"`
H int `json:"h"` H *int `json:"h,omitempty"`
OX int `json:"oX"` OX *int `json:"oX,omitempty"`
OY int `json:"oY"` OY *int `json:"oY,omitempty"`
X *float64 `json:"x"` X *float64 `json:"x"`
Y *float64 `json:"y"` Y *float64 `json:"y"`
Active bool `json:"active"` Active bool `json:"active"`

View file

@ -209,18 +209,8 @@ function createToken() {
const name = tokenName.value; const name = tokenName.value;
if (!isNaN(w) && !isNaN(h) && !isNaN(oX) && !isNaN(oY) && img && name) { if (!isNaN(w) && !isNaN(h) && !isNaN(oX) && !isNaN(oY) && img && name) {
console.log("all green"); // send it on the websocket and wait for it to come back
const [x, y] = [0, 0];
// 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();
sendToken({ sendToken({
w: w, w: w,
h: h, h: h,
@ -232,6 +222,7 @@ function createToken() {
name: name, name: name,
active: false} active: false}
); );
setTokenCreateFormVisible(false);
return; return;
} }
setErr("All token fields are required"); setErr("All token fields are required");

View file

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

View file

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