From ade4cd7d4039cd57ef7eb2438497ea362b315cba Mon Sep 17 00:00:00 2001 From: U~man Date: Thu, 30 Jul 2020 15:26:47 +0200 Subject: [PATCH] FIX: Attack counters --- src/module/actor/monster-sheet.js | 49 +++++++++---------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/src/module/actor/monster-sheet.js b/src/module/actor/monster-sheet.js index d47d892..15ee7c3 100644 --- a/src/module/actor/monster-sheet.js +++ b/src/module/actor/monster-sheet.js @@ -136,41 +136,20 @@ export class OseActorSheetMonster extends OseActorSheet { }); } - async _onCountChange(event) { - event.preventDefault(); - const itemId = event.currentTarget.closest(".item").dataset.itemId; - const item = this.actor.getOwnedItem(itemId); - if (event.target.dataset.field == "value") { - return item.update({ - "data.counter.value": parseInt(event.target.value), - }); - } else if (event.target.dataset.field == "max") { - return item.update({ - "data.counter.max": parseInt(event.target.value), + async _resetCounters(event) { + const weapons = this.actor.data.items.filter(i => i.type === 'weapon'); + for (let wp of weapons) { + const item = this.actor.getOwnedItem(wp._id); + await item.update({ + data: { + counter: { + value: parseInt(wp.data.counter.max), + }, + }, }); } } - async _resetCounters(event) { - $(event.currentTarget) - .closest(".abilities") - .find(".item") - .each(async (_, el) => { - let itemId = el.dataset.itemId; - const item = this.actor.getOwnedItem(itemId); - if (item.data.type == "weapon") { - await item.update({ - _id: item.id, - data: { - counter: { - value: parseInt(item.data.data.counter.max), - }, - }, - }); - } - }); - } - /** * Activate event listeners using the prepared sheet HTML * @param html {HTML} The prepared HTML object ready to be rendered into the DOM @@ -242,10 +221,10 @@ export class OseActorSheetMonster extends OseActorSheet { actorObject.rollAppearing({ event: event, check: check }); }); - html - .find(".counter input") - .click((ev) => ev.target.select()) - .change(this._onCountChange.bind(this)); + // html + // .find(".counter input") + // .click((ev) => ev.target.select()) + // .change(this._onCountChange.bind(this)); html.find(".hp-roll").click((ev) => { let actorObject = this.actor;