Implement the buttons spinbuttons for the inventory area

This commit is contained in:
Oliver-Akins 2024-02-07 19:39:24 -07:00
parent 1c737b3dc4
commit 4544516c5c
8 changed files with 131 additions and 71 deletions

View file

@ -34,11 +34,11 @@ export const icons = [
`close.svg`,
`edit.svg`,
`sheet.svg`,
`minus.svg`,
];
export async function registerHandlebarsHelpers() {
console.log(Handlebars)
Handlebars.registerHelper(helpers);
};

View file

@ -1,4 +1,5 @@
import DOTDUNGEON from "../config.mjs";
import { getPath } from "../utils.mjs";
export class GenericActorSheet extends ActorSheet {
_expanded = new Set();
@ -54,6 +55,10 @@ export class GenericActorSheet extends ActorSheet {
.on(`click`, this.actor.genericSendToChat.bind(this.actor));
html.find(`[data-embedded-edit]`)
.on(`click`, this.actor.openEmbeddedSheet.bind(this.actor));
html.find(`button[data-increment]`)
.on(`click`, this._incrementValue.bind(this));
html.find(`button[data-decrement]`)
.on(`click`, this._decrementValue.bind(this));
};
async _handleRoll($e) {
@ -73,7 +78,27 @@ export class GenericActorSheet extends ActorSheet {
});
};
_handleSummaryToggle($e) {
async _incrementValue($e) {
const target = $e.currentTarget;
const data = target.dataset;
const value = getPath(data.increment, this.actor);
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 = getPath(data.decrement, this.actor);
if (typeof value != "number") {
return;
};
this.actor.update({ [data.decrement]: value - 1 });
};
async _handleSummaryToggle($e) {
let data = $e.currentTarget.dataset;
let open = $e.currentTarget.parentNode.open;
console.debug(`.dungeon | Collapse ID: ${data.collapseId} (open: ${open})`);

View file

@ -1,13 +1,15 @@
export function reloadWindows(type = null) {
if (!type) {
for (const window of globalThis.ui.windows) {
window.render(true);
};
return;
};
for (const window of globalThis.ui.windows) {
if (window instanceof type) {
window.render(true);
};
/**
* @param {string} path
* @param {object} data
* @returns {unknown}
*/
export function getPath(path, data) {
if (!path.includes(`.`)) {
return data[path];
};
let [ key, nextPath ] = path.split(`.`, 2)
return getPath(
nextPath,
data[key]
);
};