From f5e1b45065b3131041adce38c3458db1210a905e Mon Sep 17 00:00:00 2001 From: WBHarry Date: Sun, 22 Mar 2026 14:37:30 +0100 Subject: [PATCH] Fixed conditional choices resource paths and ResourcesField.getField function --- .../sheets-configs/activeEffectConfig.mjs | 23 ++++++++++++++----- module/data/fields/actorField.mjs | 12 ++++++---- .../sheets/activeEffect/conditionals.hbs | 2 +- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/module/applications/sheets-configs/activeEffectConfig.mjs b/module/applications/sheets-configs/activeEffectConfig.mjs index 1db08d34..3a993da0 100644 --- a/module/applications/sheets-configs/activeEffectConfig.mjs +++ b/module/applications/sheets-configs/activeEffectConfig.mjs @@ -4,7 +4,8 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac constructor(options) { super(options); - this.changeChoices = DhActiveEffectConfig.getChangeChoices(); + this.changeChoices = this.#getChangeChoices(); + this.conditionalChoices = this.#getChangeChoices({ resourceValuePaths: true }); } static DEFAULT_OPTIONS = { @@ -50,7 +51,7 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac * Get ChangeChoices for the changes autocomplete. Static for use in this class aswell as in settings-active-effect-config.mjs * @returns {ChangeChoice { value: string, label: string, hint: string, group: string }[]} */ - static getChangeChoices() { + #getChangeChoices(options = { resourceValuePaths: false }) { const ignoredActorKeys = ['config', 'DhEnvironment', 'DhParty']; const getAllLeaves = (root, group, parentPath = '') => { @@ -70,6 +71,8 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac return leaves; }; + + const resourcePathEnding = options.resourceValuePaths ? 'value' : 'max'; return Object.keys(game.system.api.models.actors).reduce((acc, key) => { if (ignoredActorKeys.includes(key)) return acc; @@ -78,11 +81,17 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac const attributes = CONFIG.Token.documentClass.getTrackedAttributes(model.metadata.type); const getTranslations = path => { - if (path === 'resources.hope.max') + if (path === 'resources.hope.max') { return { label: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.FIELDS.maxHope.label'), hint: '' }; + } else if (path === 'resources.hope.value') { + return { + label: game.i18n.localize('DAGGERHEART.GENERAL.hope'), + hint: '' + }; + } const field = model.schema.getField(path); return { @@ -92,7 +101,7 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac }; const bars = attributes.bar.flatMap(x => { - const joined = `${x.join('.')}.max`; + const joined = `${x.join('.')}.${resourcePathEnding}`; return { value: joined, ...getTranslations(joined), group }; }); const values = attributes.value.flatMap(x => { @@ -112,16 +121,18 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac _attachPartListeners(partId, htmlElement, options) { super._attachPartListeners(partId, htmlElement, options); const changeChoices = this.changeChoices; + const conditionalChoices = this.conditionalChoices; htmlElement.querySelectorAll('.effect-change-input').forEach(element => { + const choices = element.classList.contains('conditional-key-input') ? conditionalChoices : changeChoices; autocomplete({ input: element, fetch: function (text, update) { if (!text) { - update(changeChoices); + update(choices); } else { text = text.toLowerCase(); - var suggestions = changeChoices.filter(n => n.label.toLowerCase().includes(text)); + var suggestions = choices.filter(n => n.label.toLowerCase().includes(text)); update(suggestions); } }, diff --git a/module/data/fields/actorField.mjs b/module/data/fields/actorField.mjs index 25e04317..e4dcb8e9 100644 --- a/module/data/fields/actorField.mjs +++ b/module/data/fields/actorField.mjs @@ -89,13 +89,17 @@ class ResourcesField extends fields.TypedObjectField { */ _getField(path) { if (path.length === 0) return this; - const first = path.shift(); - if (first === this.element.name) return this.element_getField(path); + const first = path.pop(); const resources = CONFIG.DH.RESOURCE[this.actorType].all; if (first in resources) { - this.element.label = resources[first].label; - return this.element._getField(path); + const field = this.element._getField(path); + const resourceName = game.i18n.localize(resources[first].label); + field.label = + field.name === 'max' + ? game.i18n.format('DAGGERHEART.GENERAL.maxWithThing', { thing: resourceName }) + : resources[first].label; + return field; } return undefined; diff --git a/templates/sheets/activeEffect/conditionals.hbs b/templates/sheets/activeEffect/conditionals.hbs index 637ac33c..f8230d94 100644 --- a/templates/sheets/activeEffect/conditionals.hbs +++ b/templates/sheets/activeEffect/conditionals.hbs @@ -32,7 +32,7 @@
- +