inject feature clones directly into actor items collection and remove legacy UUID patching logic
This commit is contained in:
parent
1931bdb239
commit
0f6e29b603
1 changed files with 18 additions and 43 deletions
|
|
@ -161,13 +161,17 @@ 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 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 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: `Actor.${this.parent.id}.Ikonis.${feature.id}`,
|
// Override ID with unique prefix to ensure it's findable via actor.items.get()
|
||||||
enumerable: false
|
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);
|
ikonisFeatures.push(featureClone);
|
||||||
console.log(`DH-Ikonis | Resolved bonded feature: ${feature.name}`);
|
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);
|
const feature = _featureCache.get(aug.featureUuid) || fromUuidSync(aug.featureUuid);
|
||||||
if (feature) {
|
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 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: `Actor.${this.parent.id}.Ikonis.${feature.id}`,
|
// Override ID with unique prefix to ensure it's findable via actor.items.get()
|
||||||
enumerable: false
|
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);
|
ikonisFeatures.push(featureClone);
|
||||||
console.log(`DH-Ikonis | Resolved augment feature: ${feature.name}`);
|
console.log(`DH-Ikonis | Resolved augment feature: ${feature.name}`);
|
||||||
}
|
}
|
||||||
|
|
@ -219,36 +227,3 @@ 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"]?.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);
|
|
||||||
};
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue