From 64ce6151162d7856f3d920ff034835b32a4b9eb7 Mon Sep 17 00:00:00 2001 From: WBHarry <89362246+WBHarry@users.noreply.github.com> Date: Tue, 24 Mar 2026 17:33:17 +0100 Subject: [PATCH] [V14] 1743 - Damage Update Error (#1746) * Fixed DamageParts causing errors on update * Fixed ActionBaseConfig error when no damage present on the action * Fix removal of damage field * Removed unneccessary default value function for parts --------- Co-authored-by: Carlos Fernandez --- .../sheets-configs/action-base-config.mjs | 14 ++++++---- module/data/fields/actionField.mjs | 1 + templates/actionTypes/damage.hbs | 28 ++++++++++--------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/module/applications/sheets-configs/action-base-config.mjs b/module/applications/sheets-configs/action-base-config.mjs index 53c57ec5..7396894f 100644 --- a/module/applications/sheets-configs/action-base-config.mjs +++ b/module/applications/sheets-configs/action-base-config.mjs @@ -154,8 +154,13 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) context.openSection = this.openSection; context.tabs = this._getTabs(this.constructor.TABS); context.config = CONFIG.DH; - if (this.action.damage?.hasOwnProperty('includeBase') && this.action.type === 'attack') - context.hasBaseDamage = !!this.action.parent.attack; + if (this.action.hasDamage) { + context.allDamageTypesUsed = !getUnusedDamageTypes(this.action.damage.parts).length; + + if (this.action.damage.hasOwnProperty('includeBase') && this.action.type === 'attack') + context.hasBaseDamage = !!this.action.parent.attack; + } + context.costOptions = this.getCostOptions(); context.getRollTypeOptions = this.getRollTypeOptions(); context.disableOption = this.disableOption.bind(this); @@ -173,7 +178,6 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) revealed: this.openTrigger === index }; }); - context.allDamageTypesUsed = !getUnusedDamageTypes(this.action.damage.parts).length; const settingsTiers = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers).tiers; context.tierOptions = [ @@ -312,8 +316,8 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) const callback = (_, button) => { const data = this.action.toObject(); const type = choices[button.form.elements.type.value].value; - const part = { applyTo: type }; - if (this.action.actor?.isNPC) part.value = { multiplier: 'flat' }; + const part = this.action.schema.fields.damage.fields.parts.element.getInitialValue(); + part.applyTo = type; data.damage.parts[type] = part; this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); }; diff --git a/module/data/fields/actionField.mjs b/module/data/fields/actionField.mjs index ee5d221b..ffdc25cd 100644 --- a/module/data/fields/actionField.mjs +++ b/module/data/fields/actionField.mjs @@ -89,6 +89,7 @@ export class ActionField extends foundry.data.fields.ObjectField { /** @override */ _cleanType(value, options, _state) { if (!(typeof value === 'object')) value = {}; + value = super._cleanType(value, options, _state); const cls = this.getModel(value); if (cls) return cls.cleanData(value, options, _state); return value; diff --git a/templates/actionTypes/damage.hbs b/templates/actionTypes/damage.hbs index 6f159a2d..9e7c2884 100644 --- a/templates/actionTypes/damage.hbs +++ b/templates/actionTypes/damage.hbs @@ -16,50 +16,52 @@ {{formField directField value=source.direct name=(concat path "damage.direct") localize=true classes="checkbox"}} {{/unless}} - {{#each source.parts as |dmg key|}} + + {{!-- Handlebars uses Symbol.Iterator to produce index|key. This isn't compatible with our parts object, so we instead use applyTo, which is the same value --}} + {{#each source.parts as |dmg|}}
- {{localize (concat "DAGGERHEART.CONFIG.HealingType." key ".name")}} + {{localize (concat "DAGGERHEART.CONFIG.HealingType." dmg.applyTo ".name")}} {{#unless (or dmg.base ../path)}} - + {{/unless}} {{#if (and (not @root.isNPC) @root.hasRoll (not dmg.base))}} - {{formField ../fields.resultBased value=dmg.resultBased name=(concat "damage.parts." key ".resultBased") localize=true classes="checkbox"}} + {{formField ../fields.resultBased value=dmg.resultBased name=(concat "damage.parts." dmg.applyTo ".resultBased") localize=true classes="checkbox"}} {{/if}} {{#if (and (not @root.isNPC) @root.hasRoll (not dmg.base) dmg.resultBased)}}
{{localize "DAGGERHEART.GENERAL.withThing" thing=(localize "DAGGERHEART.GENERAL.hope")}} - {{> formula fields=../fields.value.fields type=../fields.type dmg=dmg source=dmg.value target="value" key=key path=../path}} + {{> formula fields=../fields.value.fields type=../fields.type dmg=dmg source=dmg.value target="value" key=dmg.applyTo path=../path}}
{{localize "DAGGERHEART.GENERAL.withThing" thing=(localize "DAGGERHEART.GENERAL.fear")}} - {{> formula fields=../fields.valueAlt.fields type=../fields.type dmg=dmg source=dmg.valueAlt target="valueAlt" key=key path=../path}} + {{> formula fields=../fields.valueAlt.fields type=../fields.type dmg=dmg source=dmg.valueAlt target="valueAlt" key=dmg.applyTo path=../path}}
{{else}} - {{> formula fields=../fields.value.fields type=../fields.type dmg=dmg source=dmg.value target="value" key=key path=../path}} + {{> formula fields=../fields.value.fields type=../fields.type dmg=dmg source=dmg.value target="value" key=dmg.applyTo path=../path}} {{/if}} {{#if (and (eq dmg.applyTo 'hitPoints') (ne @root.source.type 'healing'))}} - {{formField ../fields.type value=dmg.type name=(concat ../path "damage.parts." key ".type") localize=true}} + {{formField ../fields.type value=dmg.type name=(concat ../path "damage.parts." dmg.applyTo ".type") localize=true}} {{/if}} {{#if ../horde}}
{{localize "DAGGERHEART.ACTORS.Adversary.hordeDamage"}}
- - {{formField ../fields.valueAlt.fields.flatMultiplier value=dmg.valueAlt.flatMultiplier name=(concat ../path "damage.parts." key ".valueAlt.flatMultiplier") label="DAGGERHEART.ACTIONS.Settings.multiplier" classes="inline-child" localize=true }} - {{formField ../fields.valueAlt.fields.dice value=dmg.valueAlt.dice name=(concat ../path "damage.parts." key ".valueAlt.dice") classes="inline-child" localize=true}} - {{formField ../fields.valueAlt.fields.bonus value=dmg.valueAlt.bonus name=(concat ../path "damage.parts." key ".valueAlt.bonus") localize=true classes="inline-child"}} + + {{formField ../fields.valueAlt.fields.flatMultiplier value=dmg.valueAlt.flatMultiplier name=(concat ../path "damage.parts." dmg.applyTo ".valueAlt.flatMultiplier") label="DAGGERHEART.ACTIONS.Settings.multiplier" classes="inline-child" localize=true }} + {{formField ../fields.valueAlt.fields.dice value=dmg.valueAlt.dice name=(concat ../path "damage.parts." dmg.applyTo ".valueAlt.dice") classes="inline-child" localize=true}} + {{formField ../fields.valueAlt.fields.bonus value=dmg.valueAlt.bonus name=(concat ../path "damage.parts." dmg.applyTo ".valueAlt.bonus") localize=true classes="inline-child"}}
{{/if}} - +
{{/each}}