all repos — felt @ 825f2ac762a2506f5c2146182663fc5a5c30fc29

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

testing clientside token stuff
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmSlGVYACgkQO3+8IhRO
Y5hBhw/8CewOtbTNMlDTKKiSbOGZJD5OnEcCdGgdzFOBoX4Wf0+72g6/OPxdkXDF
jFOCJvyTa1CG7wAU8YcbHivsfEnn9LZ0wL7On2QbaA7qGAdw1v0QP+b61J02OmHf
NJMHryWzao62xrRisB0CMcrAiWEtSdrmoecpvV7KYaO2B73foi0v230ygXH7Pyfe
9ToGQIvWl9xJMMl3oPjj/kIdwzgLO5eAqIKZ4miQj9sH6LWl7eZ8ni5PcT4m+PoJ
8+eBa7sIXENTe2RPXXZwJe3krNkSbX8drfA3GO22EWC8x5R1a9wcoUYCiUBXUvCN
rIaiaeaTtXhfMFfAg1gMIIqIElLFWIUNHLJ+s7nNBj5Nr+jdUEUEAWPey/sK5M8e
otJrxt58YCoDYYE78dTH9GVthaOj9l2xc+YfDLBGdCh9Ltq5dWglVP53hUv2PD0a
s6EElkoTeb1GvNfgfxVwzCXP2FzALAasXbwbOdXdrR23/DD46fbV90FeHDDNvSAT
gVJ6WiCmEOSYU4ATeG6sWGGqgT5KCXrRDv+N/lH7UerB8PWrT/bRTaFDiPJJn6rU
cRH+3unRlYFUNXQbHkp9iEc5CC/EsjWJl2XwDmg5RiqJGJtHl8nI6tbblxyBJ/T+
RlUB4Ey/MIhW55kfobST6tYMfToiOo5jwJMaLK+FbQFF+tot1hI=
=dNcZ
-----END PGP SIGNATURE-----
commit

825f2ac762a2506f5c2146182663fc5a5c30fc29

parent

f7973370742f0cb864c52ce7824edee1f332007f

5 files changed, 60 insertions(+), 24 deletions(-)

jump to
M admin/admin.goadmin/admin.go

@@ -273,10 +273,11 @@ return

} } } - w.WriteHeader(422) - next.ServeHTTP(w, req) - return + w.WriteHeader(422) + next.ServeHTTP(w, req) + return } + return http.HandlerFunc(handlerFunc) }

@@ -284,7 +285,7 @@

func apiDeleteImage(next http.Handler, uploads string, uploadType string, udb auth.UserStore, dbAdapter mongodb.DbAdapter) http.Handler { handlerFunc := func(w http.ResponseWriter, req *http.Request) { // put the path together - urlParams := req.Context().Value("params").(map[string]string) +urlParams := req.Context().Value("params").(map[string]string) tableName := urlParams["table"] tableKey := models.TableKey{ Name: tableName,

@@ -307,20 +308,20 @@ }

if ok { if dbAdapter.CheckTable(tableKey) { - // if the file exists, delete it and return 201 - filename := urlParams["file"] - fullPath := filepath.Join(uploads, tableName, uploadType, filename) - s, err := os.Stat(fullPath) - if err == nil && !s.IsDir() { - err = os.Remove(fullPath) - if err == nil { - w.WriteHeader(201) - next.ServeHTTP(w, req) - return - } - } - } - } + // if the file exists, delete it and return 201 + filename := urlParams["file"] + fullPath := filepath.Join(uploads, tableName, uploadType, filename) + s, err := os.Stat(fullPath) + if err == nil && !s.IsDir() { + err = os.Remove(fullPath) + if err == nil { + w.WriteHeader(201) + next.ServeHTTP(w, req) + return + } + } + } + } } // otherwise, return an error w.WriteHeader(500)
M gametable/server.gogametable/server.go

@@ -165,13 +165,14 @@ return

} err = self.writeToDB(&tableMsg) + // sanitize auth for rebroadcast tableMsg.Auth = nil clean, err := json.Marshal(tableMsg) - fmt.Println(string(clean[:])) if err != nil { fmt.Println(err.Error()) return } + self.publishLimiter.Wait(context.Background()) for s, k := range self.subscribers {

@@ -241,8 +242,6 @@ }

} } } - - tableMsg.Auth = nil return nil }
M static/admin.jsstatic/admin.js

@@ -40,8 +40,9 @@ } else {

infoHtml += "<label>Maps couldn't be retrieved</label>"; } adminZone.innerHTML = infoHtml; - } - else { + + // also, we have to fill and toggle the tokens window + } else { console.log(res.status); } } catch (err) {
M static/map.jsstatic/map.js

@@ -1,9 +1,11 @@

let map = null; let mapImg = null; +let tokens = []; function initializeMap(mapImgUrl) { if (!map) { map = L.map('map', { minZoom: 0, maxZoom: 4, crs: L.CRS.Simple }); + map.on("zoomend", resizeMarkers); } if (mapImg) { mapImg.removeFrom(map);

@@ -12,4 +14,37 @@ mapImg = L.imageOverlay(mapImgUrl, [[-180, 180],[180, -180]]);

mapImg.addTo(map); map.setMaxBounds([[-180,180],[180,-180]]); map.setView([0,0], 2); +} + +// this works but assumes the map is square (reasonable limitation I think) +function resizeMarkers() { + tokens.forEach(t=>{ + const icon = t.m.options.icon; + const scaleFactor = mapImg._image.clientWidth / mapImg._image.naturalWidth; + icon.options.iconSize = [scaleFactor * t.sz[0], scaleFactor * t.sz[1]]; + t.m.setIcon(icon); + }); +} + +function addToken(token) { + const self = { sz: token.sz, m: L.marker(token.pos, { + icon: L.icon({ + iconUrl: token.img, + iconSize: token.sz, + }), + title: token.name, + draggable: true, + autoPan: true + })}; + + tokens.push(self); + self.m.addTo(map); +} + +// token for testing in browser console +const t = { + img: "https://nilfm.cc/favicon.png", + sz: [32,32], + pos: [0,0], + name: "test", }
M static/style.cssstatic/style.css

@@ -155,7 +155,7 @@ }

nav { display: grid; - grid-template-columns: 1fr 1fr; + grid-template-columns: auto 1fr; } .leaflet-container {