diff --git a/module/applications/sheets-configs/action-base-config.mjs b/module/applications/sheets-configs/action-base-config.mjs index d09e464f..0befa525 100644 --- a/module/applications/sheets-configs/action-base-config.mjs +++ b/module/applications/sheets-configs/action-base-config.mjs @@ -1,4 +1,4 @@ -import { AltDamageOutcome } from '../../data/fields/action/damageField.mjs'; +import { AltOutcome } from '../../data/action/altOutcome.mjs'; import { getUnusedDamageTypes } from '../../helpers/utils.mjs'; import DaggerheartSheet from '../sheets/daggerheart-sheet.mjs'; @@ -10,8 +10,6 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) this.action = action; this.openSection = null; this.openTrigger = this.action.triggers.length > 0 ? 0 : null; - - this.outcomeTabs = DHActionBaseConfig.getOutcomeTabs(action); } get title() { @@ -125,7 +123,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) static getOutcomeTabs(action) { const outcomeKeys = [ 'default', - ...Object.keys(action.damage?.altOutcomes ?? {}).filter(key => action.damage.altOutcomes[key]) + ...Object.keys(action.altOutcomes ?? {}).filter(key => action.altOutcomes[key]) ]; return outcomeKeys.reduce((acc, key, index) => { acc[key] = { @@ -134,7 +132,10 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) group: 'outcomes', id: key, icon: null, - label: game.i18n.localize(CONFIG.DH.ACTIONS.outcomeTypes[key].label) + label: game.i18n.localize(CONFIG.DH.ACTIONS.outcomeTypes[key].label), + source: key === 'default' ? action._source : action._source.altOutcomes[key], + fields: key === 'default' ? action.schema.fields : action.schema.fields.altOutcomes.fields[key].fields, + getBasePath: path => (key === 'default' ? path : ['altOutcomes', key, path].join('.')) }; return acc; }, {}); @@ -143,7 +144,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) /* Needs to consider effect altOutcomes aswell */ static selectOutcome(action, callback) { const choices = Object.entries(CONFIG.DH.ACTIONS.outcomeTypes).reduce((acc, [key, value]) => { - if (action.damage.altOutcomes[key] === null) acc.push({ id: key, label: game.i18n.localize(value.label) }); + if (action.altOutcomes[key] === null) acc.push({ id: key, label: game.i18n.localize(value.label) }); return acc; }, []); @@ -237,8 +238,8 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) context.openSection = this.openSection; context.tabs = this._getTabs(this.constructor.TABS); - context.outcomeTabs = this._getTabs(this.outcomeTabs); - context.allOutcomesAssigned = Object.keys(this.outcomeTabs).length >= 4; + context.outcomeTabs = this._getTabs(DHActionBaseConfig.getOutcomeTabs(this.action)); + context.allOutcomesAssigned = Object.keys(context.outcomeTabs).length >= 4; context.config = CONFIG.DH; if (this.action.damage) { @@ -388,9 +389,8 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) if (!this.action.damage.parts) return; const outcome = button.dataset.outcome; - const source = this.action._source; - const outcomeParts = outcome === 'default' ? source.damage.parts : source.damage.altOutcomes[outcome].parts; - const choices = getUnusedDamageTypes(outcomeParts); + const outcomeData = outcome === 'default' ? this.action._source : this.action._source.altOutcomes[outcome]; + const choices = getUnusedDamageTypes(outcomeData.damage.parts); const content = new foundry.data.fields.StringField({ label: game.i18n.localize('Damage Type'), choices, @@ -413,8 +413,8 @@ 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; } - if (outcome !== 'default') data.damage.altOutcomes[outcome] ??= new AltDamageOutcome(); - (outcome === 'default' ? data.damage : data.damage.altOutcomes[outcome]).parts[type] = part; + if (outcome !== 'default') data.altOutcomes[outcome] ??= new AltOutcome(); + (outcome === 'default' ? data : data.altOutcomes[outcome]).damage.parts[type] = part; this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); }; @@ -444,8 +444,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) if (!this.action.damage.parts) return; const data = this.action.toObject(); const { key, outcome } = button.dataset; - const parts = outcome === 'default' ? data.damage.parts : data.damage.altOutcomes[outcome].parts; - parts[key] = _del; + (outcome === 'default' ? data : data.altOutcomes[outcome]).damage.parts[key] = _del; this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); } diff --git a/module/applications/sheets-configs/action-config.mjs b/module/applications/sheets-configs/action-config.mjs index a4b0a6c4..444a60fe 100644 --- a/module/applications/sheets-configs/action-config.mjs +++ b/module/applications/sheets-configs/action-config.mjs @@ -1,4 +1,4 @@ -import { AltDamageOutcome } from '../../data/fields/action/damageField.mjs'; +import { AltOutcome } from '../../data/action/altOutcome.mjs'; import DHActionBaseConfig from './action-base-config.mjs'; export default class DHActionConfig extends DHActionBaseConfig { @@ -27,9 +27,7 @@ export default class DHActionConfig extends DHActionBaseConfig { DHActionBaseConfig.selectOutcome(this.action, key => { if (!key) return; - - data.damage.altOutcomes[key] = new AltDamageOutcome(); - this.outcomeTabs = DHActionBaseConfig.getOutcomeTabs(data); + data.altOutcomes[key] = new AltOutcome(); this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); }); } @@ -37,10 +35,7 @@ export default class DHActionConfig extends DHActionBaseConfig { static onRemoveOutcome(_event, button) { const { outcome } = button.dataset; const data = this.action.toObject(); - - data.damage.altOutcomes[outcome] = null; - this.outcomeTabs = DHActionBaseConfig.getOutcomeTabs(data); - + data.altOutcomes[outcome] = null; this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); } diff --git a/module/data/action/altOutcome.mjs b/module/data/action/altOutcome.mjs new file mode 100644 index 00000000..95f75f73 --- /dev/null +++ b/module/data/action/altOutcome.mjs @@ -0,0 +1,19 @@ +import { getDamageBaseFields } from '../fields/action/damageField.mjs'; + +const fields = foundry.data.fields; + +export class AltOutcome extends foundry.abstract.DataModel { + static defineSchema() { + return { + damage: new fields.SchemaField(getDamageBaseFields()) + // todo: add effects + }; + } + + get data() { + return { + ...this.parent, + ...this + }; + } +} diff --git a/module/data/action/damageAction.mjs b/module/data/action/damageAction.mjs index 51735543..f7814181 100644 --- a/module/data/action/damageAction.mjs +++ b/module/data/action/damageAction.mjs @@ -1,8 +1,23 @@ +import { AltOutcome } from './altOutcome.mjs'; import DHBaseAction from './baseAction.mjs'; +const fields = foundry.data.fields; + export default class DHDamageAction extends DHBaseAction { static extraSchemas = [...super.extraSchemas, 'damage', 'target', 'effects']; + static defineSchema() { + return { + ...super.defineSchema(), + altOutcomes: new fields.SchemaField({ + successHope: new fields.EmbeddedDataField(AltOutcome, { nullable: true, initial: null }), + successFear: new fields.EmbeddedDataField(AltOutcome, { nullable: true, initial: null }), + failureHope: new fields.EmbeddedDataField(AltOutcome, { nullable: true, initial: null }), + failureFear: new fields.EmbeddedDataField(AltOutcome, { nullable: true, initial: null }) + }) + }; + } + /** * Return a display ready damage formula string * @returns Formula string diff --git a/module/data/fields/action/damageField.mjs b/module/data/fields/action/damageField.mjs index 78c27774..6520b6da 100644 --- a/module/data/fields/action/damageField.mjs +++ b/module/data/fields/action/damageField.mjs @@ -4,7 +4,7 @@ import IterableTypedObjectField from '../iterableTypedObjectField.mjs'; const fields = foundry.data.fields; -const getDamageBaseFields = () => ({ +export const getDamageBaseFields = () => ({ parts: new IterableTypedObjectField(DHDamageData), includeBase: new fields.BooleanField({ initial: false, @@ -23,12 +23,6 @@ export default class DamageField extends fields.SchemaField { constructor(options, context = {}) { const damageFields = { ...getDamageBaseFields(), - altOutcomes: new fields.SchemaField({ - successHope: new fields.EmbeddedDataField(AltDamageOutcome, { nullable: true, initial: null }), - successFear: new fields.EmbeddedDataField(AltDamageOutcome, { nullable: true, initial: null }), - failureHope: new fields.EmbeddedDataField(AltDamageOutcome, { nullable: true, initial: null }), - failureFear: new fields.EmbeddedDataField(AltDamageOutcome, { nullable: true, initial: null }) - }), groupAttack: new fields.StringField({ choices: CONFIG.DH.GENERAL.groupAttackRange, blank: true, @@ -342,18 +336,3 @@ export class DHDamageData extends DHResourceData { }; } } - -export class AltDamageOutcome extends foundry.abstract.DataModel { - static defineSchema() { - return { - ...getDamageBaseFields() - }; - } - - get data() { - return { - ...this.parent, - ...this - }; - } -} diff --git a/templates/actionTypes/damage.hbs b/templates/actionTypes/damage.hbs index fef6591e..83715564 100644 --- a/templates/actionTypes/damage.hbs +++ b/templates/actionTypes/damage.hbs @@ -38,15 +38,15 @@
{{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=dmg.applyTo path=../path outcomePath=../outcomePath}} + {{> formula fields=../fields.value.fields type=../fields.type dmg=dmg source=dmg.value target="value" key=dmg.applyTo path=../path basePath=../basePath}}
{{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=dmg.applyTo path=../path outcomePath=../outcomePath}} + {{> formula fields=../fields.valueAlt.fields type=../fields.type dmg=dmg source=dmg.valueAlt target="valueAlt" key=dmg.applyTo path=../path basePath=../basePath}}
{{else}} - {{> formula fields=../fields.value.fields type=../fields.type dmg=dmg source=dmg.value target="value" key=dmg.applyTo path=../path outcomePath=../outcomePath}} + {{> formula fields=../fields.value.fields type=../fields.type dmg=dmg source=dmg.value target="value" key=dmg.applyTo path=../path basePath=../basePath}} {{/if}} {{#if (and (eq dmg.applyTo 'hitPoints') (ne @root.source.type 'healing'))}} @@ -72,21 +72,21 @@ {{#*inline "formula"}} {{#unless dmg.base}} - {{formField fields.custom.fields.enabled value=source.custom.enabled name=(concat path outcomePath ".parts." key "." target ".custom.enabled") classes="checkbox" localize=true}} + {{formField fields.custom.fields.enabled value=source.custom.enabled name=(concat path basePath ".parts." key "." target ".custom.enabled") classes="checkbox" localize=true}} {{/unless}} {{#if source.custom.enabled}} - {{formField fields.custom.fields.formula value=source.custom.formula name=(concat path outcomePath ".parts." key "." target ".custom.formula") localize=true}} + {{formField fields.custom.fields.formula value=source.custom.formula name=(concat path basePath ".parts." key "." target ".custom.formula") localize=true}} {{else}}
{{#unless @root.isNPC}} - {{formField fields.multiplier value=source.multiplier name=(concat path outcomePath ".parts." key "." target ".multiplier") localize=true}} + {{formField fields.multiplier value=source.multiplier name=(concat path basePath ".parts." key "." target ".multiplier") localize=true}} {{/unless}} - {{#if (eq source.multiplier 'flat')}}{{formField fields.flatMultiplier value=source.flatMultiplier name=(concat path outcomePath ".parts." key "." target ".flatMultiplier") localize=true }}{{/if}} - {{formField fields.dice value=source.dice name=(concat path outcomePath ".parts." key "." target ".dice") localize=true}} - {{formField fields.bonus value=source.bonus name=(concat path outcomePath ".parts." key "." target ".bonus") localize=true}} + {{#if (eq source.multiplier 'flat')}}{{formField fields.flatMultiplier value=source.flatMultiplier name=(concat path basePath ".parts." key "." target ".flatMultiplier") localize=true }}{{/if}} + {{formField fields.dice value=source.dice name=(concat path basePath ".parts." key "." target ".dice") localize=true}} + {{formField fields.bonus value=source.bonus name=(concat path basePath ".parts." key "." target ".bonus") localize=true}}
{{/if}} {{#if @root.isNPC}} - + {{/if}} {{/inline}} \ No newline at end of file diff --git a/templates/sheets-settings/action-settings/outcomes.hbs b/templates/sheets-settings/action-settings/outcomes.hbs index 442333a4..fb15bd06 100644 --- a/templates/sheets-settings/action-settings/outcomes.hbs +++ b/templates/sheets-settings/action-settings/outcomes.hbs @@ -21,14 +21,15 @@ data-group="outcomes" data-tab="{{tab.id}}" > - {{#if ../fields.damage}} - {{#if (eq tab.id 'default')}} - {{> 'systems/daggerheart/templates/actionTypes/damage.hbs' fields=../fields.damage.fields.parts.element.fields source=../source.damage baseFields=../fields.damage.fields outcome=tab.id outcomePath="damage" isDefaultDamage="true" }} - {{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 outcomePath=(concat "damage.altOutcomes." tab.id) }} - {{/with }} - {{/if}} + {{#if tab.fields.damage}} + {{> 'systems/daggerheart/templates/actionTypes/damage.hbs' + outcome=tab.id + fields=tab.fields.damage.fields.parts.element.fields + source=tab.source.damage + baseFields=tab.fields.damage.fields + isDefaultDamage="true" + basePath=(tab.getBasePath "damage") + }} {{/if}}