From ce2e5871bc0d5b494380d84e6f5f92f8dc059d9c Mon Sep 17 00:00:00 2001 From: WBHarry Date: Sat, 3 Jan 2026 03:36:23 +0100 Subject: [PATCH] Added automation setting --- daggerheart.mjs | 7 +++++-- lang/en.json | 9 +++++++++ module/data/settings/Automation.mjs | 7 +++++++ .../feature_Strange_Patterns_6YsfFjmCGuFYVhT4.json | 2 +- templates/settings/automation-settings/roll.hbs | 11 +++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/daggerheart.mjs b/daggerheart.mjs index fa1fd026..5c333e27 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -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( diff --git a/lang/en.json b/lang/en.json index c35b3d88..1a8797e2 100755 --- a/lang/en.json +++ b/lang/en.json @@ -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": { diff --git a/module/data/settings/Automation.mjs b/module/data/settings/Automation.mjs index 2aec990f..3376b153 100644 --- a/module/data/settings/Automation.mjs +++ b/module/data/settings/Automation.mjs @@ -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' + }) }) }; } diff --git a/src/packs/classes/feature_Strange_Patterns_6YsfFjmCGuFYVhT4.json b/src/packs/classes/feature_Strange_Patterns_6YsfFjmCGuFYVhT4.json index bdb614e4..359ad45d 100644 --- a/src/packs/classes/feature_Strange_Patterns_6YsfFjmCGuFYVhT4.json +++ b/src/packs/classes/feature_Strange_Patterns_6YsfFjmCGuFYVhT4.json @@ -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 };" } ] } diff --git a/templates/settings/automation-settings/roll.hbs b/templates/settings/automation-settings/roll.hbs index 5769bf61..dc65f8ae 100644 --- a/templates/settings/automation-settings/roll.hbs +++ b/templates/settings/automation-settings/roll.hbs @@ -19,4 +19,15 @@ {{/each}} + +
+ + {{localize "DAGGERHEART.SETTINGS.Automation.trigger.title"}} + + +
+ {{formGroup settingFields.schema.fields.triggers.fields.enabled value=settingFields.triggers.enabled localize=true}} +

{{localize "DAGGERHEART.SETTINGS.Automation.FIELDS.triggers.enabled.hint"}}

+
+
\ No newline at end of file