This commit is contained in:
WBHarry 2026-01-02 22:12:55 +01:00
parent 36eac51041
commit 8881f14153
8 changed files with 84 additions and 13 deletions

View file

@ -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
})
);
}
}
}
}

View file

@ -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": {

View file

@ -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) });

View file

@ -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'
}
};

View file

@ -548,6 +548,7 @@
code-mirror {
width: 100%;
height: 500px;
}
}

View file

@ -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;
}
}
}
}

View file

@ -1,3 +1,5 @@
@import './actions/actions.less';
@import './actors/actor-sheet-shared.less';
@import './actors/adversary/actions.less';

View file

@ -5,13 +5,20 @@
>
<button data-action="addTrigger">{{localize "Add Trigger"}} <i class="fa-solid fa-plus icon-button"></i></button>
{{#each @root.source.triggers as |trigger index|}}
{{#each @root.triggers as |trigger index|}}
<fieldset class="one-column">
<legend><a data-action="removeTrigger" data-index="{{index}}"><i class="fa-solid fa-trash"></i></a></legend>
<select id="triggerOptionSelect">
{{selectOptions @root.triggerOptions seleced=trigger.trigger localize=true}}
</select>
<div class="trigger-data">
<select name="{{concat "triggers." index ".trigger"}}">
{{selectOptions @root.triggerOptions seleced=trigger.trigger localize=true}}
</select>
<div class="hint-section">
<strong>{{localize "Context: "}}</strong>
<span class="hint">{{localize trigger.hint}}</span>
</div>
</div>
{{formInput @root.fields.triggers.element.fields.command value=trigger.command elementType="code-mirror" name=(concat "triggers." index ".command") aria=(object label=(localize "Test"))}}
</fieldset>
{{/each}}