[Feature] Item Resource Support (#328)

* Initial

* Resource setup finished

* Fixed so that costs can be used

* Corrected standard resources

* Actions can only use item resources from their parent item

* Fixed up dice

* Fixed resource dice positioning

* Fixed parsing of resource.max

* Fixed styling on settings tab

* Added manual input for Dice Resources

* Lightmode fixes

* Fixed Feature spellcasting modifier

* Bugfix for item input to resourceDiceDialog

* Item fix for TokenInput

* PR Fixes
This commit is contained in:
WBHarry 2025-07-14 01:12:32 +02:00 committed by GitHub
parent eefa116d9a
commit 4be3e6179c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
53 changed files with 972 additions and 329 deletions

View file

@ -1,3 +1,5 @@
import { itemAbleRollParse } from './utils.mjs';
export default class RegisterHandlebarsHelpers {
static registerHelpers() {
Handlebars.registerHelper({
@ -6,8 +8,7 @@ export default class RegisterHandlebarsHelpers {
times: this.times,
damageFormula: this.damageFormula,
damageSymbols: this.damageSymbols,
tertiary: this.tertiary,
signedNumber: this.signedNumber
rollParsed: this.rollParsed
});
}
@ -43,7 +44,9 @@ export default class RegisterHandlebarsHelpers {
return new Handlebars.SafeString(Array.from(symbols).map(symbol => `<i class="fa-solid ${symbol}"></i>`));
}
static tertiary(a, b) {
return a ?? b;
static rollParsed(value, actor, item, numerical) {
const isNumerical = typeof numerical === 'boolean' ? numerical : false;
const result = itemAbleRollParse(value, actor, item);
return isNumerical && !result ? 0 : result;
}
}

View file

@ -245,10 +245,10 @@ export const getDamageLabel = damage => {
export const damageKeyToNumber = key => {
return {
'none': 0,
'minor': 1,
'major': 2,
'severe': 3
none: 0,
minor: 1,
major: 2,
severe: 3
}[key];
};
@ -299,3 +299,15 @@ export const updateActorTokens = async (actor, update) => {
}
}
};
export const itemAbleRollParse = (value, actor, item) => {
if (!value) return value;
const isItemTarget = value.toLowerCase().startsWith('item.');
const slicedValue = isItemTarget ? value.slice(5) : value;
try {
return Roll.safeEval(Roll.replaceFormulaData(slicedValue, isItemTarget ? item : actor));
} catch (_) {
return '';
}
};