diff --git a/module/applications/sheets-configs/action-base-config.mjs b/module/applications/sheets-configs/action-base-config.mjs index b98e2079..3a14dbef 100644 --- a/module/applications/sheets-configs/action-base-config.mjs +++ b/module/applications/sheets-configs/action-base-config.mjs @@ -1,4 +1,4 @@ -import { getNextUnusedDamageType } from '../../helpers/utils.mjs'; +import { getUnusedDamageTypes } from '../../helpers/utils.mjs'; import DaggerheartSheet from '../sheets/daggerheart-sheet.mjs'; const { ApplicationV2 } = foundry.applications.api; @@ -269,12 +269,53 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) static addDamage(_event) { if (!this.action.damage.parts) return; - 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) }); + + 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); } static removeDamage(_event, button) { diff --git a/module/data/fields/action/damageField.mjs b/module/data/fields/action/damageField.mjs index d904c3a0..2c4ef617 100644 --- a/module/data/fields/action/damageField.mjs +++ b/module/data/fields/action/damageField.mjs @@ -287,6 +287,7 @@ 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 3fd57a58..72575a75 100644 --- a/module/helpers/utils.mjs +++ b/module/helpers/utils.mjs @@ -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); } -export function getNextUnusedDamageType(parts) { +export function getUnusedDamageTypes(parts) { const usedKeys = Object.keys(parts); - for (const key of Object.keys(CONFIG.DH.GENERAL.healingTypes)) { - if (!usedKeys.includes(key)) return key; - } + 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) + }); - return null; + return acc; + }, []); } diff --git a/styles/less/global/elements.less b/styles/less/global/elements.less index f5e92e2c..53e9ba20 100755 --- a/styles/less/global/elements.less +++ b/styles/less/global/elements.less @@ -333,6 +333,15 @@ 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 ec556c17..e63f602d 100644 --- a/templates/actionTypes/damage.hbs +++ b/templates/actionTypes/damage.hbs @@ -1,6 +1,6 @@