Sync foundry folder colors #57
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 folder colors sync through dragonroll and foundry
I'll start by exploring the repo structure and the Foundry sync code.
Now let me implement the backend side of the sync:
Let me verify how the existing test harness behaves by running a loadable copy of it:
I'll now update the test file — fixing the harness gaps that prevent it from running, plus adding color coverage:
I'm done. Here's what I changed and how I verified it.
Feature: folder colours sync between Foundry and Dragonroll
Foundry folder colours now travel both ways along the item-folder tree that already syncs (#44).
Backend —
backend/src/routes/foundry-link.jsfoundryFolderColor(source)normalises a pushed folder colour:undefined= the push says nothing about colours (older module) → the campaign's colour stays;null= the world shows no colour → the campaign's colour comes off; anything else is the colour.orderFoundryFolderSourcescarries it,syncFoundryItemFoldersapplies it alongside name/nesting (world still owns name and nesting; a folder created from a coloured push arrives coloured).GET /sync/itemsnow answers{items, folders}— the campaign's item folders withcolorandfoundryFolderId, the same shape the app's own/item/listuses — so the colour a user picks in Dragonroll has a way home.Foundry module —
dragonroll-foundry/scripts/api.jsworldItemFolderSnapshots()reports each folder'scolor(nullwhen uncoloured) with every tree push.applyDragonrollFolderColors(), run from the existing item reconcile, writes the campaign's colour onto the matching world folder — only when it differs, only for world item-directory folders, and held in a newsyncingFolderIdsset so theupdateFolderhook does not echo it straight back to the campaign. It runs before the D&D 5e gate, since a colour is system-agnostic while writing items is not. Autosync off still stops everything.Docs: one bullet in
AGENTS.md§4 and two indragonroll-foundry/README.md(rule + route table), plus the echo-suppression note.The Dragonroll UI needed nothing:
Folder.color, the sidebar colour menu and the sidebar's 5-second entry refetch were already there.Tests (
tests/item-folder-sync.test.js)8 new tests: colour in → campaign (new folder and re-colour), world un-colouring clears it, an older module that sends no colour leaves it alone,
/sync/itemsreturns the coloured item folders (and not the note folders); module side: the tree carries colours, a GM recolour pushes one, a campaign colour lands on the world folder without echoing back, a cleared colour clears the world folder, autosync off writes nothing.node --test tests/→ 188 pass, 25 fail. Two notes on that number:awaitmade Node 20.20 read it as an ES module (require is not defined), and its harness did not stubnode:crypto, wrote seeded rows without acampaign, or gave the actor/folder stubs theupdate/updateEmbeddedDocumentsthey call. I repaired those harness gaps, which is why the file contributes 27 passes now.map-pins/map-tokens(require("../models/Folder") is not stubbed) and 3 in this file that were masked by it not loading — theFolder.find(regex assertion overnote.js/folder.js, and the twoBuildItemRowssidebar-ordering tests. None touch files I changed; I left them alone.One landmine found while doing this, untouched because it is unrelated:
dragonroll-foundry/scripts/api.js:1279callsscheduleDragonrollCharacterSync(15000), which is never defined — so a failed startup character sync throws aReferenceErrorinstead of scheduling its retry.Implementation is ready for review: #66
The automated implementation stopped because of an internal error. Please check the worker logs for details.