From 378d25d29ffaeff35fde3b6fd0f9a7eb58e4c175 Mon Sep 17 00:00:00 2001 From: cosmo Date: Sun, 26 Apr 2026 18:21:06 +0200 Subject: [PATCH] standardize bonded and augmented feature resolution and ensure unequipped items remain resolvable in memory --- scripts/ikonis-data.js | 50 ++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/scripts/ikonis-data.js b/scripts/ikonis-data.js index af50bac..a747cc0 100644 --- a/scripts/ikonis-data.js +++ b/scripts/ikonis-data.js @@ -153,55 +153,37 @@ export function patchDhCharacter(DhCharacter) { } for (const item of weapons) { - if (!item.system.equipped) continue; - + const isEquipped = item.system.equipped; const installedIds = item.getFlag('dh-ikonis', 'installedAugments') || []; const bondedUuid = item.getFlag('dh-ikonis', 'bondedFeatureUuid'); - if (bondedUuid) { - const feature = _featureCache.get(bondedUuid) || fromUuidSync(bondedUuid); + const processFeature = (uuid, type) => { + const feature = _featureCache.get(uuid) || fromUuidSync(uuid); if (feature) { - // Use constructor and unique ID to inject into actor's items collection - const ItemClass = getDocumentClass("Item"); - const featureClone = new ItemClass(feature.toObject(), { parent: this.parent }); - - // Override ID with unique prefix to ensure it's findable via actor.items.get() + // Use clone() to preserve internal action state + const featureClone = feature.clone({ parent: this.parent }, { keepId: true }); const virtualId = `ikonis-${feature.id}`; Object.defineProperty(featureClone, "id", { value: virtualId, enumerable: true }); - // Inject into the actor's in-memory items collection + // ALWAYS inject into memory collection so it's resolvable this.parent.items.set(virtualId, featureClone); - ikonisFeatures.push(featureClone); - console.log(`DH-Ikonis | Resolved bonded feature: ${feature.name}`); + // ONLY add to the sheet list if the weapon is equipped + if (isEquipped) { + ikonisFeatures.push(featureClone); + console.log(`DH-Ikonis | Resolved ${type} feature: ${feature.name} (Equipped)`); + } else { + console.log(`DH-Ikonis | Resolved ${type} feature: ${feature.name} (Unequipped - Hidden from sheet)`); + } } - } + }; - if (installedIds.length > 0) { - console.log(`DH-Ikonis | Found ${installedIds.length} installed augments on ${item.name}`); - } + if (bondedUuid) processFeature(bondedUuid, "bonded"); const allAugs = getAugments(); for (const id of installedIds) { const aug = allAugs.find(a => String(a.id) === String(id)); - if (!aug?.featureUuid) continue; - - const feature = _featureCache.get(aug.featureUuid) || fromUuidSync(aug.featureUuid); - if (feature) { - // Use constructor and unique ID to inject into actor's items collection - const ItemClass = getDocumentClass("Item"); - const featureClone = new ItemClass(feature.toObject(), { parent: this.parent }); - - // Override ID with unique prefix to ensure it's findable via actor.items.get() - const virtualId = `ikonis-${feature.id}`; - Object.defineProperty(featureClone, "id", { value: virtualId, enumerable: true }); - - // Inject into the actor's in-memory items collection - this.parent.items.set(virtualId, featureClone); - - ikonisFeatures.push(featureClone); - console.log(`DH-Ikonis | Resolved augment feature: ${feature.name}`); - } + if (aug?.featureUuid) processFeature(aug.featureUuid, "augment"); } }