Finish the Inventory item improvements

This commit is contained in:
Oliver-Akins 2024-02-06 19:29:05 -07:00
parent 83039c6144
commit 2f8ec1b79c
9 changed files with 107 additions and 13 deletions

View file

@ -254,6 +254,9 @@
}, },
"warn": { "warn": {
"negative-aspect-limit": "The Aspect limit must be 0 or greater" "negative-aspect-limit": "The Aspect limit must be 0 or greater"
},
"info": {
"increased-item-quantity": "Increased the item quantity for: {name}"
} }
}, },
"dialogs": { "dialogs": {
@ -274,6 +277,12 @@
"title": "You want to kill your pet?!", "title": "You want to kill your pet?!",
"content": "Are you sure you would like to kill the pet: {name}<br /><br />This action cannot be undone." "content": "Are you sure you would like to kill the pet: {name}<br /><br />This action cannot be undone."
} }
},
"untyped": {
"delete": {
"title": "Confirm Item Deletion",
"content": "Are you sure you would like to delete the item: {name}<br /><br />This action cannot be undone."
}
} }
}, },
"keyword": { "keyword": {
@ -317,6 +326,9 @@
}, },
"pet": { "pet": {
"name": "(Unnamed Pet)" "name": "(Unnamed Pet)"
},
"untyped": {
"name": "Unknown Item"
} }
} }
}, },

View file

