From 39917a0f89e35c76f04fad30307ece0df1628eda Mon Sep 17 00:00:00 2001 From: macniel Date: Fri, 3 Oct 2025 15:27:48 +0200 Subject: [PATCH] Implements rudimentary item management --- src/main.mjs | 1 + src/module/sheets/characterSheet.mjs | 17 ++++++- src/module/sheets/groupSheet.mjs | 44 ++++++++++++++++++- src/style/_character-sheet.scss | 35 ++++++++++++++- src/style/_equipment-sheet.scss | 11 +++-- src/style/_group-sheet.scss | 20 ++++++--- src/templates/actor/actor-character-sheet.hbs | 14 +++--- src/templates/actor/group-sheet.hbs | 5 +++ src/templates/ui/partial-equipment-button.hbs | 4 ++ 9 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 src/templates/ui/partial-equipment-button.hbs diff --git a/src/main.mjs b/src/main.mjs index 170e8dc9..11fe8153 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -20,6 +20,7 @@ async function preloadHandlebarsTemplates() { 'systems/DSA_4-1/templates/ui/partial-talent-editable.hbs', 'systems/DSA_4-1/templates/ui/partial-die.hbs', 'systems/DSA_4-1/templates/ui/partial-advantage-button.hbs', + 'systems/DSA_4-1/templates/ui/partial-equipment-button.hbs', 'systems/DSA_4-1/templates/ui/partial-array-editor.hbs' ]); } diff --git a/src/module/sheets/characterSheet.mjs b/src/module/sheets/characterSheet.mjs index 96b1955e..5abb797b 100644 --- a/src/module/sheets/characterSheet.mjs +++ b/src/module/sheets/characterSheet.mjs @@ -156,6 +156,7 @@ export class CharacterSheet extends ActorSheet { #addEquipmentsToContext(context) { context.equipments = []; const actorData = context.data; + context.carryingweight = 0; Object.values(actorData.items).forEach( (item, index) => { if (item.type === "Equipment") { context.equipments.push({ @@ -164,8 +165,11 @@ export class CharacterSheet extends ActorSheet { quantity: item.system.quantity, name: item.name, }) + context.carryingweight += item.system.quantity * item.system.weight; } }) + context.maxcarryingcapacity = actorData.system.attribute.kk.aktuell + context.carryingpercentage = (context.carryingweight / context.maxcarryingcapacity)*100; } prepareEigenschaftRoll(actorData, name) { @@ -323,7 +327,7 @@ export class CharacterSheet extends ActorSheet { }) html.on('click', '.equipment .name', (evt) => { - this.openEmbeddedDocument(evt.target.dataset.id); + this.openEmbeddedDocument(evt.target.parentElement.dataset.id); evt.stopPropagation(); }) @@ -358,6 +362,17 @@ export class CharacterSheet extends ActorSheet { li.addEventListener("dragstart", handler, false); }); + new ContextMenu(html, '.equipment', [ + { + name: "Aus dem Inventar entfernen", + icon: '', + callback: (event) => { + this.object.deleteEmbeddedDocuments('Item', [event[0].dataset.id]) + }, + condition: () => true + } + ]); + } #handleDroppedSkill(actor, skill) { diff --git a/src/module/sheets/groupSheet.mjs b/src/module/sheets/groupSheet.mjs index dd53d5c4..1f4a9efd 100644 --- a/src/module/sheets/groupSheet.mjs +++ b/src/module/sheets/groupSheet.mjs @@ -65,9 +65,22 @@ export class GroupSheet extends ActorSheet { } ) } - console.log(groupData, context.characters) - return await context; + + context.equipments = []; + const actorData = context.data; + Object.values(actorData.items).forEach( (item, index) => { + if (item.type === "Equipment") { + context.equipments.push({ + index: index, + id: item._id, + quantity: item.system.quantity, + name: item.name, + }) + } + }) + + return await context; } /** @override */ @@ -97,6 +110,16 @@ export class GroupSheet extends ActorSheet { }) ui.notifications.info(`${character.name} ist der Heldengruppe ${group.name} beigetreten`) } + if (data.type === "Equipment") { + const uuid = await foundry.utils.parseUuid(data.uuid); + const equipment = await (game.actors.get(uuid.id)) + ui.notifications.info(`${equipment.name} befindet sich nun im Inventar der Heldengruppe ${group.name}`) + return true; + } + } + + openEmbeddedDocument(documentId) { + this.object.items.get(documentId).sheet.render(true) } activateListeners(html) { @@ -122,5 +145,22 @@ export class GroupSheet extends ActorSheet { (await game.actors.get(id)).sheet.render(true); } }) + + + html.on('click', '.equipment .name', (evt) => { + this.openEmbeddedDocument(evt.target.dataset.id); + evt.stopPropagation(); + }) + + new ContextMenu(html, '.equipment', [ + { + name: "Aus dem Gruppeninventar entfernen", + icon: '', + callback: (event) => { + this.object.deleteEmbeddedDocuments('Item', [event[0].dataset.id]) + }, + condition: () => true + } + ]); } } diff --git a/src/style/_character-sheet.scss b/src/style/_character-sheet.scss index e57c691c..4ad0709c 100644 --- a/src/style/_character-sheet.scss +++ b/src/style/_character-sheet.scss @@ -52,6 +52,39 @@ overflow: auto; } + .backpack { + position: absolute; + left: 0; + top: 0; + bottom: 0; + right: 0; + padding: 8px; + + .resource { + + position: relative; + border: 1px inset #ccc; + background-color: rgba(0,0,0,0.2); + height: 8px; + + span.fill { + position:absolute; + left: 0; + top: 0; + bottom: 0; + background: linear-gradient(to bottom, #0bad29 0%,#11f128 50%,#0cde24 51%,#6ff77b 100%); + } + + } + + .equipment:hover { + .item-name { + text-shadow: 0 0 10px rgb(255 0 0); + } + } + } + + } -} \ No newline at end of file +} diff --git a/src/style/_equipment-sheet.scss b/src/style/_equipment-sheet.scss index 910033d5..dc8ddbc0 100644 --- a/src/style/_equipment-sheet.scss +++ b/src/style/_equipment-sheet.scss @@ -5,14 +5,17 @@ position: relative; top: 5px; - .tab.meta.active { - - position: absolute; + .tab.active { + padding: 4px; top: 0; bottom: 0; left: 0; right: 0; - padding: 4px; + } + + .tab.meta.active { + + position: absolute; display: grid; grid-auto-columns: 1fr 1fr; grid-template-columns: 80px auto; diff --git a/src/style/_group-sheet.scss b/src/style/_group-sheet.scss index a39b8874..730b6da4 100644 --- a/src/style/_group-sheet.scss +++ b/src/style/_group-sheet.scss @@ -18,16 +18,19 @@ position: absolute; left: 0; right: 0; - top: 27px; + top: 76px; height: 32px; + padding: 0 16px; } .sheet-body { position: absolute; - top: 112px; - left: 2px; - bottom: 2px; - right: 2px; + top: 98px; + left: 0; + bottom: 0; + right: 0; + padding: 8px; + margin: 8px; div.tab { height: 100%; @@ -41,6 +44,7 @@ overflow-x: auto; height: 100%; width: 100%; + gap: 8px; &.minimal { display: unset!important; @@ -167,4 +171,10 @@ } + .equipment:hover { + .item-name { + text-shadow: 0 0 10px rgb(255 0 0); + } + } + } diff --git a/src/templates/actor/actor-character-sheet.hbs b/src/templates/actor/actor-character-sheet.hbs index 338afbb6..d80b6bdc 100644 --- a/src/templates/actor/actor-character-sheet.hbs +++ b/src/templates/actor/actor-character-sheet.hbs @@ -146,14 +146,16 @@
-
diff --git a/src/templates/actor/group-sheet.hbs b/src/templates/actor/group-sheet.hbs index 26d3b79e..cea13336 100644 --- a/src/templates/actor/group-sheet.hbs +++ b/src/templates/actor/group-sheet.hbs @@ -68,6 +68,11 @@ {{/if}}
+
diff --git a/src/templates/ui/partial-equipment-button.hbs b/src/templates/ui/partial-equipment-button.hbs new file mode 100644 index 00000000..9dc4bffc --- /dev/null +++ b/src/templates/ui/partial-equipment-button.hbs @@ -0,0 +1,4 @@ +
+ {{this.quantity}} + {{this.name}} +