Set command codeblock to expandable

This commit is contained in:
WBHarry 2026-01-03 02:50:47 +01:00
parent 5c3a2cf060
commit 958dd8b1d0
7 changed files with 58 additions and 17 deletions

View file

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

View file

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