mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 06:26:13 +01:00
Reworked ActionConfig damage ui
This commit is contained in:
parent
9bda624112
commit
fc7b9a4828
5 changed files with 76 additions and 24 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { getNextUnusedDamageType } from '../../helpers/utils.mjs';
|
import { getUnusedDamageTypes } from '../../helpers/utils.mjs';
|
||||||
import DaggerheartSheet from '../sheets/daggerheart-sheet.mjs';
|
import DaggerheartSheet from '../sheets/daggerheart-sheet.mjs';
|
||||||
|
|
||||||
const { ApplicationV2 } = foundry.applications.api;
|
const { ApplicationV2 } = foundry.applications.api;
|
||||||
|
|
@ -269,12 +269,53 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
|
|
||||||
static addDamage(_event) {
|
static addDamage(_event) {
|
||||||
if (!this.action.damage.parts) return;
|
if (!this.action.damage.parts) return;
|
||||||
|
|
||||||
|
const choices = getUnusedDamageTypes(this.action.damage.parts);
|
||||||
|
const content = new foundry.data.fields.StringField({
|
||||||
|
label: game.i18n.localize('Damage Type'),
|
||||||
|
choices,
|
||||||
|
required: true
|
||||||
|
}).toFormGroup(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
name: 'type',
|
||||||
|
localize: true,
|
||||||
|
nameAttr: 'value',
|
||||||
|
labelAttr: 'label'
|
||||||
|
}
|
||||||
|
).outerHTML;
|
||||||
|
|
||||||
|
const callback = (_, button) => {
|
||||||
const data = this.action.toObject();
|
const data = this.action.toObject();
|
||||||
const type = getNextUnusedDamageType(this.action.damage.parts);
|
const type = choices[button.form.elements.type.value].value;
|
||||||
const part = { applyTo: type };
|
const part = { applyTo: type };
|
||||||
if (this.action.actor?.isNPC) part.value = { multiplier: 'flat' };
|
if (this.action.actor?.isNPC) part.value = { multiplier: 'flat' };
|
||||||
data.damage.parts[type] = part;
|
data.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) });
|
||||||
|
};
|
||||||
|
|
||||||
|
const typeDialog = new foundry.applications.api.DialogV2({
|
||||||
|
buttons: [
|
||||||
|
foundry.utils.mergeObject(
|
||||||
|
{
|
||||||
|
action: 'ok',
|
||||||
|
label: 'Confirm',
|
||||||
|
icon: 'fas fa-check',
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
{ callback: callback }
|
||||||
|
)
|
||||||
|
],
|
||||||
|
content: content,
|
||||||
|
rejectClose: false,
|
||||||
|
modal: false,
|
||||||
|
window: {
|
||||||
|
title: game.i18n.localize('Add Damage')
|
||||||
|
},
|
||||||
|
position: { width: 300 }
|
||||||
|
});
|
||||||
|
|
||||||
|
typeDialog.render(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static removeDamage(_event, button) {
|
static removeDamage(_event, button) {
|
||||||
|
|
|
||||||
|
|
@ -287,6 +287,7 @@ export class DHDamageData extends DHResourceData {
|
||||||
return {
|
return {
|
||||||
...super.defineSchema(),
|
...super.defineSchema(),
|
||||||
base: new fields.BooleanField({ initial: false, readonly: true, label: 'Base' }),
|
base: new fields.BooleanField({ initial: false, readonly: true, label: 'Base' }),
|
||||||
|
// direct: new fields.BooleanField({ initial: false, label: 'DAGGERHEART.CONFIG.DamageType.direct.name' }),
|
||||||
type: new fields.SetField(
|
type: new fields.SetField(
|
||||||
new fields.StringField({
|
new fields.StringField({
|
||||||
choices: CONFIG.DH.GENERAL.damageTypes,
|
choices: CONFIG.DH.GENERAL.damageTypes,
|
||||||
|
|
|
||||||
|
|
@ -558,11 +558,15 @@ export function calculateExpectedValue(formulaOrTerms) {
|
||||||
return terms.reduce((r, t) => r + (t.bonus ?? 0) + (t.diceQuantity ? (t.diceQuantity * (t.faces + 1)) / 2 : 0), 0);
|
return terms.reduce((r, t) => r + (t.bonus ?? 0) + (t.diceQuantity ? (t.diceQuantity * (t.faces + 1)) / 2 : 0), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNextUnusedDamageType(parts) {
|
export function getUnusedDamageTypes(parts) {
|
||||||
const usedKeys = Object.keys(parts);
|
const usedKeys = Object.keys(parts);
|
||||||
for (const key of Object.keys(CONFIG.DH.GENERAL.healingTypes)) {
|
return Object.keys(CONFIG.DH.GENERAL.healingTypes).reduce((acc, key) => {
|
||||||
if (!usedKeys.includes(key)) return key;
|
if (!usedKeys.includes(key))
|
||||||
}
|
acc.push({
|
||||||
|
value: key,
|
||||||
|
label: game.i18n.localize(CONFIG.DH.GENERAL.healingTypes[key].label)
|
||||||
|
});
|
||||||
|
|
||||||
return null;
|
return acc;
|
||||||
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -333,6 +333,15 @@
|
||||||
legend {
|
legend {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: light-dark(@dark-blue, @golden);
|
color: light-dark(@dark-blue, @golden);
|
||||||
|
|
||||||
|
&.with-icon {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
i {
|
||||||
|
padding: 0 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type='text'],
|
input[type='text'],
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
<fieldset class="one-column">
|
<fieldset class="one-column">
|
||||||
<legend>
|
<legend class="with-icon">
|
||||||
{{#if (eq @root.source.type 'healing')}}
|
{{#if (eq @root.source.type 'healing')}}
|
||||||
{{localize "DAGGERHEART.GENERAL.healing"}}
|
{{localize "DAGGERHEART.GENERAL.healing"}}
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
@ -19,6 +19,8 @@
|
||||||
{{#each source.parts as |dmg key|}}
|
{{#each source.parts as |dmg key|}}
|
||||||
<div class="nest-inputs">
|
<div class="nest-inputs">
|
||||||
<fieldset{{#if dmg.base}} disabled{{/if}} class="one-column{{#if ../path}} no-style{{/if}}">
|
<fieldset{{#if dmg.base}} disabled{{/if}} class="one-column{{#if ../path}} no-style{{/if}}">
|
||||||
|
<legend class="with-icon">{{localize (concat "DAGGERHEART.CONFIG.HealingType." key ".name")}}{{#unless (or dmg.base ../path)}}<a data-action="removeDamage" data-key="{{key}}"><i class="fas fa-trash"></i></a>{{/unless}}</legend>
|
||||||
|
|
||||||
{{#if (and (not @root.isNPC) @root.hasRoll (not dmg.base))}}
|
{{#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." key ".resultBased") localize=true classes="checkbox"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
@ -34,17 +36,13 @@
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
<fieldset{{#if dmg.base}} disabled{{/if}} class="one-column">
|
|
||||||
<legend>{{localize "DAGGERHEART.GENERAL.formula"}}</legend>
|
|
||||||
{{> 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=key path=../path}}
|
||||||
</fieldset>
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<div class="nest-inputs">
|
|
||||||
{{formField ../fields.applyTo value=dmg.applyTo name=(concat ../path "damage.parts." key ".applyTo") localize=true}}
|
|
||||||
{{#if (and (eq dmg.applyTo 'hitPoints') (ne @root.source.type 'healing'))}}
|
{{#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." key ".type") localize=true}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
|
||||||
{{#if ../horde}}
|
{{#if ../horde}}
|
||||||
<fieldset class="one-column">
|
<fieldset class="one-column">
|
||||||
<legend>{{localize "DAGGERHEART.ACTORS.Adversary.hordeDamage"}}</legend>
|
<legend>{{localize "DAGGERHEART.ACTORS.Adversary.hordeDamage"}}</legend>
|
||||||
|
|
@ -58,7 +56,6 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<input type="hidden" name="damage.parts.{{key}}.base" value="{{dmg.base}}">
|
<input type="hidden" name="damage.parts.{{key}}.base" value="{{dmg.base}}">
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{{#unless (or dmg.base ../path)}}<div class="fas fa-trash" data-action="removeDamage" data-key="{{key}}"></div>{{/unless}}
|
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue