From 9a3b82ef6a660069dec5e68f36b9f4cdaeaba70a Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Fri, 24 Jan 2025 20:47:32 -0700 Subject: [PATCH] Update Weapon context menu to also work for the Armour/Shield --- module/Apps/ActorSheets/HeroSummaryCardV1.mjs | 48 +++++++++++-------- templates/Apps/HeroSummaryCardV1/content.hbs | 31 +++++++++--- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/module/Apps/ActorSheets/HeroSummaryCardV1.mjs b/module/Apps/ActorSheets/HeroSummaryCardV1.mjs index 7317cf6..4437e3c 100644 --- a/module/Apps/ActorSheets/HeroSummaryCardV1.mjs +++ b/module/Apps/ActorSheets/HeroSummaryCardV1.mjs @@ -46,27 +46,35 @@ export class HeroSummaryCardV1 extends GenericAppMixin(HandlebarsApplicationMixi }; static async _onRender() { - const itemMenuOptions = [ - { - name: `Edit`, - condition: () => this.isEditable, - callback: HeroSummaryCardV1._editItem, - }, - { - name: `Delete`, - condition: () => this.isEditable, - callback: async (el) => { - const itemEl = el.closest(`[data-item-id]`); - if (!itemEl) { return }; - const itemId = itemEl.dataset.itemId; - const item = await fromUuid(itemId); - await item.delete(); + new ContextMenu( + this.element, + `[data-ctx-menu="weapon"],[data-ctx-menu="armour"]`, + [ + { + name: `Edit`, + condition: (el) => { + const itemId = el.dataset.itemId; + return this.isEditable && itemId !== ``; + }, + callback: HeroSummaryCardV1._editItem, }, - }, - ]; - if (itemMenuOptions.length) { - new ContextMenu(this.element, `.weapon-ctx-menu`, itemMenuOptions, { jQuery: false, fixed: true }); - }; + { + name: `Delete`, + condition: (el) => { + const itemId = el.dataset.itemId; + return this.isEditable && itemId !== ``; + }, + callback: async (el) => { + const itemEl = el.closest(`[data-item-id]`); + if (!itemEl) { return }; + const itemId = itemEl.dataset.itemId; + const item = await fromUuid(itemId); + await item.delete(); + }, + }, + ], + { jQuery: false, fixed: true }, + ); }; async _preparePartContext(partId, ctx, opts) { diff --git a/templates/Apps/HeroSummaryCardV1/content.hbs b/templates/Apps/HeroSummaryCardV1/content.hbs index a08e05b..be83299 100644 --- a/templates/Apps/HeroSummaryCardV1/content.hbs +++ b/templates/Apps/HeroSummaryCardV1/content.hbs @@ -55,23 +55,41 @@ {{/each}}