add DhCharacter patch to inject Ikonis augment features into character sheet UI lists

This commit is contained in:
CPTN Cosmo 2026-04-26 17:48:08 +02:00
parent 7c52be79c3
commit 077d284987
2 changed files with 62 additions and 11 deletions

View file

@ -10,8 +10,9 @@ export const DEFAULT_AUGMENTS = [
{ id: "weight", name: "Gravity Plate", effect: "Weapon is Heavy (more damage)", cost: "4 Lead", precompile: 2 }
];
// Global cache for resolved features to keep generators fast
// Global caches for resolved features to keep getters fast
const _featureCache = new Map();
const _itemObjectCache = new Map();
export function getAugments() {
return game.settings.get('dh-ikonis', 'augmentsList') || DEFAULT_AUGMENTS;
@ -63,10 +64,8 @@ export function patchIkonisLogic() {
// 1. Patch allApplicableEffects to inject Active Effects from Augments
const originalAllEffects = Actor.prototype.allApplicableEffects;
Actor.prototype.allApplicableEffects = function* () {
// Yield standard effects
yield* originalAllEffects.call(this);
// Inject effects from equipped Ikonis weapons
for (const item of this.items) {
if (item.type !== 'weapon' || !item.system.equipped) continue;
@ -77,18 +76,14 @@ export function patchIkonisLogic() {
const aug = allAugs.find(a => String(a.id) === String(id));
if (!aug?.featureUuid) continue;
// We use sync lookup here because generators must be synchronous.
// The features should already be in the cache from the sheet rendering.
const feature = fromUuidSync(aug.featureUuid);
if (!feature || !feature.effects) continue;
for (const effect of feature.effects) {
// Only yield transfer effects (those meant to apply to the actor)
if (effect.transfer) yield effect;
}
}
// Also check Bonded feature
const bondedUuid = item.getFlag('dh-ikonis', 'bondedFeatureUuid');
if (bondedUuid) {
const feature = fromUuidSync(bondedUuid);
@ -100,11 +95,64 @@ export function patchIkonisLogic() {
}
}
};
}
console.log("DH-Ikonis | Actor patches complete.");
/**
* Patches the Character Data Model to show features in the UI lists.
*/
export function patchDhCharacter(DhCharacter) {
console.log("DH-Ikonis | Patching DhCharacter data model for UI lists...");
const descriptor = Object.getOwnPropertyDescriptor(DhCharacter.prototype, 'sheetLists');
if (!descriptor) return;
const originalSheetLists = descriptor.get;
Object.defineProperty(DhCharacter.prototype, 'sheetLists', {
get: function() {
const lists = originalSheetLists.call(this);
const ikonisFeatures = [];
// Find equipped Ikonis weapons
for (const item of this.parent.items) {
if (item.type !== 'weapon' || !item.system.equipped) continue;
const installedIds = item.getFlag('dh-ikonis', 'installedAugments') || [];
const allAugs = getAugments();
const bondedUuid = item.getFlag('dh-ikonis', 'bondedFeatureUuid');
// Collect Bonded Feature
if (bondedUuid) {
const feature = fromUuidSync(bondedUuid);
if (feature) ikonisFeatures.push(feature);
}
// Collect Augments
for (const id of installedIds) {
const aug = allAugs.find(a => String(a.id) === String(id));
if (!aug?.featureUuid) continue;
const feature = fromUuidSync(aug.featureUuid);
if (feature) ikonisFeatures.push(feature);
}
}
if (ikonisFeatures.length > 0) {
// Ensure unique features
const uniqueFeatures = Array.from(new Set(ikonisFeatures));
lists.ikonis = {
title: "Ikonis Augments",
type: "ikonis",
values: uniqueFeatures
};
}
return lists;
},
configurable: true
});
}
export function patchDHWeapon() {
console.log("DH-Ikonis | Patching DH Weapon system...");
// Future: Add damage type override logic here
}