diff --git a/module/documents/Actor/GenericActor.mjs b/module/documents/Actor/GenericActor.mjs index 7debd74..b597d55 100644 --- a/module/documents/Actor/GenericActor.mjs +++ b/module/documents/Actor/GenericActor.mjs @@ -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 } ); diff --git a/module/documents/Actor/Player.mjs b/module/documents/Actor/Player.mjs index 404283f..ff54481 100644 --- a/module/documents/Actor/Player.mjs +++ b/module/documents/Actor/Player.mjs @@ -27,39 +27,6 @@ export class Player extends DotDungeonActor { return this.itemTypes.aspect.length >= limit; }; - async preAspectEmbed(item) { - if (this.atAspectLimit) { - ui.notifications.error( - game.i18n.format( - `dotdungeon.notification.error.aspect-limit-reached`, - { limit: game.settings.get(`dotdungeon`, `aspectLimit`) } - ), - { console: false } - ); - return false; - }; - }; - - /** - * TODO: Make this quantity increase work for all item types - * TODO: Find item based of the source's ID, not name - * @param {DotDungeonItem} item - */ - // async 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; - // }; - // }; - getRollData() { const data = { initiative: this.system.stats.hands ?? 0, diff --git a/module/documents/Item/Aspect.mjs b/module/documents/Item/Aspect.mjs index 07698a9..8906c09 100644 --- a/module/documents/Item/Aspect.mjs +++ b/module/documents/Item/Aspect.mjs @@ -1,9 +1,20 @@ import { DotDungeonItem } from "./GenericItem.mjs"; export class Aspect extends DotDungeonItem { - async _preCreate() { + async _preCreate(...args) { if (this.isEmbedded) { - return await this.actor?.preItemEmbed(this); + if (this.actor.atAspectLimit) { + ui.notifications.error( + game.i18n.format( + `dotdungeon.notification.error.aspect-limit-reached`, + { limit: game.settings.get(`dotdungeon`, `aspectLimit`) } + ), + { console: false } + ); + return false; + }; + + return await this.actor?.preItemEmbed(...args); }; } }; diff --git a/module/documents/Item/GenericItem.mjs b/module/documents/Item/GenericItem.mjs index b52ddcd..e1034d3 100644 --- a/module/documents/Item/GenericItem.mjs +++ b/module/documents/Item/GenericItem.mjs @@ -1,7 +1,7 @@ export class DotDungeonItem extends Item { - async _preCreate() { + async _preCreate(...args) { if (this.isEmbedded) { - return await this.actor?.preItemEmbed(this); + return await this.actor?.preItemEmbed(...args); }; };