Add map sync #109

Closed
opened 2026-10-16 15:55:46 +00:00 by Syndria98 · 16 comments
Owner

Can you make the maps from dragonroll sync with the foundry module?

Can you make the maps from dragonroll sync with the foundry module?
Syndria98 added the ai-ready label 2026-10-16 15:55:46 +00:00
Agent added the working label 2026-10-16 15:55:46 +00:00
Collaborator

I'll start by exploring the repository to understand the existing sync architecture and map handling.

I'll start by exploring the repository to understand the existing sync architecture and map handling.
Collaborator

This is very valuable — there's an earlier ai/issue-99 branch ("Make maps sync") that implements exactly this feature. Let me examine it.

This is very valuable — there's an earlier `ai/issue-99` branch ("Make maps sync") that implements exactly this feature. Let me examine it.
Collaborator

The ai/issue-99 branch is the reference implementation for exactly this feature. Let me extract its full diff to study and port it.

The `ai/issue-99` branch is the reference implementation for exactly this feature. Let me extract its full diff to study and port it.
Collaborator

This is the reference implementation. Let me get the remaining changes (module version, README, AGENTS.md, and the test-file adaptation points).

This is the reference implementation. Let me get the remaining changes (module version, README, AGENTS.md, and the test-file adaptation points).
Collaborator

Let me establish a baseline by running the test suite before making changes.

Let me establish a baseline by running the test suite before making changes.
Collaborator

Now I'll implement. Starting with the backend Map model and the new mapper service.

Now I'll implement. Starting with the backend Map model and the new mapper service.
Collaborator

Now the Foundry module. First the state variables:

Now the Foundry module. First the state variables:
Collaborator

Now the test stub updates for existing tests that load the sync router:

Now the test stub updates for existing tests that load the sync router:
Collaborator

Now add the new test file from the reference branch, adapted so the current router's Note dependency is stubbed:

Now add the new test file from the reference branch, adapted so the current router's `Note` dependency is stubbed:
Collaborator

All 22 new tests pass. Now the full suite:

All 22 new tests pass. Now the full suite:
Collaborator

Now the documentation. Let me read the current Foundry integration docs:

Now the documentation. Let me read the current Foundry integration docs:
Collaborator

Now AGENTS.md:

Now AGENTS.md:
Collaborator

I'll review the final state of the changes before summarizing.

I'll review the final state of the changes before summarizing.
Collaborator

Let me run the full test suite and syntax checks to confirm the final state.

Let me run the full test suite and syntax checks to confirm the final state.
Collaborator

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 — added foundrySceneId (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.src since Foundry V13, img before), the cell size (grid.size / grid), and the grid origin (flags.core.shiftX / .shiftY); returns null for a scene with no name or no picture.
  • backend/src/routes/foundry-link.js — imports the mapper as MapModel (avoids shadowing the route's own built-in Map folder trees, per #100/#101), adds saveFoundryScene and the token-authenticated routes POST /sync/scenes (upsert; prunes only on fullSync) and POST /sync/scene-delete. Identity resolves via foundrySceneId, a dragonroll-foundry.mapId flag, or a single hand-made map of the same name (adopted rather than duplicated).

Foundry module (dragonroll-foundry/scripts/api.js)

  • Scene state/queue, serializeFoundryScene (absolutizes the picture URL), pushFoundryScenes, deleteDragonrollScene, queueFoundrySceneChange, flushSceneChanges, initializeSceneSync.
  • Wired into link completion, the ready hook (full list on load), autosync on/off (queued edits resume, existing note reconcile preserved), and createScene / updateScene / deleteScene.
  • module.json bumped 0.5.1 → 0.6.0.

Docs — 03-maps.md, 03-foundry.md, dragonroll-foundry/README.md, and the AGENTS.md model/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), plus Map/map-foundry stubs added to the four existing sync test harnesses that load foundry-link.js.

Verification

  • npm test → 386 pass, 0 fail (baseline 364).
  • node --check passes on every changed JS file.

All changes remain uncommitted in the working tree on ai/issue-109; I have not committed or pushed.

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` — added `foundrySceneId` (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.src` since Foundry V13, `img` before), the cell size (`grid.size` / `grid`), and the grid origin (`flags.core.shiftX` / `.shiftY`); returns `null` for a scene with no name or no picture. - `backend/src/routes/foundry-link.js` — imports the mapper as `MapModel` (avoids shadowing the route's own built-in `Map` folder trees, per #100/#101), adds `saveFoundryScene` and the token-authenticated routes `POST /sync/scenes` (upsert; prunes only on `fullSync`) and `POST /sync/scene-delete`. Identity resolves via `foundrySceneId`, a `dragonroll-foundry.mapId` flag, or a single hand-made map of the same name (adopted rather than duplicated). **Foundry module** (`dragonroll-foundry/scripts/api.js`) - Scene state/queue, `serializeFoundryScene` (absolutizes the picture URL), `pushFoundryScenes`, `deleteDragonrollScene`, `queueFoundrySceneChange`, `flushSceneChanges`, `initializeSceneSync`. - Wired into link completion, the `ready` hook (full list on load), autosync on/off (queued edits resume, existing note reconcile preserved), and `createScene` / `updateScene` / `deleteScene`. - `module.json` bumped `0.5.1` → `0.6.0`. **Docs** — `03-maps.md`, `03-foundry.md`, `dragonroll-foundry/README.md`, and the `AGENTS.md` model/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), plus `Map`/`map-foundry` stubs added to the four existing sync test harnesses that load `foundry-link.js`. ## Verification - `npm test` → **386 pass, 0 fail** (baseline 364). - `node --check` passes on every changed JS file. All changes remain uncommitted in the working tree on `ai/issue-109`; I have not committed or pushed.
Collaborator

Implementation is ready for review: #110

Implementation is ready for review: https://git.aranroig.com/Syndria98/dragonroll/pulls/110
Agent added help wanted and removed working labels 2026-10-16 16:06:21 +00:00
Agent referenced this issue from a commit 2026-10-16 16:06:22 +00:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Syndria98/dragonroll#109