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:
@@ -130,7 +130,11 @@ function foundryTraits(source, items) {
|
||||
return features.length ? features.join('\n\n') : undefined;
|
||||
}
|
||||
|
||||
function foundryActorToCharacter(foundryActor) {
|
||||
// `replace` is a forced actor sync from the module's context menu (Syndria98/dragonroll#96):
|
||||
// it replaces everything the campaign holds for this actor, so the fields a live edit
|
||||
// leaves out when the world says nothing are written empty instead of kept. A live Foundry
|
||||
// change passes `false` and keeps the campaign's own toggles and text.
|
||||
function foundryActorToCharacter(foundryActor, replace = false) {
|
||||
const system = foundryActor.system || {};
|
||||
const details = system.details || {};
|
||||
const abilities = system.abilities || {};
|
||||
@@ -169,7 +173,9 @@ function foundryActorToCharacter(foundryActor) {
|
||||
])),
|
||||
armorClass: numberOr(attributes.ac?.value ?? attributes.ac, 10),
|
||||
speed: numberOr(movement.walk ?? movement.value, 30),
|
||||
proficiencies: foundryProficiencies || asText(savedDragonrollFields.proficiencies),
|
||||
// A replace takes the world's text even when it has none, so what Dragonroll
|
||||
// cached on the actor's flag does not survive it; a live edit keeps that text.
|
||||
proficiencies: foundryProficiencies || (replace ? '' : asText(savedDragonrollFields.proficiencies)),
|
||||
// What the character carries: gear, and gear only (Syndria98/dragonroll#89). A feat
|
||||
// is a trait — its tab shows it — and a race is the species; standing them in the
|
||||
// inventory next to the longswords is how traits and items got mixed up.
|
||||
@@ -201,9 +207,21 @@ function foundryActorToCharacter(foundryActor) {
|
||||
const currency = foundryCurrency(system);
|
||||
if (currency) fields.currency = currency;
|
||||
const worldTraits = foundryTraits(foundryActor, items);
|
||||
const campaignTraits = asText(savedDragonrollFields.traits);
|
||||
const campaignTraits = replace ? '' : asText(savedDragonrollFields.traits);
|
||||
if (worldTraits || campaignTraits) fields.traits = worldTraits || campaignTraits;
|
||||
|
||||
// A replace writes the fields a live edit would leave out when the world says
|
||||
// nothing, so the campaign's toggles, lists and text for this actor go with it and
|
||||
// the row reads as the Foundry actor alone (Syndria98/dragonroll#96).
|
||||
if (replace) {
|
||||
if (fields.skills === undefined) fields.skills = {};
|
||||
if (fields.savingThrows === undefined) fields.savingThrows = {};
|
||||
if (fields.tools === undefined) fields.tools = [];
|
||||
if (fields.languages === undefined) fields.languages = [];
|
||||
if (fields.currency === undefined) fields.currency = {};
|
||||
if (fields.traits === undefined) fields.traits = '';
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user