all repos — felt @ 0e72eb09adbe512af5c509d8f71fb0929de4dd28

virtual tabletop for dungeons and dragons (and similar) using Go, MongoDB, and websockets

streamline token messages by making most fields optional
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmSx1GIACgkQO3+8IhRO
Y5jZfA/+MJ2JOsFlHM2UG1LdgNvMVHysU2xcIPOTTpeNfE91oL1Wpc3RWDzH35wU
lzHEIUqUjRBgiuMtCO78JQ7amwOABFjS9HfJOSWokMZ7hc3sZ17OwsjMSEanWiLA
F/uiQQbOnKBdAdj4s+1MCIXNYRVXljqhOpr/EQghxkEkxxXTxnSiwL6jRDw0TmYu
Y1FPWRwhLjEP3JXhtv8hN/V4KLdQv6KudpuIT6KJtLro6tXZArQ+x9Pv0gV/cYW0
G6rdX5aPqwPWIX1/SlXcNAPeJAysi8yfU4idH3T1OCM0fzot6k53DTQ8rXCS9XgY
QYC3T/+4Wgs1fTHruZDEA54Ry18OV4tRgEhFWrrcMhEYgZQ471jutuqklLpQMmgZ
krGn/cCYBqXXP1dVZfuIT8scJVrq0kvUk8R9jLcGDlg5OGAf1UyjLdCDzpUQYIgc
Vb+5TbA7+XK2EznrgjJWKZKdypcHbxOm0x8yw3CS02eDZUSgBuNU4Ul0dtAlDG7w
Vt0sBZuUrO1bPsbR4OiirnDe9xQDyKgNTlZukblBMC/MNrfIVNgbtN0daleyNE/6
c8QUyCUC/Q8C6S2eFBQVPCOIjFU/4iLCTNmatA01XKk+ETuet8/nE2GqqmL+0bcR
rIMZj+PR68+L2RiWHayCG4eL7F641XsiKhas3CbMW3FCCJ6+q0Q=
=moqG
-----END PGP SIGNATURE-----
commit

0e72eb09adbe512af5c509d8f71fb0929de4dd28

parent

ba3b6a782f88b41747f58236f0329e323f6d74c0

5 files changed, 29 insertions(+), 29 deletions(-)

jump to
M README.mdREADME.md

@@ -60,4 +60,4 @@ 5. When running behind a reverse proxy, you will need to make sure that the server can forward the `Upgrade: websocket` header.

## 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.
M models/models.gomodels/models.go

@@ -19,12 +19,12 @@ }

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"`
M static/admin.jsstatic/admin.js

@@ -209,18 +209,8 @@ const img = tokenSpriteDropdown[tokenSpriteDropdown.selectedIndex].value;

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 @@ sprite: img,

name: name, active: false} ); + setTokenCreateFormVisible(false); return; } setErr("All token fields are required");
M static/map.jsstatic/map.js

@@ -1,7 +1,8 @@

let map = null; let mapImg = null; let tokens = []; -const worldBounds = [[180, -180],[-180, 180]]; +const worldBounds = [[180, -180], [-180, 180]]; +const cameraBounds = [[270, -270], [-270, 270]]; function initializeMap(mapImgUrl) { let init = false;

@@ -15,7 +16,7 @@ mapImg.removeFrom(map);

} 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 @@ if (existing) {

const self = Object.assign({}, existing.t); self.active = !self.active; console.log(self); - publish({token: self}); + publish({token: stripToken(self)}); } }

@@ -101,9 +102,19 @@ const self = Object.assign({}, existing.t);

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) {
M static/socket.jsstatic/socket.js

@@ -208,11 +208,9 @@ tblPassInput.readOnly = true;

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");