Add an ItemHandler class and prevent players from having more than 1 aspect.
This commit is contained in:
parent
82108bfe5f
commit
38fcb1193a
7 changed files with 49 additions and 6 deletions
17
module/documents/Item/Aspect.mjs
Normal file
17
module/documents/Item/Aspect.mjs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/** @this {Item} */
|
||||
async function _preCreate(data, options, user) {
|
||||
if (this.parent.itemTypes.aspect.length > 0) {
|
||||
ui.notifications.error(
|
||||
game.i18n.format(
|
||||
`dotdungeon.notification.error.aspect-limit-reached`,
|
||||
{ limit: 1 }
|
||||
),
|
||||
{ console: false }
|
||||
);
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
export default {
|
||||
_preCreate,
|
||||
};
|
||||
21
module/documents/Item/Handler.mjs
Normal file
21
module/documents/Item/Handler.mjs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import AspectItem from "./Aspect.mjs";
|
||||
|
||||
export class ItemHandler extends Item {
|
||||
itemTypes = {
|
||||
aspect: AspectItem,
|
||||
};
|
||||
|
||||
constructor(data, ctx) {
|
||||
super(data, ctx);
|
||||
};
|
||||
|
||||
/** @type {class|undefined} */
|
||||
get fn() {
|
||||
return this.itemTypes[this.type];
|
||||
};
|
||||
|
||||
async _preCreate(...args) {
|
||||
if (!this.fn?._preCreate) return;
|
||||
return this.fn?._preCreate.bind(this)(...args);
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue