implement pre-loading cache for Ikonis features and override system currency settings

This commit is contained in:
CPTN Cosmo 2026-04-26 17:52:44 +02:00
parent 077d284987
commit b62824cd54
2 changed files with 96 additions and 49 deletions

View file

@ -1,4 +1,4 @@
import { patchDHWeapon, patchIkonisLogic, patchDhCharacter, DEFAULT_AUGMENTS } from './ikonis-data.js';
import { patchDHWeapon, patchIkonisLogic, patchDhCharacter, loadIkonisFeatures, DEFAULT_AUGMENTS } from './ikonis-data.js';
import { patchIkonisSheet } from './ikonis-sheet.js';
import { IkonisAugmentConfig } from './ikonis-config.js';
@ -82,27 +82,68 @@ Hooks.on('updateItem', (item, changes, options, userId) => {
});
Hooks.once('ready', async () => {
console.log("DH-Ikonis | Ready hook triggered.");
// Sync features from compendium if needed
if (game.user.isGM) {
await syncIkonisFeatures();
await overrideCurrency();
}
const actorsApi = game.system.api.models.actors || {};
const DhCharacter = actorsApi.DhCharacter || actorsApi.character;
// Load features into memory for sync getters
await loadIkonisFeatures();
// Patch Character Data Model
const DhCharacter = game.system.api?.models?.actors?.DhCharacter || CONFIG.Actor.dataModels?.character;
if (DhCharacter) {
// Apply visual injection patch
patchDhCharacter(DhCharacter);
Object.defineProperty(DhCharacter.prototype, 'primaryWeapon', {
get: function() { return this.parent.items.find(x => x.type === 'weapon' && x.system.equipped && !x.system.secondary); },
configurable: true
});
Object.defineProperty(DhCharacter.prototype, 'secondaryWeapon', {
get: function() { return this.parent.items.find(x => x.type === 'weapon' && x.system.equipped && x.system.secondary); },
configurable: true
});
} else {
console.warn("DH-Ikonis | Could not find DhCharacter class for patching visual features.");
}
// Force re-render of open character sheets to show newly patched features
Object.values(ui.windows).forEach(w => {
if (w.document?.type === 'character') w.render(true);
});
});
async function overrideCurrency() {
const homebrew = game.settings.get('daggerheart', 'homebrew');
// Only override if not already set to Quantum to avoid spamming updates
if (homebrew.currency?.title !== "Quantum") {
console.log("DH-Ikonis | Overriding currency settings to Quantum...");
// We must work with a plain object for settings updates
const newHomebrew = homebrew.toObject();
newHomebrew.currency = {
title: "Quantum",
coins: {
enabled: true,
label: "Quantum",
icon: "fa-solid fa-atom"
},
handfuls: {
enabled: false,
label: "Handfuls",
icon: "fa-solid fa-coins"
},
bags: {
enabled: false,
label: "Bags",
icon: "fa-solid fa-sack"
},
chests: {
enabled: false,
label: "Chests",
icon: "fa-solid fa-treasure-chest"
}
};
await game.settings.set('daggerheart', 'homebrew', newHomebrew);
}
}
async function syncIkonisFeatures() {
const pack = game.packs.get("dh-ikonis.ikonis-features");
if (!pack) return;