@ -84,6 +84,7 @@ export class ActorHandler extends Actor {
*/ */
async preItemEmbed(item) { async preItemEmbed(item) {
let type = item.type[0].toUpperCase() + item.type.slice(1); let type = item.type[0].toUpperCase() + item.type.slice(1);
console.log(`preEmbed type =`, type)
if (this.fn?.[`pre${type}Embed`]) { if (this.fn?.[`pre${type}Embed`]) {
return await this.fn?.[`pre${type}Embed`].bind(this)(item); return await this.fn?.[`pre${type}Embed`].bind(this)(item);
}; };

View file

@ -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} */ /** @this {Actor} */
async function createCustomAspect() { async function createCustomAspect() {
await createCustomItem.bind(this)([{ 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 { export default {
atAspectLimit, atAspectLimit,
createCustomItem, createCustomItem,
createCustomUntyped,
createCustomAspect, createCustomAspect,
createCustomSpell, createCustomSpell,
createCustomPet, createCustomPet,
genericEmbeddedDelete, genericEmbeddedDelete,
preAspectEmbed, preAspectEmbed,
preUntypedEmbed,
}; };

View file

@ -23,7 +23,8 @@ export class ItemHandler extends Item {
}; };
async _preCreate(...args) { async _preCreate(...args) {
if (!this.fn?._preCreate) return; if (this.fn?._preCreate) return this.fn?._preCreate.bind(this)(...args);
return this.fn?._preCreate.bind(this)(...args); if (this.isEmbedded) return await this.actor?.preItemEmbed(this);
return;
}; };
}; };

View file

@ -12,7 +12,7 @@ import { ActorHandler } from "./documents/Actor/Handler.mjs";
import { ItemHandler } from "./documents/Item/Handler.mjs"; import { ItemHandler } from "./documents/Item/Handler.mjs";
// Item Sheets // Item Sheets
import { CustomItemSheet } from "./sheets/Items/CustomItemSheet.mjs"; import { UntypedItemSheet } from "./sheets/Items/UntypedItemSheet.mjs";
import { AspectSheet } from "./sheets/Items/AspectSheet.mjs"; import { AspectSheet } from "./sheets/Items/AspectSheet.mjs";
import { SpellSheet } from "./sheets/Items/SpellSheet.mjs"; import { SpellSheet } from "./sheets/Items/SpellSheet.mjs";
import { PetSheet } from "./sheets/Items/PetSheet.mjs"; import { PetSheet } from "./sheets/Items/PetSheet.mjs";
@ -41,7 +41,7 @@ Hooks.once(`init`, async () => {
CONFIG.Actor.dataModels.player = PlayerData; CONFIG.Actor.dataModels.player = PlayerData;
CONFIG.Actor.dataModels.sync = SyncData; CONFIG.Actor.dataModels.sync = SyncData;
CONFIG.Actor.dataModels.mob = MobData; CONFIG.Actor.dataModels.mob = MobData;
CONFIG.Item.dataModels.custom = DescribedItemData; CONFIG.Item.dataModels.untyped = DescribedItemData;
CONFIG.Item.dataModels.aspect = AspectItemData; CONFIG.Item.dataModels.aspect = AspectItemData;
CONFIG.Item.dataModels.spell = SpellItemData; CONFIG.Item.dataModels.spell = SpellItemData;
CONFIG.Item.dataModels.pet = PetItemData; CONFIG.Item.dataModels.pet = PetItemData;
@ -82,9 +82,9 @@ Hooks.once(`init`, async () => {
types: ["pet"], types: ["pet"],
label: "dotdungeon.sheet-names.PetSheet" label: "dotdungeon.sheet-names.PetSheet"
}); });
Items.registerSheet("dotdungeon", CustomItemSheet, { Items.registerSheet("dotdungeon", UntypedItemSheet, {
makeDefault: true, makeDefault: true,
label: "dotdungeon.sheet-names.CustomItemSheet" label: "dotdungeon.sheet-names.UntypedItemSheet"
}) })

View file

@ -1,6 +1,6 @@
import { GenericItemSheet } from "./GenericItemSheet.mjs"; import { GenericItemSheet } from "./GenericItemSheet.mjs";
export class CustomItemSheet extends GenericItemSheet { export class UntypedItemSheet extends GenericItemSheet {
static get defaultOptions() { static get defaultOptions() {
let opts = mergeObject( let opts = mergeObject(
super.defaultOptions, super.defaultOptions,

View file

@ -11,6 +11,6 @@
gap: 8px; gap: 8px;
.name { grid-area: name; } .name { grid-area: name; }
.usage { grid-area: usage; } .usage { grid-area: usage; white-space: nowrap; }
.description { grid-area: description; } .description { grid-area: description; }
} }

View file

@ -8,7 +8,7 @@
}, },
"Item": { "Item": {
"types": [ "types": [
"custom", "untyped",
"aspect", "aspect",
"weapon", "weapon",
"armour", "armour",

View file

@ -58,8 +58,59 @@
aria-valuenow="{{system.supplies}}" aria-valuenow="{{system.supplies}}"
> >
</label> </label>
<label class="grow col"> {{#each items.untyped as | item |}}
Inventory <details {{dd-expanded ../meta.expanded item.uuid}}>
<textarea class="grow" name="system.inventoryString">{{system.inventoryString}}</textarea> <summary data-collapse-id="{{item.uuid}}">
</label> {{item.name}} (x {{item.system.quantity}})
</summary>
<div class="item">
{{#if (defined item.system.buy)}}
<div>Cost: {{item.system.buy}}</div>
{{/if}}
{{#if item.system.description}}
<p>{{item.system.description}}</p>
{{/if}}
<div class="actions">
<button
type="button"
class="confirm"
data-embedded-edit="{{item.uuid}}"
>
Edit
</button>
<button
type="button"
class="neutral equal-padding"
data-message-type="Untyped"
data-message-content="{{item.system.description}}"
data-embedded-id="{{item.uuid}}"
>
<div aria-hidden="true" class="icon icon--20">
{{{ ../icons.chat-bubble }}}
</div>
</button>
<button
type="button"
class="danger equal-padding"
data-embedded-delete
data-embedded-id="{{item.uuid}}"
>
<div aria-hidden="true" class="icon icon--20">
{{{ ../icons.garbage-bin }}}
</div>
</button>
</div>
</div>
</details>
{{/each}}
<button
type="button"
class="confirm"
data-embedded-create="Untyped"
>
<div aria-hidden="true" class="icon icon--20">
{{{ icons.create }}}
</div>
Add Item
</button>
{{/ dotdungeon.panel}} {{/ dotdungeon.panel}}