Sync toggle on foundry #8
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 add on the foundry module an option on each actor to force sync onto dragonroll and a toggle to autosync (that is on by default) that does what the current implementation is already doing (that is synchronizing with CRUD requests the actors with dragonroll). If it is off, do not make it sync.
I'll start by exploring the repository structure and the Foundry module.
Now let me implement the changes in the Foundry module.
Now the module README documentation:
Now let me build a verification harness that stubs the Foundry globals, to actually exercise the new gating logic:
All six checks pass. Now let me put the test into the repo in a clean, permanent form:
Let me refine the force-sync action to respect Foundry's multi-select context-menu convention:
I renamed that function, so I need to update its call site in the context menu.
One inconsistency to fix: the actor path drops changes while autosync is off, but the item path queues them. Let me make both paths behave the same way:
Done. Here's what I implemented for Syndria98/dragonroll#8:
Changes
dragonroll-foundry/scripts/api.js— the whole feature is client-side, in the module:Autosync toggle (on by default) — new
autoSyncmodule setting (Dragonroll Auto-sync,config: true,default: true, client scope like the module's other sync settings). When off:flushActorChanges/flushItemChangesreturn early, so Foundry create/update/delete events no longer reach/foundry/sync/*;initializeCharacterSync) and both periodic reconciles (/sync/characters,/sync/items) do not run, so Dragonroll also stops rewriting Foundry documents;Per-actor force sync — a Dragonroll: Force Sync entry in the actor directory's context menu (
getActorDirectoryEntryContext, GM-only, shown once the world is paired). It pushes the selected actor(s) immediately withfullSync: false— an upsert, so it never prunes other campaign actors — and notifies success/failure. Actors Dragonroll does not import (anything that is not character/NPC/creature) are refused with a notification instead of silently doing nothing.Also bumped
module.jsonto0.4.0and documented the toggle and the menu entry indragonroll-foundry/README.md;AGENTS.mdwas updated where it documented the sync rules and the (now no longer absent) test command.Tests
Added
tests/foundry-sync-toggle.test.js(Node's built-in runner,npm testat the root, no dependencies): it loads the module script into anode:vmcontext with stubbed Foundry globals (game,Hooks,ui,fetch, fake timers) so every queued push/reconcile is observable. 10 tests, all passing (# pass 10 / # fail 0on Node v20.20.2): setting defaults to on, CRUD syncs while on, nothing is sent or reconciled while off (including at world start), queued edits land on re-enable, force sync works with the toggle off and on, multi-select sends one push, and unsupported actor types are refused.Interpretation notes (flagging in case you wanted otherwise)
/api/foundry/*) and never writes into the campaign. Easy to gate it too if you want the switch to stop all outbound traffic.Nothing is committed or pushed.
Implementation is ready for review: #9