improve feature resolution, robustness of currency settings, and initialization logic
This commit is contained in:
parent
8975a13f99
commit
e12ac35855
3 changed files with 72 additions and 18 deletions
|
|
@ -49,12 +49,24 @@ Hooks.once('init', () => {
|
|||
},
|
||||
restricted: true
|
||||
});
|
||||
|
||||
// Try to patch character model early if available
|
||||
const DhCharacter = CONFIG.Actor.dataModels?.character;
|
||||
if (DhCharacter) {
|
||||
patchDhCharacter(DhCharacter);
|
||||
}
|
||||
});
|
||||
|
||||
Hooks.on('setup', () => {
|
||||
patchDHWeapon();
|
||||
patchIkonisLogic();
|
||||
patchIkonisSheet();
|
||||
|
||||
// Ensure character model is patched if missed in init
|
||||
const DhCharacter = CONFIG.Actor.dataModels?.character;
|
||||
if (DhCharacter) {
|
||||
patchDhCharacter(DhCharacter);
|
||||
}
|
||||
});
|
||||
|
||||
// Watch for Tier/Ikonis changes and force a refresh
|
||||
|
|
@ -93,7 +105,7 @@ Hooks.once('ready', async () => {
|
|||
// Load features into memory for sync getters
|
||||
await loadIkonisFeatures();
|
||||
|
||||
// Patch Character Data Model
|
||||
// Final check for Character Data Model patch
|
||||
const DhCharacter = game.system.api?.models?.actors?.DhCharacter || CONFIG.Actor.dataModels?.character;
|
||||
if (DhCharacter) {
|
||||
patchDhCharacter(DhCharacter);
|
||||
|
|
@ -103,18 +115,35 @@ Hooks.once('ready', async () => {
|
|||
|
||||
// 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);
|
||||
if (w.document?.type === 'character') {
|
||||
console.log(`DH-Ikonis | Forcing refresh of character sheet: ${w.document.name}`);
|
||||
w.render(true);
|
||||
}
|
||||
});
|
||||
|
||||
if (game.user.isGM) {
|
||||
ui.notifications.info("DH-Ikonis | Ikonis Module initialized and features synchronized.");
|
||||
}
|
||||
});
|
||||
|
||||
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...");
|
||||
// Robust key check for Daggerheart Homebrew settings
|
||||
let key = 'Homebrew';
|
||||
if (!game.settings.settings.has('daggerheart.Homebrew')) {
|
||||
if (game.settings.settings.has('daggerheart.homebrew')) key = 'homebrew';
|
||||
else return; // Setting not found
|
||||
}
|
||||
|
||||
const homebrew = game.settings.get('daggerheart', key);
|
||||
if (!homebrew) return;
|
||||
|
||||
// Check if we already have Quantum to avoid spamming updates
|
||||
const currentTitle = homebrew.currency?.title;
|
||||
if (currentTitle !== "Quantum") {
|
||||
console.log(`DH-Ikonis | Overriding currency settings to Quantum (using key: ${key})...`);
|
||||
|
||||
// We must work with a plain object for settings updates
|
||||
const newHomebrew = homebrew.toObject();
|
||||
// Handle both DataModel and plain object
|
||||
const newHomebrew = (typeof homebrew.toObject === 'function') ? homebrew.toObject() : foundry.utils.deepClone(homebrew);
|
||||
|
||||
newHomebrew.currency = {
|
||||
title: "Quantum",
|
||||
|
|
@ -140,7 +169,8 @@ async function overrideCurrency() {
|
|||
}
|
||||
};
|
||||
|
||||
await game.settings.set('daggerheart', 'homebrew', newHomebrew);
|
||||
await game.settings.set('daggerheart', key, newHomebrew);
|
||||
ui.notifications.info("DH-Ikonis | Currency system updated to Quantum Credits.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue