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 }); + }; };