Add incrementer button support for item sheets

This commit is contained in:
Oliver-Akins 2024-04-04 23:14:46 -06:00
parent 96b24d6445
commit d8b676535f

View file

@ -10,13 +10,6 @@ export class GenericItemSheet extends ItemSheet {
`resourcesOrSupplies`, `resourcesOrSupplies`,
]; ];
activateListeners(html) {
super.activateListeners(html);
if (!this.isEditable) return;
console.debug(`.dungeon | Adding event listeners for Generic Item: ${this.id}`);
};
async getData() { async getData() {
const ctx = {}; const ctx = {};
@ -42,4 +35,35 @@ export class GenericItemSheet extends ItemSheet {
return ctx; 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 });
};
}; };