diff --git a/module/applications/sheets-configs/action-base-config.mjs b/module/applications/sheets-configs/action-base-config.mjs index c7e8e758..b3c79ff8 100644 --- a/module/applications/sheets-configs/action-base-config.mjs +++ b/module/applications/sheets-configs/action-base-config.mjs @@ -1,4 +1,4 @@ -import { getUnusedDamageTypes } from '../../helpers/utils.mjs'; +import { getNextUnusedDamageType } from '../../helpers/utils.mjs'; import DaggerheartSheet from '../sheets/daggerheart-sheet.mjs'; const { ApplicationV2 } = foundry.applications.api; @@ -104,7 +104,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) } }; - static CLEAN_ARRAYS = ['cost', 'effects', 'summon']; + static CLEAN_ARRAYS = ['damage.parts', 'cost', 'effects', 'summon']; _getTabs(tabs) { for (const v of Object.values(tabs)) { @@ -156,7 +156,6 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) revealed: this.openTrigger === index }; }); - context.allDamageTypesUsed = !getUnusedDamageTypes(this.action.damage.parts).length; const settingsTiers = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers).tiers; context.tierOptions = [ @@ -270,61 +269,19 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) static addDamage(_event) { 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 type = choices[button.form.elements.type.value].value; - const part = { applyTo: type }; - if (this.action.actor?.isNPC) part.value = { multiplier: 'flat' }; - data.damage.parts[type] = part; - 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); + const data = this.action.toObject(); + const type = getNextUnusedDamageType(this.action.damage.parts); + const part = { applyTo: type }; + if (this.action.actor?.isNPC) part.value = { multiplier: 'flat' }; + data.damage.parts[type] = part; + this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); } static removeDamage(_event, button) { if (!this.action.damage.parts) return; - const data = this.action.toObject(); - const key = button.dataset.key; - delete data.damage.parts[key]; - data.damage.parts[`-=${key}`] = null; + const data = this.action.toObject(), + index = button.dataset.index; + data.damage.parts.splice(index, 1); 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 2c4ef617..d904c3a0 100644 --- a/module/data/fields/action/damageField.mjs +++ b/module/data/fields/action/damageField.mjs @@ -287,7 +287,6 @@ export class DHDamageData extends DHResourceData { return { ...super.defineSchema(), 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( new fields.StringField({ choices: CONFIG.DH.GENERAL.damageTypes, diff --git a/module/helpers/utils.mjs b/module/helpers/utils.mjs index 72575a75..3fd57a58 100644 --- a/module/helpers/utils.mjs +++ b/module/helpers/utils.mjs @@ -558,15 +558,11 @@ export function calculateExpectedValue(formulaOrTerms) { return terms.reduce((r, t) => r + (t.bonus ?? 0) + (t.diceQuantity ? (t.diceQuantity * (t.faces + 1)) / 2 : 0), 0); } -export function getUnusedDamageTypes(parts) { +export function getNextUnusedDamageType(parts) { const usedKeys = Object.keys(parts); - return Object.keys(CONFIG.DH.GENERAL.healingTypes).reduce((acc, key) => { - if (!usedKeys.includes(key)) - acc.push({ - value: key, - label: game.i18n.localize(CONFIG.DH.GENERAL.healingTypes[key].label) - }); + for (const key of Object.keys(CONFIG.DH.GENERAL.healingTypes)) { + if (!usedKeys.includes(key)) return key; + } - return acc; - }, []); + return null; } diff --git a/styles/less/global/elements.less b/styles/less/global/elements.less index 53e9ba20..f5e92e2c 100755 --- a/styles/less/global/elements.less +++ b/styles/less/global/elements.less @@ -333,15 +333,6 @@ legend { font-weight: bold; color: light-dark(@dark-blue, @golden); - - &.with-icon { - display: flex; - align-items: center; - - i { - padding: 0 4px; - } - } } input[type='text'], diff --git a/templates/actionTypes/damage.hbs b/templates/actionTypes/damage.hbs index 6f159a2d..96bb361c 100644 --- a/templates/actionTypes/damage.hbs +++ b/templates/actionTypes/damage.hbs @@ -1,12 +1,12 @@
{{#*inline "formula"}} {{#unless dmg.base}} - {{formField fields.custom.fields.enabled value=source.custom.enabled name=(concat path "damage.parts." key "." target ".custom.enabled") classes="checkbox" localize=true}} + {{formField fields.custom.fields.enabled value=source.custom.enabled name=(concat path "damage.parts." realIndex "." target ".custom.enabled") classes="checkbox" localize=true}} {{/unless}} {{#if source.custom.enabled}} - {{formField fields.custom.fields.formula value=source.custom.formula name=(concat path "damage.parts." key "." target ".custom.formula") localize=true}} + {{formField fields.custom.fields.formula value=source.custom.formula name=(concat path "damage.parts." realIndex "." target ".custom.formula") localize=true}} {{else}}