Added automation setting

This commit is contained in:
WBHarry 2026-01-03 03:36:23 +01:00
parent 958dd8b1d0
commit ce2e5871bc
5 changed files with 33 additions and 3 deletions

View file

@ -395,6 +395,9 @@ class RegisteredTriggers extends Map {
async runTrigger(trigger, currentActor, ...args) {
const updates = [];
const triggerSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).triggers;
if (!triggerSettings.enabled) return updates;
const dualityTrigger = this.get(trigger);
if (dualityTrigger) {
for (let { actor, commands } of dualityTrigger.values()) {
@ -402,8 +405,8 @@ class RegisteredTriggers extends Map {
for (let command of commands) {
try {
const commandUpdates = await command(...args);
if (commandUpdates?.length) updates.push(...commandUpdates);
const result = await command(...args);
if (result?.updates?.length) updates.push(...result.updates);
} catch (_) {
const triggerName = game.i18n.localize(CONFIG.DH.TRIGGER.triggers[trigger].label);
ui.notifications.error(

View file

@ -2448,6 +2448,12 @@
"hint": "Automatically apply effects. Targets must be selected before the action is made and Reaction Roll Automation must be different than Never. Bypass users permissions."
}
},
"triggers": {
"enabled": {
"label": "Enabled",
"hint": "Advanced automation such as triggering a popup for a wizard's Strange Patterns"
}
},
"summaryMessages": {
"label": "Summary Messages"
}
@ -2457,6 +2463,9 @@
},
"roll": {
"title": "Actions"
},
"trigger": {
"title": "Triggers"
}
},
"Homebrew": {

View file

@ -173,6 +173,13 @@ export default class DhAutomation extends foundry.abstract.DataModel {
label: 'DAGGERHEART.GENERAL.player.plurial'
})
})
}),
triggers: new fields.SchemaField({
enabled: new fields.BooleanField({
nullable: false,
initial: true,
label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.triggers.enabled.label'
})
})
};
}

View file

@ -84,7 +84,7 @@
"triggers": [
{
"trigger": "dualityRoll",
"command": "/* Check if there's a Strange Pattern match */\nconst dice = [roll.dFear.total, roll.dHope.total];\nconst resource = this.parent.resource?.diceStates ? Object.values(this.parent.resource.diceStates).map(x => x.value)[0] : null;\nconst diceMatch = dice.includes(resource);\n\nif (!diceMatch) return;\n\n/* Create a dialog to choose Hope or Stress - or to cancel*/\nconst choice = await foundry.applications.api.DialogV2.wait({\n classes: ['dh-style', 'two-big-buttons'],\n window: { title: this.item.name },\n content: game.i18n.localize('DAGGERHEART.CONFIG.Triggers.triggerTexts.strangePatternsContent'),\n buttons: [\n {\n action: 'hope',\n label: game.i18n.localize('DAGGERHEART.GENERAL.hope'),\n icon: 'fa-solid fa-hands-holding'\n },\n {\n action: 'stress',\n label: game.i18n.localize('DAGGERHEART.GENERAL.stress'),\n icon: 'fa-solid fa-bolt-lightning'\n }\n ]\n});\n \nif (!choice) return;\n\n/* Return resource update according to choice */\nconst isHope = choice === 'hope';\nreturn [{ key: choice, value: isHope ? 1 : -1, total: isHope ? -1 : 1, enabled: true }];"
"command": "/* Check if there's a Strange Pattern match */\nconst dice = [roll.dFear.total, roll.dHope.total];\nconst resource = this.parent.resource?.diceStates ? Object.values(this.parent.resource.diceStates).map(x => x.value)[0] : null;\nconst diceMatch = dice.includes(resource);\n\nif (!diceMatch) return;\n\n/* Create a dialog to choose Hope or Stress - or to cancel*/\nconst choice = await foundry.applications.api.DialogV2.wait({\n classes: ['dh-style', 'two-big-buttons'],\n window: { title: this.item.name },\n content: game.i18n.localize('DAGGERHEART.CONFIG.Triggers.triggerTexts.strangePatternsContent'),\n buttons: [\n {\n action: 'hope',\n label: game.i18n.localize('DAGGERHEART.GENERAL.hope'),\n icon: 'fa-solid fa-hands-holding'\n },\n {\n action: 'stress',\n label: game.i18n.localize('DAGGERHEART.GENERAL.stress'),\n icon: 'fa-solid fa-bolt-lightning'\n }\n ]\n});\n \nif (!choice) return;\n\n/* Return resource update according to choice */\nconst isHope = choice === 'hope';\nconst updates = [{ key: choice, value: isHope ? 1 : -1, total: isHope ? -1 : 1, enabled: true }];\nreturn { updates };"
}
]
}

View file

@ -19,4 +19,15 @@
</div>
{{/each}}
</fieldset>
<fieldset>
<legend>
{{localize "DAGGERHEART.SETTINGS.Automation.trigger.title"}}
</legend>
<div class="form-group">
{{formGroup settingFields.schema.fields.triggers.fields.enabled value=settingFields.triggers.enabled localize=true}}
<p class="hint">{{localize "DAGGERHEART.SETTINGS.Automation.FIELDS.triggers.enabled.hint"}}</p>
</div>
</fieldset>
</section>