import { DEFAULT_AUGMENTS } from './augments.js'; // Global caches for resolved features to keep getters fast const _featureCache = new Map(); /** * Injects Ikonis defaults directly into the system configuration. */ export function registerIkonisFeatures() { if (!CONFIG.DH?.ITEM?.weaponFeatures) return; console.log("DH-Ikonis | Registering features in CONFIG..."); for (const aug of DEFAULT_AUGMENTS) { const nativeId = `ikonis-${aug.id}`; CONFIG.DH.ITEM.weaponFeatures[nativeId] = { name: `Ikonis: ${aug.name}`, img: aug.img || "systems/daggerheart/assets/icons/documents/items/chip.svg", description: aug.cost ? `
${aug.effect}
${aug.cost}
` : `${aug.effect}
`, actions: aug.actions || {}, effects: aug.effects || [] }; } console.log("DH-Ikonis | Features registered in CONFIG."); } /** * Seeds the Daggerheart Homebrew settings with Ikonis defaults if they don't exist. */ export async function seedIkonisHomebrew() { if (!game.user.isGM) return; let homebrewKey = 'Homebrew'; if (!game.settings.settings.has('daggerheart.Homebrew')) { if (game.settings.settings.has('daggerheart.homebrew')) homebrewKey = 'homebrew'; else { console.warn("DH-Ikonis | Daggerheart Homebrew setting not found."); return; } } const current = game.settings.get('daggerheart', homebrewKey) || {}; const homebrew = (typeof current.toObject === 'function') ? current.toObject() : foundry.utils.deepClone(current); console.log(`DH-Ikonis | Seeding homebrew features (key: ${homebrewKey})...`); if (!homebrew.itemFeatures) homebrew.itemFeatures = { weaponFeatures: {}, armorFeatures: {} }; if (!homebrew.itemFeatures.weaponFeatures) homebrew.itemFeatures.weaponFeatures = {}; let updates = false; const recognizedIds = DEFAULT_AUGMENTS.map(aug => `ikonis-${aug.id}`); // Purge undefined Ikonis features for (const [id, feature] of Object.entries(homebrew.itemFeatures.weaponFeatures)) { if (id.startsWith('ikonis-') && !recognizedIds.includes(id)) { console.log(`DH-Ikonis | Purging undefined feature: ${id}`); delete homebrew.itemFeatures.weaponFeatures[id]; updates = true; } } for (const aug of DEFAULT_AUGMENTS) { const nativeId = `ikonis-${aug.id}`; // Force update to ensure 16-character IDs and correct mechanical effects are synced console.log(`DH-Ikonis | Seeding/Updating feature: ${aug.name}`); let description = `${aug.effect}
`; if (aug.cost) description += `${aug.cost}
`; if (aug.precompile) description += `Precompile: ${aug.precompile}
`; homebrew.itemFeatures.weaponFeatures[nativeId] = { name: `Ikonis: ${aug.name}`, img: aug.img || "systems/daggerheart/assets/icons/documents/items/chip.svg", description: description, actions: aug.actions || {}, effects: aug.effects || [] }; updates = true; } if (updates) { await game.settings.set('daggerheart', homebrewKey, homebrew); console.log("DH-Ikonis | Default blueprints seeded into Homebrew settings."); } else { console.log("DH-Ikonis | Homebrew features are already up to date."); } } /** * Scans the Daggerheart system config for any weapon features starting with "Ikonis:". * These are treated as available augments for our slot system. */ 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 [id, feature] of Object.entries(allFeatures)) { const name = feature.label || feature.name || ""; if (name.startsWith("Ikonis:")) { let desc = feature.description || ""; // Replace common line-breaking tags with actual newlines before stripping desc = desc.replace(/<\/p>|