From 3c9951966027e3f88e3e68844bdeb278a0d35a7e Mon Sep 17 00:00:00 2001 From: WBHarry Date: Sun, 3 May 2026 19:04:44 +0200 Subject: [PATCH] Start of different outcomes --- .../sheets-configs/action-base-config.mjs | 26 +++++++++++++------ module/data/fields/action/damageField.mjs | 10 ++++--- templates/actionTypes/damage.hbs | 4 +-- .../action-settings/effect.hbs | 17 +++++++++++- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/module/applications/sheets-configs/action-base-config.mjs b/module/applications/sheets-configs/action-base-config.mjs index a20cc251..51243f39 100644 --- a/module/applications/sheets-configs/action-base-config.mjs +++ b/module/applications/sheets-configs/action-base-config.mjs @@ -1,3 +1,4 @@ +import { AltDamageOutcome } from '../../data/fields/action/damageField.mjs'; import { getUnusedDamageTypes } from '../../helpers/utils.mjs'; import DaggerheartSheet from '../sheets/daggerheart-sheet.mjs'; @@ -62,7 +63,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) id: 'configuration', template: 'systems/daggerheart/templates/sheets-settings/action-settings/configuration.hbs' }, - configuration: { + range: { id: 'range', template: 'systems/daggerheart/templates/sheets-settings/action-settings/range.hbs' }, @@ -120,19 +121,19 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) }; static OUTCOME_TABS = { - successWithHope: { + successHope: { active: true, cssClass: '', group: 'outcomes', - id: 'successWithHope', + id: 'successHope', icon: null, label: 'Success With Hope' }, - successWithFear: { + successFear: { active: false, cssClass: '', group: 'outcomes', - id: 'successWithFear', + id: 'successFear', icon: null, label: 'Success With Fear' }, @@ -188,7 +189,6 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) context.tabs = this._getTabs(this.constructor.TABS); context.outcomeTabs = this._getTabs(this.constructor.OUTCOME_TABS); - context.outcomeData = context.outcomeTabs.successWithHope.active ? context.source.damage : context.source.damage.altOutcomes.successWithFear; context.config = CONFIG.DH; if (this.action.damage) { @@ -334,9 +334,10 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); } - static addDamage(_event) { + static addDamage(_event, button) { if (!this.action.damage.parts) return; + const outcome = button.dataset.outcome; const choices = getUnusedDamageTypes(this.action._source.damage.parts); const content = new foundry.data.fields.StringField({ label: game.i18n.localize('Damage Type'), @@ -360,7 +361,16 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) if (type === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) part.type = this.action.schema.fields.damage.fields.parts.element.fields.type.element.initial; - data.damage.parts[type] = part; + if (outcome === 'successHope') + data.damage.parts[type] = part; + else { + if (!data.damage.altOutcomes[outcome]) { + data.damage.altOutcomes[outcome] = new AltDamageOutcome(); + } + + data.damage.altOutcomes[outcome].parts[type] = part; + } + this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); }; diff --git a/module/data/fields/action/damageField.mjs b/module/data/fields/action/damageField.mjs index ba8277ef..6c0d2a88 100644 --- a/module/data/fields/action/damageField.mjs +++ b/module/data/fields/action/damageField.mjs @@ -343,16 +343,18 @@ export class DHDamageData extends DHResourceData { } } -class AltDamageOutcome extends foundry.abstract.DataModel { +export class AltDamageOutcome extends foundry.abstract.DataModel { static defineSchema() { return { - copyStandard: new fields.BooleanField({ required: true, initial: true }), + useStandardHitPointDamage: new fields.BooleanField({ required: true, initial: true }), ...getDamageBaseFields(), - /* Stuff */ } } get data() { - return this.copyStandard ? this.parent : {}; // If not copying, return data from the this alternate outcome + return { + ...this.parent, + ...this, + } } } \ No newline at end of file diff --git a/templates/actionTypes/damage.hbs b/templates/actionTypes/damage.hbs index 03300840..f1952c78 100644 --- a/templates/actionTypes/damage.hbs +++ b/templates/actionTypes/damage.hbs @@ -6,7 +6,7 @@ {{else}} {{localize "DAGGERHEART.GENERAL.damage"}} {{/if}} - {{#unless (eq path 'system.attack.')}}{{/unless}} + {{#unless (eq path 'system.attack.')}}{{/unless}}
{{#if @root.hasBaseDamage}} @@ -19,7 +19,7 @@ {{formField baseFields.groupAttack value=source.groupAttack name=(concat path "damage.groupAttack") localize=true classes="select"}} {{/if}}
- + {{!-- 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 key|}}
diff --git a/templates/sheets-settings/action-settings/effect.hbs b/templates/sheets-settings/action-settings/effect.hbs index aa22a28e..ea30eddf 100644 --- a/templates/sheets-settings/action-settings/effect.hbs +++ b/templates/sheets-settings/action-settings/effect.hbs @@ -12,8 +12,23 @@
{{/each}} + + {{#each outcomeTabs as |tab|}} +
+ {{#if (eq tab.id 'successHope')}} + {{#if ../fields.damage}}{{> 'systems/daggerheart/templates/actionTypes/damage.hbs' fields=../fields.damage.fields.parts.element.fields source=../source.damage baseFields=../fields.damage.fields outcome=tab.id }}{{/if}} + {{else}} + {{#with (lookup ../fields.damage.fields.altOutcomes.fields tab.id) as |field|}} + {{> 'systems/daggerheart/templates/actionTypes/damage.hbs' fields=field.fields.parts.element.fields source=(lookup ../../source.damage.altOutcomes ../id) baseFields=field.fields outcome=../id }} + {{/with }} + {{/if}} +
+ {{/each}} - {{#if fields.damage}}{{> 'systems/daggerheart/templates/actionTypes/damage.hbs' fields=fields.damage.fields.parts.element.fields source=outcomeData baseFields=fields.damage.fields }}{{/if}} {{#if fields.macro}}{{> 'systems/daggerheart/templates/actionTypes/macro.hbs' fields=fields.macro source=source.macro}}{{/if}} {{#if fields.effects}}{{> 'systems/daggerheart/templates/actionTypes/effect.hbs' fields=fields.effects.element.fields source=source.effects}}{{/if}} {{#if fields.beastform}}{{> 'systems/daggerheart/templates/actionTypes/beastform.hbs' fields=fields.beastform.fields source=source.beastform}}{{/if}}