From f9c1eceb6fd205f52d45522df8ebd3317ed301fd Mon Sep 17 00:00:00 2001 From: cosmo Date: Sun, 26 Apr 2026 18:14:07 +0200 Subject: [PATCH] implement virtual UUIDs and patch fromUuid resolvers for Ikonis features --- scripts/ikonis-data.js | 47 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/scripts/ikonis-data.js b/scripts/ikonis-data.js index 82d8c3a..90faafe 100644 --- a/scripts/ikonis-data.js +++ b/scripts/ikonis-data.js @@ -161,10 +161,13 @@ export function patchDhCharacter(DhCharacter) { if (bondedUuid) { const feature = _featureCache.get(bondedUuid) || fromUuidSync(bondedUuid); if (feature) { - // Use constructor and override UUID so system can find it for descriptions + // Use constructor and virtual UUID so system can resolve the clone const ItemClass = getDocumentClass("Item"); const featureClone = new ItemClass(feature.toObject(), { parent: this.parent }); - Object.defineProperty(featureClone, "uuid", { value: feature.uuid, enumerable: false }); + Object.defineProperty(featureClone, "uuid", { + value: `Actor.${this.parent.id}.Ikonis.${feature.id}`, + enumerable: false + }); ikonisFeatures.push(featureClone); console.log(`DH-Ikonis | Resolved bonded feature: ${feature.name}`); } @@ -181,10 +184,13 @@ export function patchDhCharacter(DhCharacter) { const feature = _featureCache.get(aug.featureUuid) || fromUuidSync(aug.featureUuid); if (feature) { - // Use constructor and override UUID so system can find it for descriptions + // Use constructor and virtual UUID so system can resolve the clone const ItemClass = getDocumentClass("Item"); const featureClone = new ItemClass(feature.toObject(), { parent: this.parent }); - Object.defineProperty(featureClone, "uuid", { value: feature.uuid, enumerable: false }); + Object.defineProperty(featureClone, "uuid", { + value: `Actor.${this.parent.id}.Ikonis.${feature.id}`, + enumerable: false + }); ikonisFeatures.push(featureClone); console.log(`DH-Ikonis | Resolved augment feature: ${feature.name}`); } @@ -211,3 +217,36 @@ export function patchDhCharacter(DhCharacter) { export function patchDHWeapon() { // Future: Add damage type override logic here } + +// Patch fromUuid and fromUuidSync to handle our virtual Ikonis UUIDs +// This allows the system to resolve our memory-only clones correctly +const _fromUuid = foundry.utils.fromUuid; +const _fromUuidSync = foundry.utils.fromUuidSync; + +foundry.utils.fromUuid = async function(uuid, options) { + if (typeof uuid === "string" && uuid.includes(".Ikonis.")) { + const parts = uuid.split("."); + const actor = await _fromUuid(`Actor.${parts[1]}`, options); + if (actor) { + // Access the character data model where sheetLists resides + const augments = actor.system.sheetLists?.features?.["Ikonis Augments"]; + const feature = augments?.find(f => f.id === parts[3]); + if (feature) return feature; + } + } + return _fromUuid(uuid, options); +}; + +foundry.utils.fromUuidSync = function(uuid, options) { + if (typeof uuid === "string" && uuid.includes(".Ikonis.")) { + const parts = uuid.split("."); + const actor = _fromUuidSync(`Actor.${parts[1]}`, options); + if (actor) { + // Access the character data model where sheetLists resides + const augments = actor.system.sheetLists?.features?.["Ikonis Augments"]; + const feature = augments?.find(f => f.id === parts[3]); + if (feature) return feature; + } + } + return _fromUuidSync(uuid, options); +};