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 {
|
export class DotDungeonActor extends Actor {
|
||||||
async createEmbeddedItem(defaults, opts = {}) {
|
async createEmbeddedItem(defaults, opts = {}) {
|
||||||
let items = await this.createEmbeddedDocuments(`Item`, defaults);
|
let items = await this.createEmbeddedDocuments(`Item`, defaults);
|
||||||
|
|
@ -17,20 +15,16 @@ export class DotDungeonActor extends Actor {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @param {DotDungeonItem} item */
|
async preItemEmbed(data) {
|
||||||
async preItemEmbed(item) {
|
let embedded = this.itemTypes[data.type].find(i => {
|
||||||
console.log(`preEmbed`, item._source._id);
|
return i.name === data.name
|
||||||
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);
|
|
||||||
if (embedded) {
|
if (embedded) {
|
||||||
await embedded.update({"system.quantity": embedded.system.quantity + 1});
|
await embedded.update({"system.quantity": embedded.system.quantity + 1});
|
||||||
ui.notifications.info(
|
ui.notifications.info(
|
||||||
game.i18n.format(
|
game.i18n.format(
|
||||||
`dotdungeon.notification.info.increased-item-quantity`,
|
`dotdungeon.notification.info.increased-item-quantity`,
|
||||||
{ name: inventoryItem.name }
|
{ name: embedded.name, quantity: embedded.system.quantity }
|
||||||
),
|
),
|
||||||
{ console: false }
|
{ console: false }
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -27,39 +27,6 @@ export class Player extends DotDungeonActor {
|
||||||
return this.itemTypes.aspect.length >= limit;
|
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() {
|
getRollData() {
|
||||||
const data = {
|
const data = {
|
||||||
initiative: this.system.stats.hands ?? 0,
|
initiative: this.system.stats.hands ?? 0,
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,20 @@
|
||||||
import { DotDungeonItem } from "./GenericItem.mjs";
|
import { DotDungeonItem } from "./GenericItem.mjs";
|
||||||
|
|
||||||
export class Aspect extends DotDungeonItem {
|
export class Aspect extends DotDungeonItem {
|
||||||
async _preCreate() {
|
async _preCreate(...args) {
|
||||||
if (this.isEmbedded) {
|
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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
export class DotDungeonItem extends Item {
|
export class DotDungeonItem extends Item {
|
||||||
async _preCreate() {
|
async _preCreate(...args) {
|
||||||
if (this.isEmbedded) {
|
if (this.isEmbedded) {
|
||||||
return await this.actor?.preItemEmbed(this);
|
return await this.actor?.preItemEmbed(...args);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue