From 153f48a7c3c97ecc7bf59348e3cd41cc5ca332bf Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 21 Apr 2026 17:42:32 -0600 Subject: [PATCH] Improve cloning-detection in the preCreate hook so that we can ignore duplications for creating attribute items --- module/data/Actor/player.mjs | 2 +- module/documents/Actor.mjs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/module/data/Actor/player.mjs b/module/data/Actor/player.mjs index 16308c3..a2b2df4 100644 --- a/module/data/Actor/player.mjs +++ b/module/data/Actor/player.mjs @@ -42,7 +42,7 @@ export class PlayerData extends foundry.abstract.TypeDataModel { // Assign the default items from the world setting if required const items = this.parent._source.items; - if (items == null || items.length === 0) { + if (items.length === 0 && !options.cloning) { const defaults = game.settings.get(__ID__, `actorDefaultAttributes`) ?? []; this.parent.updateSource({ items: defaults }); }; diff --git a/module/documents/Actor.mjs b/module/documents/Actor.mjs index 98988ce..af03605 100644 --- a/module/documents/Actor.mjs +++ b/module/documents/Actor.mjs @@ -15,6 +15,16 @@ export class TAFActor extends Actor { super._onEmbeddedDocumentChange(...args); this.#sortedTypes = null; }; + + /** + * This override allows the _preCreate operations to see whether the actor is + * being cloned or created from nothing. This allows for easy one-time operations + * that should be performed during Actor creation but not duplication to occur. + */ + clone(data, context) { + context.cloning = true; + return super.clone(data, context); + }; // #endregion Lifecycle // #region Token Attributes