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;
|
if (!this.fn?.[`createCustom${data.embeddedCreate}`]) return;
|
||||||
this.fn?.[`createCustom${data.embeddedCreate}`].bind(this)($event);
|
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} */
|
/** @this {Actor} */
|
||||||
async function genericEmbeddedUpdate($event) {
|
async function genericEmbeddedUpdate($event) {
|
||||||
let data = $event.delegateTarget.dataset;
|
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 {
|
export default {
|
||||||
genericEmbeddedDelete,
|
genericEmbeddedDelete,
|
||||||
genericEmbeddedUpdate,
|
genericEmbeddedUpdate,
|
||||||
createCustomItem,
|
createCustomItem,
|
||||||
createCustomAspect,
|
createCustomAspect,
|
||||||
createCustomSpell
|
createCustomSpell,
|
||||||
|
preAspectEmbed,
|
||||||
};
|
};
|
||||||
|
|
@ -1,14 +1,7 @@
|
||||||
/** @this {Item} */
|
/** @this {ItemHandler} */
|
||||||
async function _preCreate(data, options, user) {
|
async function _preCreate(_data, _options, _user) {
|
||||||
if (this.parent.itemTypes.aspect.length > 0) {
|
if (this.isEmbedded) {
|
||||||
ui.notifications.error(
|
return await this.actor?.preItemEmbed(this);
|
||||||
game.i18n.format(
|
|
||||||
`dotdungeon.notification.error.aspect-limit-reached`,
|
|
||||||
{ limit: 1 }
|
|
||||||
),
|
|
||||||
{ console: false }
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
import AspectItem from "./Aspect.mjs";
|
import AspectItem from "./Aspect.mjs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends {Item}
|
||||||
|
*/
|
||||||
export class ItemHandler extends Item {
|
export class ItemHandler extends Item {
|
||||||
|
/** @override */
|
||||||
|
|
||||||
itemTypes = {
|
itemTypes = {
|
||||||
aspect: AspectItem,
|
aspect: AspectItem,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue