Add map sync #109
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?
Can you make the maps from dragonroll sync with the foundry module?
I'll start by exploring the repository to understand the existing sync architecture and map handling.
This is very valuable — there's an earlier
ai/issue-99branch ("Make maps sync") that implements exactly this feature. Let me examine it.The
ai/issue-99branch is the reference implementation for exactly this feature. Let me extract its full diff to study and port it.This is the reference implementation. Let me get the remaining changes (module version, README, AGENTS.md, and the test-file adaptation points).
Let me establish a baseline by running the test suite before making changes.
Now I'll implement. Starting with the backend Map model and the new mapper service.
Now the Foundry module. First the state variables:
Now the test stub updates for existing tests that load the sync router:
Now add the new test file from the reference branch, adapted so the current router's
Notedependency is stubbed:All 22 new tests pass. Now the full suite:
Now the documentation. Let me read the current Foundry integration docs:
Now AGENTS.md:
I'll review the final state of the changes before summarizing.
Let me run the full test suite and syntax checks to confirm the final state.
Done. Map sync is implemented, tested, and documented.
What changed
Interpretation: Foundry scenes → Dragonroll campaign maps, one-way. Only the scene's background picture and the grid laid over it cross over; pins, tokens, folder,
scale, and what a cell means stay with the campaign, and nothing of a map is written back to the world.Backend
backend/src/models/Map.js— addedfoundrySceneId(String) plus a unique-per-campaign partial index, so one scene maps to exactly one map.backend/src/services/map-foundry.js(new) —foundrySceneToMapData: reads the picture (background.srcsince Foundry V13,imgbefore), the cell size (grid.size/grid), and the grid origin (flags.core.shiftX/.shiftY); returnsnullfor a scene with no name or no picture.backend/src/routes/foundry-link.js— imports the mapper asMapModel(avoids shadowing the route's own built-inMapfolder trees, per #100/#101), addssaveFoundrySceneand the token-authenticated routesPOST /sync/scenes(upsert; prunes only onfullSync) andPOST /sync/scene-delete. Identity resolves viafoundrySceneId, adragonroll-foundry.mapIdflag, or a single hand-made map of the same name (adopted rather than duplicated).Foundry module (
dragonroll-foundry/scripts/api.js)serializeFoundryScene(absolutizes the picture URL),pushFoundryScenes,deleteDragonrollScene,queueFoundrySceneChange,flushSceneChanges,initializeSceneSync.readyhook (full list on load), autosync on/off (queued edits resume, existing note reconcile preserved), andcreateScene/updateScene/deleteScene.module.jsonbumped0.5.1→0.6.0.Docs —
03-maps.md,03-foundry.md,dragonroll-foundry/README.md, and theAGENTS.mdmodel/API notes.Tests — new
tests/map-foundry-sync.test.js(22 tests: the mapper, both routes, identity/adoption/pruning, and the module queue/autosync behaviour), plusMap/map-foundrystubs added to the four existing sync test harnesses that loadfoundry-link.js.Verification
npm test→ 386 pass, 0 fail (baseline 364).node --checkpasses on every changed JS file.All changes remain uncommitted in the working tree on
ai/issue-109; I have not committed or pushed.Implementation is ready for review: #110