From 4544516c5c9374e6eefa15eae71f2e12513fe208 Mon Sep 17 00:00:00 2001
From: Oliver-Akins
Date: Wed, 7 Feb 2024 19:39:24 -0700
Subject: [PATCH] Implement the buttons spinbuttons for the inventory area
---
assets/minus.svg | 3 +
assets/sources.txt | 3 +
module/handlebars.mjs | 2 +-
module/sheets/GenericActorSheet.mjs | 27 +++++-
module/utils.mjs | 24 ++---
styles/sheets/actor/mvp.scss | 14 ++-
.../char-sheet-mvp/panels/backpack.pc.hbs | 96 ++++++++++++++-----
templates/actors/char-sheet-mvp/sheet.hbs | 33 -------
8 files changed, 131 insertions(+), 71 deletions(-)
create mode 100644 assets/minus.svg
diff --git a/assets/minus.svg b/assets/minus.svg
new file mode 100644
index 0000000..171613e
--- /dev/null
+++ b/assets/minus.svg
@@ -0,0 +1,3 @@
+
\ No newline at end of file
diff --git a/assets/sources.txt b/assets/sources.txt
index e9d03fc..eb52587 100644
--- a/assets/sources.txt
+++ b/assets/sources.txt
@@ -18,6 +18,9 @@ Fritz Duggan:
Landan Lloyd:
create.svg (https://thenounproject.com/icon/create-1447560/)
+Bismillah
+ minus.svg (https://thenounproject.com/icon/minus-1727966/)
+
Rokhman Kharis:
close.svg (https://thenounproject.com/icon/close-4996834/)
diff --git a/module/handlebars.mjs b/module/handlebars.mjs
index 32eec11..3c39add 100644
--- a/module/handlebars.mjs
+++ b/module/handlebars.mjs
@@ -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);
};
diff --git a/module/sheets/GenericActorSheet.mjs b/module/sheets/GenericActorSheet.mjs
index 57794da..96df69b 100644
--- a/module/sheets/GenericActorSheet.mjs
+++ b/module/sheets/GenericActorSheet.mjs
@@ -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})`);
diff --git a/module/utils.mjs b/module/utils.mjs
index 7d63d62..40f45a7 100644
--- a/module/utils.mjs
+++ b/module/utils.mjs
@@ -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]
+ );
};
\ No newline at end of file
diff --git a/styles/sheets/actor/mvp.scss b/styles/sheets/actor/mvp.scss
index ba9d43b..28fafaf 100644
--- a/styles/sheets/actor/mvp.scss
+++ b/styles/sheets/actor/mvp.scss
@@ -79,6 +79,12 @@
flex-direction: row;
align-items: center;
}
+ .grid-row {
+ display: grid;
+ grid-template-columns: 1fr min-content 25% min-content;
+ gap: 4px;
+ align-items: center;
+ }
.col {
display: flex;
flex-direction: column;
@@ -95,11 +101,15 @@
.bytes-input,
.supplies-count,
- .materials-count {
- width: 25%;
+ .materials-count,
+ .item-quantity {
text-align: center;
}
+ .item-quantity {
+ width: 25%
+ }
+
textarea {
resize: vertical;
}
diff --git a/templates/actors/char-sheet-mvp/panels/backpack.pc.hbs b/templates/actors/char-sheet-mvp/panels/backpack.pc.hbs
index 2be09a1..929dfac 100644
--- a/templates/actors/char-sheet-mvp/panels/backpack.pc.hbs
+++ b/templates/actors/char-sheet-mvp/panels/backpack.pc.hbs
@@ -1,9 +1,21 @@
{{#> dotdungeon.panel class="backpack" title="dotdungeon.actor.pc.panel.backpack"}}
-
{{else}}
-
+
This item hasn't been described yet
{{/if}}
diff --git a/templates/actors/char-sheet-mvp/sheet.hbs b/templates/actors/char-sheet-mvp/sheet.hbs
index 318729c..98e9dcc 100644
--- a/templates/actors/char-sheet-mvp/sheet.hbs
+++ b/templates/actors/char-sheet-mvp/sheet.hbs
@@ -38,37 +38,4 @@
{{> dotdungeon.pc.pets }}
{{> dotdungeon.pc.storage}}
-
- {{#if settings.devMode}}
-
-
- Settings:
-
{{dd-stringify settings}}
-
-
- Meta:
-
{{dd-stringify meta}}
-
-
-
- Config:
-
{{dd-stringify config}}
-
-
-
- Items:
-
{{dd-stringify items}}
-
-
-
- System:
-
{{dd-stringify system}}
-
-
-
- Actor:
-
{{dd-stringify actor}}
-
-
- {{/if}}
\ No newline at end of file