From 4d0f29d7f0319893f5bd077f2e26f2816f85dd87 Mon Sep 17 00:00:00 2001 From: Eldritch-Oliver Date: Fri, 10 Oct 2025 21:49:32 -0600 Subject: [PATCH] Prevent creating a Trait when it's on a non-geist Actor --- langs/en-ca.json | 3 ++- module/data/Item/Trait.mjs | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/langs/en-ca.json b/langs/en-ca.json index 4ba733a..93d8f79 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -202,7 +202,8 @@ "invalid-socket": "Invalid socket data received, this means a module or system bug is present.", "unknown-socket-event": "An unknown socket event was received: {event}", "no-active-gm": "No active @USER.GM is logged in, you must wait for a @USER.GM to be active before you can do that.", - "malformed-socket-payload": "Socket event \"{event}\" received with malformed payload. Details: {details}" + "malformed-socket-payload": "Socket event \"{event}\" received with malformed payload. Details: {details}", + "invalid-parent-document": "Cannot create an item with type \"{itemType}\" on a parent document of type \"{parentType}\"" }, "warn": { "cannot-go-negative": "\"{name}\" is unable to be a negative number." diff --git a/module/data/Item/Trait.mjs b/module/data/Item/Trait.mjs index 1a90c5a..775d5aa 100644 --- a/module/data/Item/Trait.mjs +++ b/module/data/Item/Trait.mjs @@ -1,11 +1,29 @@ +import { localizer } from "../../utils/Localizer.mjs"; + const { fields } = foundry.data; export class TraitData extends foundry.abstract.TypeDataModel { // #region Schema static defineSchema() { return { - description: fields.HTMLField({ blank: true, nullable: false, trim: true }), + description: new fields.HTMLField({ blank: true, nullable: false, trim: true }), }; }; // #endregion Schema + + // #region Lifecycle + async _preCreate() { + if (this.parent.isEmbedded && this.parent.parent.type !== `geist`) { + ui.notifications.error(localizer( + `RipCrypt.notifs.error.invalid-parent-document`, + { itemType: `trait`, parentType: this.parent.parent.type }, + )); + return false; + }; + }; + // #endregion + + async getFormFields() { + return []; + }; };