standardize bonded and augmented feature resolution and ensure unequipped items remain resolvable in memory
This commit is contained in:
parent
0f6e29b603
commit
378d25d29f
1 changed files with 16 additions and 34 deletions
|
|
@ -153,55 +153,37 @@ export function patchDhCharacter(DhCharacter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const item of weapons) {
|
for (const item of weapons) {
|
||||||
if (!item.system.equipped) continue;
|
const isEquipped = item.system.equipped;
|
||||||
|
|
||||||
const installedIds = item.getFlag('dh-ikonis', 'installedAugments') || [];
|
const installedIds = item.getFlag('dh-ikonis', 'installedAugments') || [];
|
||||||
const bondedUuid = item.getFlag('dh-ikonis', 'bondedFeatureUuid');
|
const bondedUuid = item.getFlag('dh-ikonis', 'bondedFeatureUuid');
|
||||||
|
|
||||||
if (bondedUuid) {
|
const processFeature = (uuid, type) => {
|
||||||
const feature = _featureCache.get(bondedUuid) || fromUuidSync(bondedUuid);
|
const feature = _featureCache.get(uuid) || fromUuidSync(uuid);
|
||||||
if (feature) {
|
if (feature) {
|
||||||
// Use constructor and unique ID to inject into actor's items collection
|
// Use clone() to preserve internal action state
|
||||||
const ItemClass = getDocumentClass("Item");
|
const featureClone = feature.clone({ parent: this.parent }, { keepId: true });
|
||||||
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}`;
|
const virtualId = `ikonis-${feature.id}`;
|
||||||
Object.defineProperty(featureClone, "id", { value: virtualId, enumerable: true });
|
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);
|
this.parent.items.set(virtualId, featureClone);
|
||||||
|
|
||||||
ikonisFeatures.push(featureClone);
|
// ONLY add to the sheet list if the weapon is equipped
|
||||||
console.log(`DH-Ikonis | Resolved bonded feature: ${feature.name}`);
|
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) {
|
if (bondedUuid) processFeature(bondedUuid, "bonded");
|
||||||
console.log(`DH-Ikonis | Found ${installedIds.length} installed augments on ${item.name}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const allAugs = getAugments();
|
const allAugs = getAugments();
|
||||||
for (const id of installedIds) {
|
for (const id of installedIds) {
|
||||||
const aug = allAugs.find(a => String(a.id) === String(id));
|
const aug = allAugs.find(a => String(a.id) === String(id));
|
||||||
if (!aug?.featureUuid) continue;
|
if (aug?.featureUuid) processFeature(aug.featureUuid, "augment");
|
||||||
|
|
||||||
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}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue