From b16efc5373fa0eb7806293d18620ee9350a645b0 Mon Sep 17 00:00:00 2001 From: cosmo Date: Sun, 26 Apr 2026 20:01:57 +0200 Subject: [PATCH] refactor: update Bonded feature identification to support multiple IDs and improve augment slot calculation logic --- scripts/ikonis-sheet.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/scripts/ikonis-sheet.js b/scripts/ikonis-sheet.js index 3c26117..519c985 100644 --- a/scripts/ikonis-sheet.js +++ b/scripts/ikonis-sheet.js @@ -48,13 +48,15 @@ export function patchIkonisSheet() { const processedAugments = []; let bondedFeature = null; - // Search for "Ikonis: Bonded" globally + // Identify "Bonded" features by name const allNativeFeatures = CONFIG.DH.ITEM.allWeaponFeatures() || {}; - const bondedId = Object.keys(allNativeFeatures).find(k => allNativeFeatures[k].name === "Ikonis: Bonded"); + const bondedIds = Object.keys(allNativeFeatures).filter(k => allNativeFeatures[k].name === "Ikonis: Bonded"); - // Auto-install if missing - if (bondedId && !weaponFeatures.some(f => f.value === bondedId)) { + // Auto-install if missing (check by name/presence of any bonded ID) + const hasBonded = weaponFeatures.some(f => bondedIds.includes(f.value)); + if (bondedIds.length > 0 && !hasBonded) { console.log(`DH-Ikonis | Auto-installing Bonded feature on ${doc.name}`); + const bondedId = bondedIds.includes("ikonis-bonded") ? "ikonis-bonded" : bondedIds[0]; const newFeatures = [...weaponFeatures, { value: bondedId }]; doc.update({ "system.weaponFeatures": newFeatures }); } @@ -63,10 +65,10 @@ export function patchIkonisSheet() { const nativeId = featureRef.value; // Special handling for Bonded - if (nativeId === bondedId) { - const feature = allNativeFeatures[bondedId]; + if (bondedIds.includes(nativeId)) { + const feature = allNativeFeatures[nativeId]; bondedFeature = { - id: bondedId, + id: nativeId, name: "Bonded", fullName: feature.name, effect: feature.description ? feature.description.replace(/<[^>]*>?/gm, '').substring(0, 100) + "..." : "Primary module", @@ -114,11 +116,16 @@ export function patchIkonisSheet() { Weapon.prototype._onAddAugment = async function(event, target) { const weaponFeatures = this.document.system.weaponFeatures || []; const allAugments = getAugments(); + const augmentIds = allAugments.map(a => a.id); - // Exclude Bonded from slot count + // Identify all features that are recognized as augments (and NOT "Bonded") const allNativeFeatures = CONFIG.DH.ITEM.allWeaponFeatures() || {}; - const bondedId = Object.keys(allNativeFeatures).find(k => allNativeFeatures[k].name === "Ikonis: Bonded"); - const usedSlotsCount = weaponFeatures.filter(f => f.value !== bondedId).length; + const bondedIds = Object.keys(allNativeFeatures).filter(k => allNativeFeatures[k].name === "Ikonis: Bonded"); + + const usedSlotsCount = weaponFeatures.filter(f => { + if (bondedIds.includes(f.value)) return false; + return augmentIds.includes(f.value); + }).length; const maxSlots = getSlotCount(this.document); if (usedSlotsCount >= maxSlots) {