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
|
|
@ -227,7 +227,8 @@
|
||||||
"error": {
|
"error": {
|
||||||
"invalid-integer": "You must enter a valid whole number",
|
"invalid-integer": "You must enter a valid whole number",
|
||||||
"item-not-found": "Failed to find an item to delete",
|
"item-not-found": "Failed to find an item to delete",
|
||||||
"spell-create-failed": "Failed to create a custom spell"
|
"spell-create-failed": "Failed to create a custom spell",
|
||||||
|
"aspect-limit-reached": "You cannot have more than {limit} aspects"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dialogs": {
|
"dialogs": {
|
||||||
|
|
|
||||||
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);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
@ -6,6 +6,7 @@ import { SyncData } from "./models/SyncData.mjs";
|
||||||
|
|
||||||
// Main Documents
|
// Main Documents
|
||||||
import { ActorHandler } from "./documents/Actor/Handler.mjs";
|
import { ActorHandler } from "./documents/Actor/Handler.mjs";
|
||||||
|
import { ItemHandler } from "./documents/Item/Handler.mjs";
|
||||||
|
|
||||||
// Character Sheets
|
// Character Sheets
|
||||||
import { SpellSheet } from "./sheets/SpellSheet.mjs";
|
import { SpellSheet } from "./sheets/SpellSheet.mjs";
|
||||||
|
|
@ -34,6 +35,7 @@ Hooks.once(`init`, () => {
|
||||||
CONFIG.Item.dataModels.aspect = AspectItemData;
|
CONFIG.Item.dataModels.aspect = AspectItemData;
|
||||||
CONFIG.Item.dataModels.spell = SpellItemData;
|
CONFIG.Item.dataModels.spell = SpellItemData;
|
||||||
CONFIG.Actor.documentClass = ActorHandler;
|
CONFIG.Actor.documentClass = ActorHandler;
|
||||||
|
CONFIG.Item.documentClass = ItemHandler;
|
||||||
|
|
||||||
CONFIG.DOTDUNGEON = DOTDUNGEON;
|
CONFIG.DOTDUNGEON = DOTDUNGEON;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
export class AspectSheet extends ItemSheet {
|
import { GenericItemSheet } from "./GenericItemSheet.mjs";
|
||||||
|
|
||||||
|
export class AspectSheet extends GenericItemSheet {
|
||||||
static get defaultOptions() {
|
static get defaultOptions() {
|
||||||
let opts = mergeObject(
|
let opts = mergeObject(
|
||||||
super.defaultOptions,
|
super.defaultOptions,
|
||||||
|
|
@ -21,13 +23,13 @@ export class AspectSheet extends ItemSheet {
|
||||||
|
|
||||||
async getData() {
|
async getData() {
|
||||||
const ctx = {};
|
const ctx = {};
|
||||||
const item = this.item.toObject(false);
|
const item = this.item;
|
||||||
|
|
||||||
ctx.name = super.name;
|
|
||||||
ctx.item = item;
|
ctx.item = item;
|
||||||
ctx.system = item.system;
|
ctx.system = item.system;
|
||||||
ctx.flags = item.flags;
|
ctx.flags = item.flags;
|
||||||
|
|
||||||
|
console.log(item.uuid, `context:`, ctx);
|
||||||
return ctx;
|
return ctx;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -33,7 +33,7 @@ export class PlayerSheet extends GenericActorSheet {
|
||||||
canAddAspect: ctx.items.aspect.length == 0,
|
canAddAspect: ctx.items.aspect.length == 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(ctx)
|
console.log(actor.uuid, `context:`, ctx)
|
||||||
return ctx;
|
return ctx;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -18,7 +18,7 @@ export class SpellSheet extends GenericItemSheet {
|
||||||
super.activateListeners(html);
|
super.activateListeners(html);
|
||||||
|
|
||||||
if (!this.isEditable) return;
|
if (!this.isEditable) return;
|
||||||
console.debug(`.dungeon | Adding event listeners for Generic Item: ${this.id}`);
|
console.debug(`.dungeon | Adding event listeners for Spell Item: ${this.id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
async getData() {
|
async getData() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue