diff --git a/lang/en.json b/lang/en.json index 1d431309..c35b3d88 100755 --- a/lang/en.json +++ b/lang/en.json @@ -1226,7 +1226,10 @@ }, "fearRoll": { "label": "Fear Roll", - "hint": "this: Action\nroll: DhRoll\nactor: DhActor" + "hint": "this: Action, roll: DhRoll, actor: DhActor" + }, + "triggerTexts": { + "strangePatternsContent": "Increase Hope or clear stress?" }, "triggerError": "{trigger} trigger failed for {actor}. It's probably configured wrong." }, diff --git a/module/applications/sheets-configs/action-base-config.mjs b/module/applications/sheets-configs/action-base-config.mjs index 27579027..67398c6b 100644 --- a/module/applications/sheets-configs/action-base-config.mjs +++ b/module/applications/sheets-configs/action-base-config.mjs @@ -7,6 +7,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) this.action = action; this.openSection = null; + this.openTrigger = this.action.triggers.length > 0 ? 0 : null; } get title() { @@ -31,7 +32,8 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) addDamage: this.addDamage, removeDamage: this.removeDamage, addTrigger: this.addTrigger, - removeTrigger: this.removeTrigger + removeTrigger: this.removeTrigger, + expandTrigger: this.expandTrigger }, form: { handler: this.updateForm, @@ -126,9 +128,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 => ({ + context.triggers = context.source.triggers.map((trigger, index) => ({ ...trigger, - hint: CONFIG.DH.TRIGGER.triggers[trigger.trigger].hint + hint: CONFIG.DH.TRIGGER.triggers[trigger.trigger].hint, + revealed: this.openTrigger === index })); const settingsTiers = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers).tiers; @@ -245,7 +248,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) static addTrigger() { const data = this.action.toObject(); - data.triggers.push({ hook: CONFIG.DH.TRIGGER.triggers.dualityRoll.id }); + data.triggers.push({ trigger: CONFIG.DH.TRIGGER.triggers.dualityRoll.id }); this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); } @@ -267,6 +270,33 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); } + static async expandTrigger(_event, button) { + const index = Number.parseInt(button.dataset.index); + const toggle = (element, codeMirror) => { + codeMirror.classList.toggle('revealed'); + const button = element.querySelector('a > i'); + button.classList.toggle('fa-angle-up'); + button.classList.toggle('fa-angle-down'); + }; + + const fieldset = button.closest('fieldset'); + const codeMirror = fieldset.querySelector('.code-mirror-wrapper'); + toggle(fieldset, codeMirror); + + if (this.openTrigger !== null && this.openTrigger !== index) { + const previouslyExpanded = fieldset + .closest(`section`) + .querySelector(`fieldset[data-index="${this.openTrigger}"]`); + const codeMirror = previouslyExpanded.querySelector('.code-mirror-wrapper'); + toggle(previouslyExpanded, codeMirror); + this.openTrigger = index; + } else if (this.openTrigger === index) { + this.openTrigger = null; + } else { + this.openTrigger = index; + } + } + /** Specific implementation in extending classes **/ static async addEffect(_event) {} static removeEffect(_event, _button) {} diff --git a/module/data/fields/triggerField.mjs b/module/data/fields/triggerField.mjs index a36786e9..9decf263 100644 --- a/module/data/fields/triggerField.mjs +++ b/module/data/fields/triggerField.mjs @@ -4,6 +4,7 @@ export default class TriggerField extends foundry.data.fields.SchemaField { { trigger: new foundry.data.fields.StringField({ nullable: false, + blank: false, initial: CONFIG.DH.TRIGGER.triggers.dualityRoll.id, choices: CONFIG.DH.TRIGGER.triggers }), diff --git a/src/packs/classes/feature_Strange_Patterns_6YsfFjmCGuFYVhT4.json b/src/packs/classes/feature_Strange_Patterns_6YsfFjmCGuFYVhT4.json index 5d5d77e1..bdb614e4 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: 'Strange Patterns' },\n content: 'Increase Hope or clear stress?',\n buttons: [\n {\n action: 'hope',\n label: 'Hope',\n icon: 'fa-solid fa-plus'\n },\n {\n action: 'stress',\n label: 'Stress',\n icon: 'fa-solid fa-book'\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';\nreturn [{ key: choice, value: isHope ? 1 : -1, total: isHope ? -1 : 1, enabled: true }];" } ] } diff --git a/styles/less/global/elements.less b/styles/less/global/elements.less index 766fd14d..e740d917 100755 --- a/styles/less/global/elements.less +++ b/styles/less/global/elements.less @@ -545,11 +545,6 @@ font-size: var(--font-size-12); padding-left: 3px; } - - code-mirror { - width: 100%; - height: 500px; - } } .application.setting.dh-style { diff --git a/styles/less/sheets/actions/actions.less b/styles/less/sheets/actions/actions.less index ff7f1cf3..9a4908e5 100644 --- a/styles/less/sheets/actions/actions.less +++ b/styles/less/sheets/actions/actions.less @@ -21,4 +21,15 @@ } } } + + .code-mirror-wrapper { + width: 100%; + height: 0; + min-height: 0; + transition: height 0.1s ease-in-out; + + &.revealed { + height: 300px; + } + } } diff --git a/templates/sheets-settings/action-settings/trigger.hbs b/templates/sheets-settings/action-settings/trigger.hbs index 4779bcd3..20561c2c 100644 --- a/templates/sheets-settings/action-settings/trigger.hbs +++ b/templates/sheets-settings/action-settings/trigger.hbs @@ -3,23 +3,24 @@ data-group="primary" data-tab="trigger" > - + {{#each @root.triggers as |trigger index|}} -