Merge branch 'main' into 419-feature-add-createtagsmethods-for-documents-and-actions

This commit is contained in:
Joaquin Pereyra 2025-07-31 22:56:32 -03:00
commit 9a4d10429f
773 changed files with 72685 additions and 1139 deletions

View file

@ -7,6 +7,7 @@ export default class RegisterHandlebarsHelpers {
includes: this.includes,
times: this.times,
damageFormula: this.damageFormula,
formulaValue: this.formulaValue,
damageSymbols: this.damageSymbols,
rollParsed: this.rollParsed,
hasProperty: foundry.utils.hasProperty,
@ -39,6 +40,15 @@ export default class RegisterHandlebarsHelpers {
return instances.join(traitTotal > 0 ? ' + ' : ' - ');
}
static formulaValue(formula, item) {
if (isNaN(formula)) {
const data = item.getRollData.bind(item)(),
roll = new Roll(Roll.replaceFormulaData(formula, data)).evaluateSync();
formula = roll.total;
}
return formula;
}
static damageSymbols(damageParts) {
const symbols = [...new Set(damageParts.reduce((a, c) => a.concat([...c.type]), []))].map(
p => CONFIG.DH.GENERAL.damageTypes[p].icon

View file

@ -5,9 +5,12 @@ export const capitalize = string => {
return string.charAt(0).toUpperCase() + string.slice(1);
};
export function rollCommandToJSON(text) {
export function rollCommandToJSON(text, raw) {
if (!text) return {};
const flavorMatch = raw?.match(/{(.*)}$/);
const flavor = flavorMatch ? flavorMatch[1] : null;
// Match key="quoted string" OR key=unquotedValue
const PAIR_RE = /(\w+)=("(?:[^"\\]|\\.)*"|\S+)/g;
const result = {};
@ -28,7 +31,7 @@ export function rollCommandToJSON(text) {
}
result[key] = value;
}
return Object.keys(result).length > 0 ? result : null;
return Object.keys(result).length > 0 ? { result, flavor } : null;
}
export const getCommandTarget = (options = {}) => {
@ -307,8 +310,8 @@ export function updateLinkedItemApps(options, sheet) {
export const itemAbleRollParse = (value, actor, item) => {
if (!value) return value;
const isItemTarget = value.toLowerCase().startsWith('item.');
const slicedValue = isItemTarget ? value.slice(5) : value;
const isItemTarget = value.toLowerCase().includes('item.@');
const slicedValue = isItemTarget ? value.replaceAll(/item\.@/gi, '@') : value;
try {
return Roll.replaceFormulaData(slicedValue, isItemTarget ? item : actor);
} catch (_) {