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:
parent
0605542d62
commit
18cdc2addc
4 changed files with 20 additions and 48 deletions
|
|
@ -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 }
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue