Get the item embedding working in a cleaner way where most of the item embedding logic is handled in the item's class instead of the actor's class

This commit is contained in:
Oliver-Akins 2024-03-22 20:23:28 -06:00
parent 0605542d62
commit 18cdc2addc
4 changed files with 20 additions and 48 deletions

View file

@ -1,5 +1,3 @@
import { DotDungeonItem } from "../Item/GenericItem.mjs";
export class DotDungeonActor extends Actor {
async createEmbeddedItem(defaults, opts = {}) {
let items = await this.createEmbeddedDocuments(`Item`, defaults);
@ -17,20 +15,16 @@ export class DotDungeonActor extends Actor {
};
};
/** @param {DotDungeonItem} item */
async preItemEmbed(item) {
console.log(`preEmbed`, item._source._id);
let type = item.type[0].toUpperCase() + item.type.slice(1);
if (this[`pre${type}Embed`]) {
return await this[`pre${type}Embed`](item);
};
let embedded = this.itemTypes[item.type].find(i => i._source._id === item._source._id);
async preItemEmbed(data) {
let embedded = this.itemTypes[data.type].find(i => {
return i.name === data.name
});
if (embedded) {
await embedded.update({"system.quantity": embedded.system.quantity + 1});
ui.notifications.info(
game.i18n.format(
`dotdungeon.notification.info.increased-item-quantity`,
{ name: inventoryItem.name }
{ name: embedded.name, quantity: embedded.system.quantity }
),
{ console: false }
);