simplify augment system to resolve features dynamically via native configuration instead of manual synchronization

This commit is contained in:
CPTN Cosmo 2026-04-26 19:00:08 +02:00
parent 01fc302b43
commit e21e66d6c2
4 changed files with 40 additions and 221 deletions

View file

@ -13,43 +13,29 @@ export const DEFAULT_AUGMENTS = [
// Global caches for resolved features to keep getters fast
const _featureCache = new Map();
export function getAugments() {
return game.settings.get('dh-ikonis', 'augmentsList') || DEFAULT_AUGMENTS;
}
/**
* Pre-loads all features from the compendium into memory.
* This is necessary because sheetLists getter is synchronous.
* Scans the Daggerheart system config for any weapon features starting with "Ikonis:".
* These are treated as available augments for our slot system.
*/
export async function loadIkonisFeatures() {
console.log("DH-Ikonis | Pre-loading features into cache...");
const allAugs = getAugments();
const bondedUuid = game.settings.get('dh-ikonis', 'defaultBondedUuid');
const uuids = new Set(allAugs.map(a => a.featureUuid).filter(Boolean));
if (bondedUuid) uuids.add(bondedUuid);
export function getAugments() {
// We get the resolved features from CONFIG.DH.ITEM which includes system + homebrew
const allFeatures = CONFIG.DH.ITEM.allWeaponFeatures() || {};
const augments = [];
for (const uuid of uuids) {
try {
const item = await fromUuid(uuid);
if (item) {
_featureCache.set(uuid, item);
console.log(`DH-Ikonis | Cached feature: ${item.name} [${uuid}]`);
}
} catch (e) {
console.error(`DH-Ikonis | Failed to load feature ${uuid}`, e);
for (const [id, feature] of Object.entries(allFeatures)) {
const name = feature.label || feature.name || "";
if (name.startsWith("Ikonis:")) {
augments.push({
id: id, // This is the native system key (e.g., "force" or "ikonis-guard")
name: name.replace("Ikonis:", "").trim(),
fullName: name,
effect: feature.description ? feature.description.replace(/<[^>]*>?/gm, '').substring(0, 100) + "..." : "Native Feature",
cost: "Homebrew"
});
}
}
console.log(`DH-Ikonis | Cache size: ${_featureCache.size}`);
}
/**
* Robust feature fetching. Tries cache first, then async fromUuid.
*/
export async function getAttachedFeature(uuid) {
if (!uuid) return null;
if (_featureCache.has(uuid)) return _featureCache.get(uuid);
return await fromUuid(uuid);
return augments;
}
export function getSlotCount(item) {
@ -68,59 +54,11 @@ export function getSlotCount(item) {
}
}
/**
* Synchronizes Ikonis Augments into the Daggerheart Homebrew settings.
* This makes them "Real" Weapon Features to the system.
*/
export async function syncIkonisToHomebrew() {
if (!game.user.isGM) return;
const MODULE_ID = 'dh-ikonis';
const homebrewKey = game.settings.settings.has('daggerheart.Homebrew') ? 'Homebrew' : 'homebrew';
const homebrew = game.settings.get('daggerheart', homebrewKey);
if (!homebrew.itemFeatures) homebrew.itemFeatures = { weaponFeatures: {}, armorFeatures: {} };
if (!homebrew.itemFeatures.weaponFeatures) homebrew.itemFeatures.weaponFeatures = {};
let updates = false;
const allAugments = getAugments();
for (const aug of allAugments) {
const feature = _featureCache.get(aug.featureUuid) || await fromUuid(aug.featureUuid);
if (feature && !homebrew.itemFeatures.weaponFeatures[aug.id]) {
console.log(`DH-Ikonis | Registering ${aug.name} as native weapon feature...`);
// Format actions for the system's Homebrew model
const actions = {};
if (feature.system.actions) {
for (const [id, action] of Object.entries(feature.system.actions)) {
actions[id] = action.toObject();
}
}
homebrew.itemFeatures.weaponFeatures[aug.id] = {
name: aug.name,
img: aug.img || feature.img,
description: feature.system.description,
actions: actions,
effects: Array.from(feature.effects || []).map(e => e.toObject())
};
updates = true;
}
}
if (updates) {
await game.settings.set('daggerheart', homebrewKey, homebrew);
console.log("DH-Ikonis | Homebrew settings synchronized.");
}
}
/**
* Patches the system's weapon data preparation to handle slot counts.
*/
export function patchIkonisLogic() {
// We no longer need to patch Actor.allApplicableEffects
// because the system handles native weapon features automatically.
// Current slot logic is handled via getSlotCount in the sheet context
}
/**