inject feature clones directly into actor items collection and remove legacy UUID patching logic

This commit is contained in:
CPTN Cosmo 2026-04-26 18:18:04 +02:00
parent 1931bdb239
commit 0f6e29b603

View file

@ -161,13 +161,17 @@ export function patchDhCharacter(DhCharacter) {
if (bondedUuid) {
const feature = _featureCache.get(bondedUuid) || fromUuidSync(bondedUuid);
if (feature) {
// Use constructor and virtual UUID so system can resolve the clone
// 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 });
Object.defineProperty(featureClone, "uuid", {
value: `Actor.${this.parent.id}.Ikonis.${feature.id}`,
enumerable: false
});
// 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 bonded feature: ${feature.name}`);
}
@ -184,13 +188,17 @@ export function patchDhCharacter(DhCharacter) {
const feature = _featureCache.get(aug.featureUuid) || fromUuidSync(aug.featureUuid);
if (feature) {
// Use constructor and virtual UUID so system can resolve the clone
// 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 });
Object.defineProperty(featureClone, "uuid", {
value: `Actor.${this.parent.id}.Ikonis.${feature.id}`,
enumerable: false
});
// 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}`);
}
@ -219,36 +227,3 @@ 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"]?.values;
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"]?.values;
const feature = augments?.find(f => f.id === parts[3]);
if (feature) return feature;
}
}
return _fromUuidSync(uuid, options);
};