Make maps sync #99
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Make that dragonroll maps sync with foundry maps. At the moment make that it just syncs the background image and the grid size and positioning
I'll start by exploring how maps and the Foundry sync currently work.
Now I have a clear picture. Let me implement the backend first.
Now the Foundry module side:
Now let me write the tests:
Now the documentation:
Done. Here's what I implemented for #99.
Maps now follow the world's scenes — background picture and grid only, as the issue asks, one-way (Foundry → campaign).
Backend
backend/src/models/Map.js— newfoundrySceneId, unique per campaign (partial index, same shape asfoundryItemId/foundryActorId).backend/src/services/map-foundry.js(new) —foundrySceneToMapData: the scene's background picture (background.srcsince V13,imgbefore),gridSizefromgrid/grid.size(Foundry's 50 px default when unset),offsetX/offsetYfrom the world'sflags.core.shiftX/shiftY. Returnsnullfor a scene with no picture, so those never become an empty map. The campaign'sscale, folder, pins and tokens are never touched.backend/src/routes/foundry-link.js—saveFoundryScene(modelled onsaveFoundryItem: identity byfoundrySceneId, adoption via adragonroll-foundry.mapIdflag or a hand-made unmapped map of the same name,fullSyncpreserves existing rows while live edits overwrite) plus two routes on the sync token:POST /api/foundry/sync/scenes(upserts, prunes only whenfullSync) andPOST /api/foundry/sync/scene-delete. The Map model is required asMapModelthere because that file builds plainMaps for the folder tree.Foundry module (
dragonroll-foundry/scripts/api.js) — scenes are sent as plain document data with the picture rewritten to an absolute URL of that world (like a portrait). The whole scene list goes when the world links and when it loads (the only push that prunes);createScene/updateScene/deleteSceneare debounced into one push 400 ms later, deletions reported separately, failures retried. Autosync covers maps: off = nothing crosses, and edits queued while off go over when it is turned back on.Frontend — no app change needed: the map viewer already treats an image stored as a full URL, so a synced scene renders as it is.
Docs — new Maps section and route rows in
dragonroll-foundry/README.md, a row and paragraph in the/docs/foundry"What syncs", a Maps from a linked Foundry world section in/docs/maps, and the AGENTS.md model/rule lines.Tests — new
tests/map-foundry-sync.test.js: 22 tests over the route (arrival, grid shift, V13 shapes, relative picture read against the campaign's world URL, scale left alone, no-picture scenes, one map per scene, live overwrite vs full-snapshot preserving campaign edits, hand-made adoption by name and by flag, prune only onfullSync, scene delete, refusals) and the module (game.scenesin the vm sandbox: full list on load, live scene edit, delete, autosync off/back on). Three existing files that loadfoundry-link.jsneeded stubs for the new model and service.npm test→ 371 passed, 0 failed (349 before).Two behaviours worth flagging, both documented: a map's
scale(what a cell stands for) stays the campaign's, since the world'sgridDistancecomes with its own units; and because nothing goes back to the world, a map deleted in the campaign returns with its scene on the next world load.Implementation is ready for review: #104