diff --git a/README.md b/README.md index b771304..6d966ea 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +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. \ No newline at end of file diff --git a/models/models.go b/models/models.go index 8e2d60d..a42eaa8 100644 --- a/models/models.go +++ b/models/models.go @@ -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"` diff --git a/static/admin.js b/static/admin.js index 320771e..22a22d7 100644 --- a/static/admin.js +++ b/static/admin.js @@ -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"); diff --git a/static/map.js b/static/map.js index c73dd84..37f1126 100644 --- a/static/map.js +++ b/static/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 @@ 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({ diff --git a/static/socket.js b/static/socket.js index 105a8b8..6c698bb 100644 --- a/static/socket.js +++ b/static/socket.js @@ -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");