mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-05 20:34:15 +02:00
Merge 7e8d5ae5dc into 56b2688fc4
This commit is contained in:
commit
52a115a65b
7 changed files with 71 additions and 63 deletions
|
|
@ -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) });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) });
|
||||
}
|
||||
|
||||
|
|
|
|||
19
module/data/action/altOutcome.mjs
Normal file
19
module/data/action/altOutcome.mjs
Normal file
|
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -339,18 +333,3 @@ export class DHDamageData extends DHResourceData {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class AltDamageOutcome extends foundry.abstract.DataModel {
|
||||
static defineSchema() {
|
||||
return {
|
||||
...getDamageBaseFields()
|
||||
};
|
||||
}
|
||||
|
||||
get data() {
|
||||
return {
|
||||
...this.parent,
|
||||
...this
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,15 +38,15 @@
|
|||
<div class="nest-inputs">
|
||||
<fieldset class="one-column">
|
||||
<legend>{{localize "DAGGERHEART.GENERAL.withThing" thing=(localize "DAGGERHEART.GENERAL.hope")}}</legend>
|
||||
{{> 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}}
|
||||
</fieldset>
|
||||
<fieldset class="one-column">
|
||||
<legend>{{localize "DAGGERHEART.GENERAL.withThing" thing=(localize "DAGGERHEART.GENERAL.fear")}}</legend>
|
||||
{{> 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}}
|
||||
</fieldset>
|
||||
</div>
|
||||
{{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}}
|
||||
<div class="nest-inputs">
|
||||
{{#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}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#if @root.isNPC}}
|
||||
<input type="hidden" name="{{concat path outcomePath ".parts.{{key}}.{{target}}.multiplier"}}" value="flat">
|
||||
<input type="hidden" name="{{concat path basePath ".parts.{{key}}.{{target}}.multiplier"}}" value="flat">
|
||||
{{/if}}
|
||||
{{/inline}}
|
||||
|
|
@ -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}}
|
||||
|
||||
</section>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue