implement feature caching and inject Ikonis augment effects into actor calculations
This commit is contained in:
parent
810afba204
commit
7c52be79c3
2 changed files with 81 additions and 22 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { patchDHWeapon, DEFAULT_AUGMENTS } from './ikonis-data.js';
|
||||
import { patchDHWeapon, patchIkonisLogic, DEFAULT_AUGMENTS } from './ikonis-data.js';
|
||||
import { patchIkonisSheet } from './ikonis-sheet.js';
|
||||
import { IkonisAugmentConfig } from './ikonis-config.js';
|
||||
|
||||
|
|
@ -53,17 +53,35 @@ Hooks.once('init', () => {
|
|||
|
||||
Hooks.on('setup', () => {
|
||||
patchDHWeapon();
|
||||
patchIkonisLogic();
|
||||
patchIkonisSheet();
|
||||
});
|
||||
|
||||
// Watch for Tier/Ikonis changes and force a refresh
|
||||
Hooks.on('updateItem', (item, changes, options, userId) => {
|
||||
if (foundry.utils.hasProperty(changes, "system.tier") || foundry.utils.hasProperty(changes, "flags.dh-ikonis")) {
|
||||
Object.values(item.apps || {}).forEach(app => { app.render?.(true); });
|
||||
const isTierUpdate = foundry.utils.hasProperty(changes, "system.tier");
|
||||
const isIkonisUpdate = foundry.utils.hasProperty(changes, "flags.dh-ikonis");
|
||||
const isEquipUpdate = foundry.utils.hasProperty(changes, "system.equipped");
|
||||
|
||||
if (isTierUpdate || isIkonisUpdate || isEquipUpdate) {
|
||||
console.log(`DH-Ikonis | Update detected for ${item.name}.`);
|
||||
|
||||
// Refresh sheets
|
||||
Object.values(item.apps || {}).forEach(app => {
|
||||
if (app.render) app.render(true);
|
||||
});
|
||||
|
||||
// If it's on an actor, we need to force the actor to recalculate its effects
|
||||
if (item.actor) {
|
||||
console.log(`DH-Ikonis | Resetting actor data for ${item.actor.name}...`);
|
||||
item.actor.prepareData();
|
||||
// Force sheet re-render for the actor
|
||||
item.actor.sheet?.render(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Hooks.once('ready', async () => {
|
||||
// Perform Auto-Sync for Features
|
||||
if (game.user.isGM) {
|
||||
await syncIkonisFeatures();
|
||||
}
|
||||
|
|
@ -82,41 +100,26 @@ Hooks.once('ready', async () => {
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Automatically links augments in the settings to features in the compendium by name.
|
||||
*/
|
||||
async function syncIkonisFeatures() {
|
||||
const pack = game.packs.get("dh-ikonis.ikonis-features");
|
||||
if (!pack) return;
|
||||
|
||||
const index = await pack.getIndex();
|
||||
const currentAugs = game.settings.get(MODULE_ID, 'augmentsList') || [];
|
||||
let updates = false;
|
||||
|
||||
// 1. Sync Augments
|
||||
const newAugs = currentAugs.map(aug => {
|
||||
if (!aug.featureUuid) {
|
||||
const match = index.find(i => i.name === aug.name);
|
||||
if (match) {
|
||||
aug.featureUuid = match.uuid;
|
||||
updates = true;
|
||||
console.log(`DH-Ikonis | Auto-linked augment [${aug.name}] to compendium feature.`);
|
||||
}
|
||||
}
|
||||
return aug;
|
||||
});
|
||||
|
||||
if (updates) {
|
||||
await game.settings.set(MODULE_ID, 'augmentsList', newAugs);
|
||||
}
|
||||
|
||||
// 2. Sync Bonded Feature
|
||||
if (updates) await game.settings.set(MODULE_ID, 'augmentsList', newAugs);
|
||||
let bondedUuid = game.settings.get(MODULE_ID, 'defaultBondedUuid');
|
||||
if (!bondedUuid) {
|
||||
const bondMatch = index.find(i => i.name === "Ikonis Bond");
|
||||
if (bondMatch) {
|
||||
await game.settings.set(MODULE_ID, 'defaultBondedUuid', bondMatch.uuid);
|
||||
console.log(`DH-Ikonis | Auto-linked default Bonded feature.`);
|
||||
}
|
||||
if (bondMatch) await game.settings.set(MODULE_ID, 'defaultBondedUuid', bondMatch.uuid);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue