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
All checks were successful
Test / test (push) Successful in 2s
This commit is contained in:
@@ -73,9 +73,11 @@ queued while it was off are sent as the world catches up.
|
||||
With autosync off — or any time a single character needs to cross over right now — right-click an
|
||||
actor (or several selected ones) in the Foundry actor directory and pick **Dragonroll: Force Sync**.
|
||||
Those actors, together with the gear carried inside them, are pushed to the campaign immediately even
|
||||
when autosync is off. It is an upsert only: it never prunes the campaign's other actors, which a full
|
||||
snapshot does and a forced sync never claims to. Actors Dragonroll does not import (anything that is
|
||||
not a character, NPC or creature) are refused with a notification.
|
||||
when autosync is off, **replacing everything that campaign holds for them** (Syndria98/dragonroll#96):
|
||||
what the campaign had edited on those actors is written over by what the world says. It replaces
|
||||
those actors only — it never prunes the campaign's other actors, which a full snapshot does and a
|
||||
forced sync never claims to. Actors Dragonroll does not import (anything that is not a character, NPC
|
||||
or creature) are refused with a notification.
|
||||
|
||||
The optional read-only snapshot bridge is not affected: it keeps publishing the world snapshot behind
|
||||
`/api/foundry/*`, which is never written into the campaign.
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user