migrate ikonis feature storage to a local actor cache and patch getEmbeddedDocument for virtual feature resolution
This commit is contained in:
parent
5ac4a0af17
commit
40cf69e061
1 changed files with 20 additions and 10 deletions
|
|
@ -164,26 +164,23 @@ export function patchDhCharacter(DhCharacter) {
|
||||||
const featureClone = feature.clone({ parent: this.parent }, { keepId: true });
|
const featureClone = feature.clone({ parent: this.parent }, { keepId: true });
|
||||||
|
|
||||||
// Set system type to 'ikonis' so the original sheetLists ignores it
|
// Set system type to 'ikonis' so the original sheetLists ignores it
|
||||||
// This prevents features from appearing twice on the sheet
|
|
||||||
featureClone.system.type = "ikonis";
|
featureClone.system.type = "ikonis";
|
||||||
|
|
||||||
// Use unique ID per weapon to prevent overwriting same-tech on different weapons
|
// Use unique ID per weapon
|
||||||
const virtualId = `ikonis-${item.id}-${feature.id}`;
|
const virtualId = `ikonis-${item.id}-${feature.id}`;
|
||||||
Object.defineProperty(featureClone, "id", { value: virtualId, enumerable: true });
|
Object.defineProperty(featureClone, "id", { value: virtualId, enumerable: true });
|
||||||
|
|
||||||
// ALWAYS inject into memory collection so it's resolvable
|
// Store in a local cache on the actor for fast lookup by our patch
|
||||||
this.parent.items.set(virtualId, featureClone);
|
if (!this.parent._ikonisCache) this.parent._ikonisCache = new Map();
|
||||||
|
this.parent._ikonisCache.set(virtualId, featureClone);
|
||||||
|
|
||||||
// ONLY add to the sheet list if the weapon is equipped
|
|
||||||
if (isEquipped) {
|
if (isEquipped) {
|
||||||
ikonisFeatures.push(featureClone);
|
ikonisFeatures.push(featureClone);
|
||||||
console.log(`DH-Ikonis | Resolved ${type} feature: ${feature.name} for ${item.name} (Equipped)`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (bondedUuid) processFeature(bondedUuid, "bonded");
|
if (bondedUuid) processFeature(bondedUuid, "bonded");
|
||||||
|
|
||||||
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));
|
||||||
|
|
@ -193,9 +190,6 @@ export function patchDhCharacter(DhCharacter) {
|
||||||
|
|
||||||
if (ikonisFeatures.length > 0) {
|
if (ikonisFeatures.length > 0) {
|
||||||
const uniqueFeatures = Array.from(new Set(ikonisFeatures));
|
const uniqueFeatures = Array.from(new Set(ikonisFeatures));
|
||||||
console.log(`DH-Ikonis | Injecting ${uniqueFeatures.length} features for ${this.parent.name}`);
|
|
||||||
|
|
||||||
// Nest within features so they show up on the Features tab
|
|
||||||
if (!lists.features) lists.features = {};
|
if (!lists.features) lists.features = {};
|
||||||
lists.features["Ikonis Augments"] = {
|
lists.features["Ikonis Augments"] = {
|
||||||
title: "Ikonis Augments",
|
title: "Ikonis Augments",
|
||||||
|
|
@ -208,6 +202,22 @@ export function patchDhCharacter(DhCharacter) {
|
||||||
},
|
},
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Patch getEmbeddedDocument to resolve our virtual features
|
||||||
|
// This is the most compatible way to make fromUuid work without patching it directly
|
||||||
|
const originalGetEmbedded = Actor.prototype.getEmbeddedDocument;
|
||||||
|
Actor.prototype.getEmbeddedDocument = function(embeddedName, id, options) {
|
||||||
|
if (embeddedName === "Item" && typeof id === "string" && id.startsWith("ikonis-")) {
|
||||||
|
// First check the cache we populated during sheetLists
|
||||||
|
if (this._ikonisCache?.has(id)) return this._ikonisCache.get(id);
|
||||||
|
|
||||||
|
// If not in cache, trigger the getter to populate it
|
||||||
|
// Accessing system.sheetLists will run our patch above
|
||||||
|
const lists = this.system.sheetLists;
|
||||||
|
if (this._ikonisCache?.has(id)) return this._ikonisCache.get(id);
|
||||||
|
}
|
||||||
|
return originalGetEmbedded.call(this, embeddedName, id, options);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function patchDHWeapon() {
|
export function patchDHWeapon() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue