From 762b2978952e1d82bc2077ff1800d4d678665313 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Tue, 16 Jan 2024 19:24:56 -0700 Subject: [PATCH] Add the data model for structures and prevent them from being embedded in most actors. --- langs/en-ca.json | 3 ++- module/documents/Item/Handler.mjs | 4 +++- module/documents/Item/Structure.mjs | 23 +++++++++++++++++++++++ module/models/Item/Structure.mjs | 22 ++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 module/documents/Item/Structure.mjs create mode 100644 module/models/Item/Structure.mjs diff --git a/langs/en-ca.json b/langs/en-ca.json index 6e943fb..598ae62 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -232,7 +232,8 @@ "invalid-integer": "You must enter a valid whole number", "item-not-found": "Failed to find an item to delete", "spell-create-failed": "Failed to create a custom spell", - "aspect-limit-reached": "You cannot have more than {limit} aspects" + "aspect-limit-reached": "You cannot have more than {limit} aspects", + "cant-embed-item": "Cannot embed item with type \"{item.type}\" in \"{actor.type}\"" }, "warn": { "negative-aspect-limit": "The Aspect limit must be 0 or greater" diff --git a/module/documents/Item/Handler.mjs b/module/documents/Item/Handler.mjs index 5018d57..7b1f210 100644 --- a/module/documents/Item/Handler.mjs +++ b/module/documents/Item/Handler.mjs @@ -1,11 +1,13 @@ import AspectItem from "./Aspect.mjs"; import SpellItem from "./Spell.mjs"; +import StructureItem from "./Structure.mjs"; /** @extends {Item} */ export class ItemHandler extends Item { proxyTargets = { aspect: AspectItem, - spell: SpellItem + spell: SpellItem, + structure: StructureItem, }; constructor(data, ctx) { diff --git a/module/documents/Item/Structure.mjs b/module/documents/Item/Structure.mjs new file mode 100644 index 0000000..c443a21 --- /dev/null +++ b/module/documents/Item/Structure.mjs @@ -0,0 +1,23 @@ +import { ItemHandler } from "./Handler.mjs"; + +/** @this {ItemHandler} */ +async function _preCreate() { + if (this.isEmbedded) { + let actor = this.actor; + if (actor.type === "settlement") { + return await actor.preItemEmbed(this); + }; + ui.notifications.error( + game.i18n.format( + `dotdungeon.notification.error.cant-embed-item`, + { item: this, actor } + ), + { console: false, } + ); + return false; + }; +}; + +export default { + _preCreate, +}; \ No newline at end of file diff --git a/module/models/Item/Structure.mjs b/module/models/Item/Structure.mjs new file mode 100644 index 0000000..7127c30 --- /dev/null +++ b/module/models/Item/Structure.mjs @@ -0,0 +1,22 @@ +import { DescribedItemData } from "./DescribedItemData.mjs"; + +export class StructureItemData extends DescribedItemData { + static defineSchema() { + const fields = foundry.data.fields; + return mergeObject(super.defineSchema(), { + one_night: new fields.NumberField({ + initial: null, + nullable: true, + }), + upkeep: new fields.NumberField({ + initial: null, + nullable: true, + }), + construction_length: new fields.NumberField({ + min: 0, + initial: 0, + nullable: false, + }), + }); + }; +}; \ No newline at end of file