From d8b676535f98620bdea1016c44f93443e58990f5 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Thu, 4 Apr 2024 23:14:46 -0600 Subject: [PATCH] Add incrementer button support for item sheets --- module/sheets/Items/GenericItemSheet.mjs | 38 +++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/module/sheets/Items/GenericItemSheet.mjs b/module/sheets/Items/GenericItemSheet.mjs index ab67779..0776648 100644 --- a/module/sheets/Items/GenericItemSheet.mjs +++ b/module/sheets/Items/GenericItemSheet.mjs @@ -10,13 +10,6 @@ export class GenericItemSheet extends ItemSheet { `resourcesOrSupplies`, ]; - activateListeners(html) { - super.activateListeners(html); - - if (!this.isEditable) return; - console.debug(`.dungeon | Adding event listeners for Generic Item: ${this.id}`); - }; - async getData() { const ctx = {}; @@ -42,4 +35,35 @@ export class GenericItemSheet extends ItemSheet { return ctx; }; + + activateListeners(html) { + super.activateListeners(html); + + if (!this.isEditable) return; + console.debug(`.dungeon | Adding event listeners for Generic Item: ${this.id}`); + html.find(`button[data-increment]`) + .on(`click`, this._incrementValue.bind(this)); + html.find(`button[data-decrement]`) + .on(`click`, this._decrementValue.bind(this)); + }; + + async _incrementValue($e) { + const target = $e.currentTarget; + const data = target.dataset; + const value = getProperty(this.actor, data.increment); + if (typeof value != "number") { + return; + }; + this.actor.update({ [data.increment]: value + 1 }); + }; + + async _decrementValue($e) { + const target = $e.currentTarget; + const data = target.dataset; + const value = getProperty(this.actor, data.decrement); + if (typeof value != "number") { + return; + }; + this.actor.update({ [data.decrement]: value - 1 }); + }; };