From 2f8ec1b79c78bd9bbffb097c878b2d53a850008b Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Tue, 6 Feb 2024 19:29:05 -0700 Subject: [PATCH] Finish the Inventory item improvements --- langs/en-ca.json | 12 ++++ module/documents/Actor/Handler.mjs | 1 + module/documents/Actor/Player.mjs | 29 +++++++++ module/documents/Item/Handler.mjs | 5 +- module/dotdungeon.mjs | 8 +-- ...stomItemSheet.mjs => UntypedItemSheet.mjs} | 2 +- styles/sheets/items/custom.scss | 2 +- template.json | 2 +- .../char-sheet-mvp/panels/backpack.pc.hbs | 59 +++++++++++++++++-- 9 files changed, 107 insertions(+), 13 deletions(-) rename module/sheets/Items/{CustomItemSheet.mjs => UntypedItemSheet.mjs} (87%) diff --git a/langs/en-ca.json b/langs/en-ca.json index 11c28ba..0e505de 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -254,6 +254,9 @@ }, "warn": { "negative-aspect-limit": "The Aspect limit must be 0 or greater" + }, + "info": { + "increased-item-quantity": "Increased the item quantity for: {name}" } }, "dialogs": { @@ -274,6 +277,12 @@ "title": "You want to kill your pet?!", "content": "Are you sure you would like to kill the pet: {name}

This action cannot be undone." } + }, + "untyped": { + "delete": { + "title": "Confirm Item Deletion", + "content": "Are you sure you would like to delete the item: {name}

This action cannot be undone." + } } }, "keyword": { @@ -317,6 +326,9 @@ }, "pet": { "name": "(Unnamed Pet)" + }, + "untyped": { + "name": "Unknown Item" } } }, diff --git a/module/documents/Actor/Handler.mjs b/module/documents/Actor/Handler.mjs index 342521a..485de3d 100644 --- a/module/documents/Actor/Handler.mjs +++ b/module/documents/Actor/Handler.mjs @@ -84,6 +84,7 @@ export class ActorHandler extends Actor { */ async preItemEmbed(item) { let type = item.type[0].toUpperCase() + item.type.slice(1); + console.log(`preEmbed type =`, type) if (this.fn?.[`pre${type}Embed`]) { return await this.fn?.[`pre${type}Embed`].bind(this)(item); }; diff --git a/module/documents/Actor/Player.mjs b/module/documents/Actor/Player.mjs index a1282c9..7cae17d 100644 --- a/module/documents/Actor/Player.mjs +++ b/module/documents/Actor/Player.mjs @@ -46,6 +46,14 @@ async function createCustomItem(defaults, opts = {}) { }; }; +/** @this {Actor} */ +async function createCustomUntyped() { + await createCustomItem.bind(this)([{ + type: `untyped`, + name: game.i18n.format(`dotdungeon.defaults.untyped.name`), + }]); +}; + /** @this {Actor} */ async function createCustomAspect() { await createCustomItem.bind(this)([{ @@ -105,12 +113,33 @@ async function preAspectEmbed(item) { }; }; +/** + * @param {ItemHandler} item + * @this {Actor} + */ +async function preUntypedEmbed(item) { + let inventoryItem = this.itemTypes.untyped.find(i => i.name === item.name); + if (inventoryItem) { + inventoryItem.update({"system.quantity": inventoryItem.system.quantity + 1}); + ui.notifications.info( + game.i18n.format( + `dotdungeon.notification.info.increased-item-quantity`, + { name: inventoryItem.name } + ), + { console: false } + ); + return false; + }; +}; + export default { atAspectLimit, createCustomItem, + createCustomUntyped, createCustomAspect, createCustomSpell, createCustomPet, genericEmbeddedDelete, preAspectEmbed, + preUntypedEmbed, }; \ No newline at end of file diff --git a/module/documents/Item/Handler.mjs b/module/documents/Item/Handler.mjs index b16e3dc..dbb6903 100644 --- a/module/documents/Item/Handler.mjs +++ b/module/documents/Item/Handler.mjs @@ -23,7 +23,8 @@ export class ItemHandler extends Item { }; async _preCreate(...args) { - if (!this.fn?._preCreate) return; - return this.fn?._preCreate.bind(this)(...args); + if (this.fn?._preCreate) return this.fn?._preCreate.bind(this)(...args); + if (this.isEmbedded) return await this.actor?.preItemEmbed(this); + return; }; }; diff --git a/module/dotdungeon.mjs b/module/dotdungeon.mjs index f3ffe13..7f4e56f 100644 --- a/module/dotdungeon.mjs +++ b/module/dotdungeon.mjs @@ -12,7 +12,7 @@ import { ActorHandler } from "./documents/Actor/Handler.mjs"; import { ItemHandler } from "./documents/Item/Handler.mjs"; // Item Sheets -import { CustomItemSheet } from "./sheets/Items/CustomItemSheet.mjs"; +import { UntypedItemSheet } from "./sheets/Items/UntypedItemSheet.mjs"; import { AspectSheet } from "./sheets/Items/AspectSheet.mjs"; import { SpellSheet } from "./sheets/Items/SpellSheet.mjs"; import { PetSheet } from "./sheets/Items/PetSheet.mjs"; @@ -41,7 +41,7 @@ Hooks.once(`init`, async () => { CONFIG.Actor.dataModels.player = PlayerData; CONFIG.Actor.dataModels.sync = SyncData; CONFIG.Actor.dataModels.mob = MobData; - CONFIG.Item.dataModels.custom = DescribedItemData; + CONFIG.Item.dataModels.untyped = DescribedItemData; CONFIG.Item.dataModels.aspect = AspectItemData; CONFIG.Item.dataModels.spell = SpellItemData; CONFIG.Item.dataModels.pet = PetItemData; @@ -82,9 +82,9 @@ Hooks.once(`init`, async () => { types: ["pet"], label: "dotdungeon.sheet-names.PetSheet" }); - Items.registerSheet("dotdungeon", CustomItemSheet, { + Items.registerSheet("dotdungeon", UntypedItemSheet, { makeDefault: true, - label: "dotdungeon.sheet-names.CustomItemSheet" + label: "dotdungeon.sheet-names.UntypedItemSheet" }) diff --git a/module/sheets/Items/CustomItemSheet.mjs b/module/sheets/Items/UntypedItemSheet.mjs similarity index 87% rename from module/sheets/Items/CustomItemSheet.mjs rename to module/sheets/Items/UntypedItemSheet.mjs index 8b40820..fcbe232 100644 --- a/module/sheets/Items/CustomItemSheet.mjs +++ b/module/sheets/Items/UntypedItemSheet.mjs @@ -1,6 +1,6 @@ import { GenericItemSheet } from "./GenericItemSheet.mjs"; -export class CustomItemSheet extends GenericItemSheet { +export class UntypedItemSheet extends GenericItemSheet { static get defaultOptions() { let opts = mergeObject( super.defaultOptions, diff --git a/styles/sheets/items/custom.scss b/styles/sheets/items/custom.scss index a390b09..0899a91 100644 --- a/styles/sheets/items/custom.scss +++ b/styles/sheets/items/custom.scss @@ -11,6 +11,6 @@ gap: 8px; .name { grid-area: name; } - .usage { grid-area: usage; } + .usage { grid-area: usage; white-space: nowrap; } .description { grid-area: description; } } \ No newline at end of file diff --git a/template.json b/template.json index 46311b1..f8aefd5 100644 --- a/template.json +++ b/template.json @@ -8,7 +8,7 @@ }, "Item": { "types": [ - "custom", + "untyped", "aspect", "weapon", "armour", diff --git a/templates/actors/char-sheet-mvp/panels/backpack.pc.hbs b/templates/actors/char-sheet-mvp/panels/backpack.pc.hbs index 1ba1125..c80f46a 100644 --- a/templates/actors/char-sheet-mvp/panels/backpack.pc.hbs +++ b/templates/actors/char-sheet-mvp/panels/backpack.pc.hbs @@ -58,8 +58,59 @@ aria-valuenow="{{system.supplies}}" > - + {{#each items.untyped as | item |}} +
+ + {{item.name}} (x {{item.system.quantity}}) + +
+ {{#if (defined item.system.buy)}} +
Cost: {{item.system.buy}}
+ {{/if}} + {{#if item.system.description}} +

{{item.system.description}}

+ {{/if}} +
+ + + +
+
+
+ {{/each}} + {{/ dotdungeon.panel}} \ No newline at end of file