Make it so that the actor can reject embedded items using the Item pre-create hook
This commit is contained in:
parent
1701547e57
commit
3791a7199c
4 changed files with 43 additions and 12 deletions
|
|
@ -39,4 +39,16 @@ export class ActorHandler extends Actor {
|
|||
if (!this.fn?.[`createCustom${data.embeddedCreate}`]) return;
|
||||
this.fn?.[`createCustom${data.embeddedCreate}`].bind(this)($event);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ItemHandler} item
|
||||
* @returns {boolean} true to allow the document to be embedded
|
||||
*/
|
||||
async preItemEmbed(item) {
|
||||
let type = item.type[0].toUpperCase() + item.type.slice(1);
|
||||
if (this.fn?.[`pre${type}Embed`]) {
|
||||
return await this.fn?.[`pre${type}Embed`].bind(this)(item);
|
||||
};
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { ItemHandler } from "../Item/Handler.mjs";
|
||||
|
||||
/** @this {Actor} */
|
||||
async function genericEmbeddedUpdate($event) {
|
||||
let data = $event.delegateTarget.dataset;
|
||||
|
|
@ -68,10 +70,29 @@ async function createCustomSpell() {
|
|||
}]);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {ItemHandler} item
|
||||
* @this {Actor}
|
||||
*/
|
||||
async function preAspectEmbed(item) {
|
||||
let limit = 1
|
||||
if (this.itemTypes.aspect.length >= limit) {
|
||||
ui.notifications.error(
|
||||
game.i18n.format(
|
||||
`dotdungeon.notification.error.aspect-limit-reached`,
|
||||
{ limit }
|
||||
),
|
||||
{ console: false }
|
||||
);
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
export default {
|
||||
genericEmbeddedDelete,
|
||||
genericEmbeddedUpdate,
|
||||
createCustomItem,
|
||||
createCustomAspect,
|
||||
createCustomSpell
|
||||
createCustomSpell,
|
||||
preAspectEmbed,
|
||||
};
|
||||
|
|
@ -1,14 +1,7 @@
|
|||
/** @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;
|
||||
/** @this {ItemHandler} */
|
||||
async function _preCreate(_data, _options, _user) {
|
||||
if (this.isEmbedded) {
|
||||
return await this.actor?.preItemEmbed(this);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import AspectItem from "./Aspect.mjs";
|
||||
|
||||
/**
|
||||
* @extends {Item}
|
||||
*/
|
||||
export class ItemHandler extends Item {
|
||||
/** @override */
|
||||
|
||||
itemTypes = {
|
||||
aspect: AspectItem,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue