Fix issue #96: When right clicking actor on foundry, show action to force sync to dragonroll
All checks were successful
Test / test (push) Successful in 2s

This commit is contained in:
Gitea OpenCode Agent
2026-10-15 22:53:03 +00:00
parent dcc6d7a14b
commit 967c704801
7 changed files with 115 additions and 14 deletions

View File

@@ -566,7 +566,7 @@ function reportActorSyncError(error) {
console.warn(`${MODULE_ID} | Character sync failed and will retry.`, error);
}
async function pushFoundryActors(actors, fullSync = false) {
async function pushFoundryActors(actors, fullSync = false, replace = false) {
const token = getSyncToken();
if (!token || !game.user?.isGM || !game.world || (!actors.length && !fullSync)) return;
if (game.system.id !== "dnd5e") {
@@ -585,6 +585,9 @@ async function pushFoundryActors(actors, fullSync = false) {
// The folder tree those world items stand in (see worldItemFolderSnapshots).
folders: worldItemFolderSnapshots(),
fullSync,
// A forced sync replaces the campaign's row for these actors outright; a live
// change or a full snapshot never sets this, so the campaign keeps its edits.
replace,
}, token);
for (const mapping of result.actors || []) {
@@ -607,8 +610,9 @@ async function deleteDragonrollActor(foundryActorId) {
}
// Sending actors on purpose, whether or not autosync is on: this is the push the
// GM asks for. It upserts those actors only, so unlike a full snapshot it never
// prunes anything else the campaign holds.
// GM asks for. It replaces everything the campaign holds for those actors (Syndria98/
// dragonroll#96), but it upserts them only, so unlike a full snapshot it never prunes
// anything else the campaign holds.
async function forceSyncActorsToDragonroll(actors) {
if (!game.user?.isGM || !game.world || !actors.length) return;
if (!getSyncToken()) {
@@ -624,7 +628,7 @@ async function forceSyncActorsToDragonroll(actors) {
if (!supported.length) return;
try {
await pushFoundryActors(supported);
await pushFoundryActors(supported, false, true);
ui.notifications?.info(supported.length === 1
? `${supported[0].name} was sent to the Dragonroll campaign.`
: `${supported.length} actors were sent to the Dragonroll campaign.`);
@@ -1484,7 +1488,8 @@ Hooks.once("ready", () => {
});
// A GM sends selected actors to Dragonroll from the actor directory's context
// menu. This works with autosync on and off: it is the one push done on purpose.
// menu, replacing whatever the campaign holds for them. This works with autosync on
// and off: it is the one push done on purpose.
Hooks.on("getActorDirectoryEntryContext", (html, options) => {
if (!game.user?.isGM || !getSyncToken()) return;