Merge branch '22-attribute-roll-bug' into 'master'

22: Refactor roll attributes in helper class

Closes #22

See merge request foundrynet/worldbuilding!12
This commit is contained in:
Andrew 2020-10-30 16:08:33 +00:00
commit e53d4a7e52

View file

@ -181,7 +181,8 @@ export class EntitySheetHelper {
const label = button.closest(".attribute").querySelector(".attribute-label")?.value; const label = button.closest(".attribute").querySelector(".attribute-label")?.value;
const chatLabel = label ?? button.parentElement.querySelector(".attribute-key").value; const chatLabel = label ?? button.parentElement.querySelector(".attribute-key").value;
const shorthand = game.settings.get("worldbuilding", "macroShorthand"); const shorthand = game.settings.get("worldbuilding", "macroShorthand");
const rollData = this.object.getRollData(); // Use the actor for rollData so that formulas are always in reference to the parent actor.
const rollData = this.actor.getRollData();
let formula = button.closest(".attribute").querySelector(".attribute-value")?.value; let formula = button.closest(".attribute").querySelector(".attribute-value")?.value;
// If there's a formula, attempt to roll it. // If there's a formula, attempt to roll it.
@ -531,9 +532,14 @@ export class EntitySheetHelper {
let dataRgx = new RegExp(/@([a-z.0-9_\-]+)/gi); let dataRgx = new RegExp(/@([a-z.0-9_\-]+)/gi);
let rollFormula = formula.replace(dataRgx, (match, term) => { let rollFormula = formula.replace(dataRgx, (match, term) => {
let value = getProperty(data, term); let value = getProperty(data, term);
if ( value === null ) return "0"; // If there was a value returned, trim and return it.
if ( String(value).includes('@') ) return value; if ( value ) {
else return `@${term}`; return String(value).trim();
}
// Otherwise, return either the missing replacement value, or the original @attr string for later replacement.
else {
return missing != null ? missing : `@${term}`;
}
}); });
return rollFormula; return rollFormula;
} }