Fix issue #77: Add a "force import from foundry" context button
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:
@@ -62,11 +62,14 @@ async function saveFoundryActor(campaign, source, fullSync = false) {
|
||||
: new Actor({ campaign: campaign._id });
|
||||
}
|
||||
actor.foundryActorId = foundryActorId;
|
||||
// `created` says whether this row is new: whoever imports a whole world counts
|
||||
// the rows it made apart from the ones it only wrote over.
|
||||
const created = actor.isNew;
|
||||
// A full snapshot runs when a GM reconnects. Preserve existing Dragonroll
|
||||
// edits then; live Foundry change events continue to overwrite normally.
|
||||
if (!fullSync || actor.isNew) Object.assign(actor, fields);
|
||||
await actor.save();
|
||||
return { foundryActorId, actorId: actor.id };
|
||||
return { foundryActorId, actorId: actor.id, created };
|
||||
}
|
||||
|
||||
// The campaign's item list mirrors the world's item directory and nothing else
|
||||
@@ -105,6 +108,9 @@ async function saveFoundryItem(campaign, source, fullSync = false, folders = nul
|
||||
}
|
||||
|
||||
item.foundryItemId = foundryItemId;
|
||||
// `created` says whether this row is new: whoever imports a whole world counts
|
||||
// the rows it made apart from the ones it only wrote over.
|
||||
const created = item.isNew;
|
||||
if (!fullSync || item.isNew) Object.assign(item, fields);
|
||||
// Foundry's own icon is kept on every save, not only when the edits above
|
||||
// land: the item window offers it back after the user picked their own.
|
||||
@@ -120,7 +126,7 @@ async function saveFoundryItem(campaign, source, fullSync = false, folders = nul
|
||||
const folder = resolveFoundryItemFolder(source, folders);
|
||||
if (folder !== undefined) item.folder = folder;
|
||||
await item.save();
|
||||
return { foundryItemId, itemId: item.id };
|
||||
return { foundryItemId, itemId: item.id, created };
|
||||
}
|
||||
|
||||
async function syncFoundryItems(campaign, sources, fullSync = false, folders = null) {
|
||||
@@ -447,3 +453,9 @@ router.post('/sync/map-item', async (req, res) => {
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
// The writers every Foundry document goes through: the sync pushes above, and the
|
||||
// force import a campaign asks for from its sidebar (routes/foundry.js). One set of
|
||||
// rules decides which campaign row a world document owns, so pulling a world over
|
||||
// twice updates its rows instead of doubling them.
|
||||
module.exports.saveFoundryActor = saveFoundryActor;
|
||||
module.exports.saveFoundryItem = saveFoundryItem;
|
||||
|
||||
Reference in New Issue
Block a user