implement virtual UUIDs and patch fromUuid resolvers for Ikonis features

This commit is contained in:
CPTN Cosmo 2026-04-26 18:14:07 +02:00
parent 68f8d5104c
commit f9c1eceb6f

View file

@ -161,10 +161,13 @@ export function patchDhCharacter(DhCharacter) {
if (bondedUuid) { if (bondedUuid) {
const feature = _featureCache.get(bondedUuid) || fromUuidSync(bondedUuid); const feature = _featureCache.get(bondedUuid) || fromUuidSync(bondedUuid);
if (feature) { if (feature) {
// Use constructor and override UUID so system can find it for descriptions // Use constructor and virtual UUID so system can resolve the clone
const ItemClass = getDocumentClass("Item"); const ItemClass = getDocumentClass("Item");
const featureClone = new ItemClass(feature.toObject(), { parent: this.parent }); const featureClone = new ItemClass(feature.toObject(), { parent: this.parent });
Object.defineProperty(featureClone, "uuid", { value: feature.uuid, enumerable: false }); Object.defineProperty(featureClone, "uuid", {
value: `Actor.${this.parent.id}.Ikonis.${feature.id}`,
enumerable: false
});
ikonisFeatures.push(featureClone); ikonisFeatures.push(featureClone);
console.log(`DH-Ikonis | Resolved bonded feature: ${feature.name}`); console.log(`DH-Ikonis | Resolved bonded feature: ${feature.name}`);
} }
@ -181,10 +184,13 @@ export function patchDhCharacter(DhCharacter) {
const feature = _featureCache.get(aug.featureUuid) || fromUuidSync(aug.featureUuid); const feature = _featureCache.get(aug.featureUuid) || fromUuidSync(aug.featureUuid);
if (feature) { if (feature) {
// Use constructor and override UUID so system can find it for descriptions // Use constructor and virtual UUID so system can resolve the clone
const ItemClass = getDocumentClass("Item"); const ItemClass = getDocumentClass("Item");
const featureClone = new ItemClass(feature.toObject(), { parent: this.parent }); const featureClone = new ItemClass(feature.toObject(), { parent: this.parent });
Object.defineProperty(featureClone, "uuid", { value: feature.uuid, enumerable: false }); Object.defineProperty(featureClone, "uuid", {
value: `Actor.${this.parent.id}.Ikonis.${feature.id}`,
enumerable: false
});
ikonisFeatures.push(featureClone); ikonisFeatures.push(featureClone);
console.log(`DH-Ikonis | Resolved augment feature: ${feature.name}`); console.log(`DH-Ikonis | Resolved augment feature: ${feature.name}`);
} }
@ -211,3 +217,36 @@ export function patchDhCharacter(DhCharacter) {
export function patchDHWeapon() { export function patchDHWeapon() {
// Future: Add damage type override logic here // 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"];
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"];
const feature = augments?.find(f => f.id === parts[3]);
if (feature) return feature;
}
}
return _fromUuidSync(uuid, options);
};