From 8881f141535abdf2919effa6d3e243fad85c0fc2 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Fri, 2 Jan 2026 22:12:55 +0100 Subject: [PATCH] . --- daggerheart.mjs | 14 +++++++++-- lang/en.json | 15 +++++++++--- .../sheets-configs/action-base-config.mjs | 20 ++++++++++++++-- module/config/triggerConfig.mjs | 6 +++-- styles/less/global/elements.less | 1 + styles/less/sheets/actions/actions.less | 24 +++++++++++++++++++ styles/less/sheets/index.less | 2 ++ .../action-settings/trigger.hbs | 15 ++++++++---- 8 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 styles/less/sheets/actions/actions.less diff --git a/daggerheart.mjs b/daggerheart.mjs index 09d4302c..fa1fd026 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -401,8 +401,18 @@ class RegisteredTriggers extends Map { if (currentActor?.uuid !== actor) continue; for (let command of commands) { - const commandUpdates = await command(...args); - if (commandUpdates?.length) updates.push(...commandUpdates); + try { + const commandUpdates = await command(...args); + if (commandUpdates?.length) updates.push(...commandUpdates); + } catch (_) { + const triggerName = game.i18n.localize(CONFIG.DH.TRIGGER.triggers[trigger].label); + ui.notifications.error( + game.i18n.format('DAGGERHEART.CONFIG.Triggers.triggerError', { + trigger: triggerName, + actor: currentActor?.name + }) + ); + } } } } diff --git a/lang/en.json b/lang/en.json index 532ff3e3..1d431309 100755 --- a/lang/en.json +++ b/lang/en.json @@ -90,7 +90,9 @@ "customFormula": "Custom Formula", "formula": "Formula" }, - "displayInChat": "Display in chat" + "displayInChat": "Display in chat", + "deleteTriggerTitle": "Delete Trigger", + "deleteTriggerContent": "Are you sure you want to delete the {trigger} trigger?" }, "RollField": { "diceRolling": { @@ -1218,8 +1220,15 @@ } }, "Triggers": { - "dualityRoll": "Duality Roll", - "fearRoll": "Fear Roll" + "dualityRoll": { + "label": "Duality Roll", + "hint": "this: Action, roll: DhRoll, actor: DhActor" + }, + "fearRoll": { + "label": "Fear Roll", + "hint": "this: Action\nroll: DhRoll\nactor: DhActor" + }, + "triggerError": "{trigger} trigger failed for {actor}. It's probably configured wrong." }, "WeaponFeature": { "barrier": { diff --git a/module/applications/sheets-configs/action-base-config.mjs b/module/applications/sheets-configs/action-base-config.mjs index b4e9b971..27579027 100644 --- a/module/applications/sheets-configs/action-base-config.mjs +++ b/module/applications/sheets-configs/action-base-config.mjs @@ -15,7 +15,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) static DEFAULT_OPTIONS = { tag: 'form', - classes: ['daggerheart', 'dh-style', 'dialog', 'max-800'], + classes: ['daggerheart', 'dh-style', 'action-config', 'dialog', 'max-800'], window: { icon: 'fa-solid fa-wrench', resizable: false @@ -126,6 +126,10 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) context.baseAttackBonus = this.action.actor?.system.attack?.roll.bonus; context.hasRoll = this.action.hasRoll; context.triggerOptions = CONFIG.DH.TRIGGER.triggers; + context.triggers = context.source.triggers.map(trigger => ({ + ...trigger, + hint: CONFIG.DH.TRIGGER.triggers[trigger.trigger].hint + })); const settingsTiers = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers).tiers; context.tierOptions = [ @@ -245,7 +249,19 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); } - static removeTrigger(_event, button) { + static async removeTrigger(_event, button) { + const trigger = CONFIG.DH.TRIGGER.triggers[this.action.triggers[button.dataset.index].trigger]; + const confirmed = await foundry.applications.api.DialogV2.confirm({ + window: { + title: game.i18n.localize('DAGGERHEART.ACTIONS.Config.deleteTriggerTitle') + }, + content: game.i18n.format('DAGGERHEART.ACTIONS.Config.deleteTriggerContent', { + trigger: game.i18n.localize(trigger.label) + }) + }); + + if (!confirmed) return; + const data = this.action.toObject(); data.triggers = data.triggers.filter((_, index) => index !== Number.parseInt(button.dataset.index)); this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); diff --git a/module/config/triggerConfig.mjs b/module/config/triggerConfig.mjs index 8ef7e989..3a1f6b1a 100644 --- a/module/config/triggerConfig.mjs +++ b/module/config/triggerConfig.mjs @@ -1,10 +1,12 @@ export const triggers = { dualityRoll: { id: 'dualityRoll', - label: 'DAGGERHEART.CONFIG.Triggers.dualityRoll' + label: 'DAGGERHEART.CONFIG.Triggers.dualityRoll.label', + hint: 'DAGGERHEART.CONFIG.Triggers.dualityRoll.hint' }, fearRoll: { id: 'fearRoll', - label: 'DAGGERHEART.CONFIG.Triggers.fearRoll' + label: 'DAGGERHEART.CONFIG.Triggers.fearRoll.label', + hint: 'DAGGERHEART.CONFIG.Triggers.fearRoll.hint' } }; diff --git a/styles/less/global/elements.less b/styles/less/global/elements.less index e5fd3646..766fd14d 100755 --- a/styles/less/global/elements.less +++ b/styles/less/global/elements.less @@ -548,6 +548,7 @@ code-mirror { width: 100%; + height: 500px; } } diff --git a/styles/less/sheets/actions/actions.less b/styles/less/sheets/actions/actions.less new file mode 100644 index 00000000..ff7f1cf3 --- /dev/null +++ b/styles/less/sheets/actions/actions.less @@ -0,0 +1,24 @@ +.application.daggerheart.dh-style.action-config { + .trigger-data { + width: 100%; + display: flex; + align-items: center; + gap: 8px; + + select { + flex: 1; + } + + .hint-section { + flex: 3; + display: flex; + align-items: center; + gap: 4px; + + .hint { + flex: 1; + flex-wrap: wrap; + } + } + } +} diff --git a/styles/less/sheets/index.less b/styles/less/sheets/index.less index 1de1b055..44a6aa4d 100644 --- a/styles/less/sheets/index.less +++ b/styles/less/sheets/index.less @@ -1,3 +1,5 @@ +@import './actions/actions.less'; + @import './actors/actor-sheet-shared.less'; @import './actors/adversary/actions.less'; diff --git a/templates/sheets-settings/action-settings/trigger.hbs b/templates/sheets-settings/action-settings/trigger.hbs index 61d856cf..4779bcd3 100644 --- a/templates/sheets-settings/action-settings/trigger.hbs +++ b/templates/sheets-settings/action-settings/trigger.hbs @@ -5,13 +5,20 @@ > - {{#each @root.source.triggers as |trigger index|}} + {{#each @root.triggers as |trigger index|}}
- +
+ +
+ {{localize "Context: "}} + {{localize trigger.hint}} +
+
+ {{formInput @root.fields.triggers.element.fields.command value=trigger.command elementType="code-mirror" name=(concat "triggers." index ".command") aria=(object label=(localize "Test"))}}
{{/each}}