mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-06 04:44:16 +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 { getUnusedDamageTypes } from '../../helpers/utils.mjs';
|
||||||
import DaggerheartSheet from '../sheets/daggerheart-sheet.mjs';
|
import DaggerheartSheet from '../sheets/daggerheart-sheet.mjs';
|
||||||
|
|
||||||
|
|
@ -10,8 +10,6 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
this.action = action;
|
this.action = action;
|
||||||
this.openSection = null;
|
this.openSection = null;
|
||||||
this.openTrigger = this.action.triggers.length > 0 ? 0 : null;
|
this.openTrigger = this.action.triggers.length > 0 ? 0 : null;
|
||||||
|
|
||||||
this.outcomeTabs = DHActionBaseConfig.getOutcomeTabs(action);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get title() {
|
get title() {
|
||||||
|
|
@ -125,7 +123,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
static getOutcomeTabs(action) {
|
static getOutcomeTabs(action) {
|
||||||
const outcomeKeys = [
|
const outcomeKeys = [
|
||||||
'default',
|
'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) => {
|
return outcomeKeys.reduce((acc, key, index) => {
|
||||||
acc[key] = {
|
acc[key] = {
|
||||||
|
|
@ -134,7 +132,10 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
group: 'outcomes',
|
group: 'outcomes',
|
||||||
id: key,
|
id: key,
|
||||||
icon: null,
|
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;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
@ -143,7 +144,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
/* Needs to consider effect altOutcomes aswell */
|
/* Needs to consider effect altOutcomes aswell */
|
||||||
static selectOutcome(action, callback) {
|
static selectOutcome(action, callback) {
|
||||||
const choices = Object.entries(CONFIG.DH.ACTIONS.outcomeTypes).reduce((acc, [key, value]) => {
|
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;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
@ -237,8 +238,8 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
context.openSection = this.openSection;
|
context.openSection = this.openSection;
|
||||||
context.tabs = this._getTabs(this.constructor.TABS);
|
context.tabs = this._getTabs(this.constructor.TABS);
|
||||||
|
|
||||||
context.outcomeTabs = this._getTabs(this.outcomeTabs);
|
context.outcomeTabs = this._getTabs(DHActionBaseConfig.getOutcomeTabs(this.action));
|
||||||
context.allOutcomesAssigned = Object.keys(this.outcomeTabs).length >= 4;
|
context.allOutcomesAssigned = Object.keys(context.outcomeTabs).length >= 4;
|
||||||
|
|
||||||
context.config = CONFIG.DH;
|
context.config = CONFIG.DH;
|
||||||
if (this.action.damage) {
|
if (this.action.damage) {
|
||||||
|
|
@ -388,9 +389,8 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
if (!this.action.damage.parts) return;
|
if (!this.action.damage.parts) return;
|
||||||
|
|
||||||
const outcome = button.dataset.outcome;
|
const outcome = button.dataset.outcome;
|
||||||
const source = this.action._source;
|
const outcomeData = outcome === 'default' ? this.action._source : this.action._source.altOutcomes[outcome];
|
||||||
const outcomeParts = outcome === 'default' ? source.damage.parts : source.damage.altOutcomes[outcome].parts;
|
const choices = getUnusedDamageTypes(outcomeData.damage.parts);
|
||||||
const choices = getUnusedDamageTypes(outcomeParts);
|
|
||||||
const content = new foundry.data.fields.StringField({
|
const content = new foundry.data.fields.StringField({
|
||||||
label: game.i18n.localize('Damage Type'),
|
label: game.i18n.localize('Damage Type'),
|
||||||
choices,
|
choices,
|
||||||
|
|
@ -413,8 +413,8 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
if (type === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) {
|
if (type === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) {
|
||||||
part.type = this.action.schema.fields.damage.fields.parts.element.fields.type.element.initial;
|
part.type = this.action.schema.fields.damage.fields.parts.element.fields.type.element.initial;
|
||||||
}
|
}
|
||||||
if (outcome !== 'default') data.damage.altOutcomes[outcome] ??= new AltDamageOutcome();
|
if (outcome !== 'default') data.altOutcomes[outcome] ??= new AltOutcome();
|
||||||
(outcome === 'default' ? data.damage : data.damage.altOutcomes[outcome]).parts[type] = part;
|
(outcome === 'default' ? data : data.altOutcomes[outcome]).damage.parts[type] = part;
|
||||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
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;
|
if (!this.action.damage.parts) return;
|
||||||
const data = this.action.toObject();
|
const data = this.action.toObject();
|
||||||
const { key, outcome } = button.dataset;
|
const { key, outcome } = button.dataset;
|
||||||
const parts = outcome === 'default' ? data.damage.parts : data.damage.altOutcomes[outcome].parts;
|
(outcome === 'default' ? data : data.altOutcomes[outcome]).damage.parts[key] = _del;
|
||||||
parts[key] = _del;
|
|
||||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
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';
|
import DHActionBaseConfig from './action-base-config.mjs';
|
||||||
|
|
||||||
export default class DHActionConfig extends DHActionBaseConfig {
|
export default class DHActionConfig extends DHActionBaseConfig {
|
||||||
|
|
@ -27,9 +27,7 @@ export default class DHActionConfig extends DHActionBaseConfig {
|
||||||
|
|
||||||
DHActionBaseConfig.selectOutcome(this.action, key => {
|
DHActionBaseConfig.selectOutcome(this.action, key => {
|
||||||
if (!key) return;
|
if (!key) return;
|
||||||
|
data.altOutcomes[key] = new AltOutcome();
|
||||||
data.damage.altOutcomes[key] = new AltDamageOutcome();
|
|
||||||
this.outcomeTabs = DHActionBaseConfig.getOutcomeTabs(data);
|
|
||||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
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) {
|
static onRemoveOutcome(_event, button) {
|
||||||
const { outcome } = button.dataset;
|
const { outcome } = button.dataset;
|
||||||
const data = this.action.toObject();
|
const data = this.action.toObject();
|
||||||
|
data.altOutcomes[outcome] = null;
|
||||||
data.damage.altOutcomes[outcome] = null;
|
|
||||||
this.outcomeTabs = DHActionBaseConfig.getOutcomeTabs(data);
|
|
||||||
|
|
||||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
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';
|
import DHBaseAction from './baseAction.mjs';
|
||||||
|
|
||||||
|
const fields = foundry.data.fields;
|
||||||
|
|
||||||
export default class DHDamageAction extends DHBaseAction {
|
export default class DHDamageAction extends DHBaseAction {
|
||||||
static extraSchemas = [...super.extraSchemas, 'damage', 'target', 'effects'];
|
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
|
* Return a display ready damage formula string
|
||||||
* @returns Formula string
|
* @returns Formula string
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import IterableTypedObjectField from '../iterableTypedObjectField.mjs';
|
||||||
|
|
||||||
const fields = foundry.data.fields;
|
const fields = foundry.data.fields;
|
||||||
|
|
||||||
const getDamageBaseFields = () => ({
|
export const getDamageBaseFields = () => ({
|
||||||
parts: new IterableTypedObjectField(DHDamageData),
|
parts: new IterableTypedObjectField(DHDamageData),
|
||||||
includeBase: new fields.BooleanField({
|
includeBase: new fields.BooleanField({
|
||||||
initial: false,
|
initial: false,
|
||||||
|
|
@ -23,12 +23,6 @@ export default class DamageField extends fields.SchemaField {
|
||||||
constructor(options, context = {}) {
|
constructor(options, context = {}) {
|
||||||
const damageFields = {
|
const damageFields = {
|
||||||
...getDamageBaseFields(),
|
...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({
|
groupAttack: new fields.StringField({
|
||||||
choices: CONFIG.DH.GENERAL.groupAttackRange,
|
choices: CONFIG.DH.GENERAL.groupAttackRange,
|
||||||
blank: true,
|
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">
|
<div class="nest-inputs">
|
||||||
<fieldset class="one-column">
|
<fieldset class="one-column">
|
||||||
<legend>{{localize "DAGGERHEART.GENERAL.withThing" thing=(localize "DAGGERHEART.GENERAL.hope")}}</legend>
|
<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>
|
||||||
<fieldset class="one-column">
|
<fieldset class="one-column">
|
||||||
<legend>{{localize "DAGGERHEART.GENERAL.withThing" thing=(localize "DAGGERHEART.GENERAL.fear")}}</legend>
|
<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>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{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}}
|
||||||
|
|
||||||
{{#if (and (eq dmg.applyTo 'hitPoints') (ne @root.source.type 'healing'))}}
|
{{#if (and (eq dmg.applyTo 'hitPoints') (ne @root.source.type 'healing'))}}
|
||||||
|
|
@ -72,21 +72,21 @@
|
||||||
|
|
||||||
{{#*inline "formula"}}
|
{{#*inline "formula"}}
|
||||||
{{#unless dmg.base}}
|
{{#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}}
|
{{/unless}}
|
||||||
{{#if source.custom.enabled}}
|
{{#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}}
|
{{else}}
|
||||||
<div class="nest-inputs">
|
<div class="nest-inputs">
|
||||||
{{#unless @root.isNPC}}
|
{{#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}}
|
{{/unless}}
|
||||||
{{#if (eq source.multiplier 'flat')}}{{formField fields.flatMultiplier value=source.flatMultiplier name=(concat path outcomePath ".parts." key "." target ".flatMultiplier") localize=true }}{{/if}}
|
{{#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 outcomePath ".parts." key "." target ".dice") localize=true}}
|
{{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 outcomePath ".parts." key "." target ".bonus") localize=true}}
|
{{formField fields.bonus value=source.bonus name=(concat path basePath ".parts." key "." target ".bonus") localize=true}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if @root.isNPC}}
|
{{#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}}
|
{{/if}}
|
||||||
{{/inline}}
|
{{/inline}}
|
||||||
|
|
@ -21,14 +21,15 @@
|
||||||
data-group="outcomes"
|
data-group="outcomes"
|
||||||
data-tab="{{tab.id}}"
|
data-tab="{{tab.id}}"
|
||||||
>
|
>
|
||||||
{{#if ../fields.damage}}
|
{{#if tab.fields.damage}}
|
||||||
{{#if (eq tab.id 'default')}}
|
{{> 'systems/daggerheart/templates/actionTypes/damage.hbs'
|
||||||
{{> '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" }}
|
outcome=tab.id
|
||||||
{{else}}
|
fields=tab.fields.damage.fields.parts.element.fields
|
||||||
{{#with (lookup ../fields.damage.fields.altOutcomes.fields tab.id) as |field|}}
|
source=tab.source.damage
|
||||||
{{> '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) }}
|
baseFields=tab.fields.damage.fields
|
||||||
{{/with }}
|
isDefaultDamage="true"
|
||||||
{{/if}}
|
basePath=(tab.getBasePath "damage")
|
||||||
|
}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue