add auto-sync for Ikonis features and implement documentation via README.md

This commit is contained in:
CPTN Cosmo 2026-04-26 17:17:00 +02:00
parent 7bffeacaac
commit 5e77008c23
3 changed files with 111 additions and 32 deletions

View file

@ -35,7 +35,7 @@ Hooks.once('init', () => {
});
});
// Configuration Menu (V2 compliant)
// Configuration Menu
game.settings.registerMenu(MODULE_ID, "augmentsMenu", {
name: "Manage Ikonis Augments",
label: "Open Augment Manager",
@ -56,37 +56,67 @@ Hooks.on('setup', () => {
patchIkonisSheet();
});
// Watch for Tier changes and force a refresh
Hooks.on('updateItem', (item, changes, options, userId) => {
// Check if system data or flags were updated
const isTierUpdate = foundry.utils.hasProperty(changes, "system.tier");
const isFlagUpdate = foundry.utils.hasProperty(changes, "flags.dh-ikonis");
if (isTierUpdate || isFlagUpdate) {
console.log(`DH-Ikonis | Update detected for ${item.name}. Re-rendering sheets...`);
// Find all active sheets for this item and force a full render
Object.values(item.apps || {}).forEach(app => {
if (app.render) app.render(true);
});
if (foundry.utils.hasProperty(changes, "system.tier") || foundry.utils.hasProperty(changes, "flags.dh-ikonis")) {
Object.values(item.apps || {}).forEach(app => { app.render?.(true); });
}
});
Hooks.once('ready', () => {
Hooks.once('ready', async () => {
// Perform Auto-Sync for Features
if (game.user.isGM) {
await syncIkonisFeatures();
}
const actorsApi = game.system.api.models.actors || {};
const DhCharacter = actorsApi.DhCharacter || actorsApi.DHCharacter || actorsApi.character;
if (DhCharacter) {
Object.defineProperty(DhCharacter.prototype, 'primaryWeapon', {
get: function() {
return this.parent.items.find(x => x.type === 'weapon' && x.system.equipped && !x.system.secondary);
},
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);
},
get: function() { return this.parent.items.find(x => x.type === 'weapon' && x.system.equipped && x.system.secondary); },
configurable: true
});
}
});
/**
* 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
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.`);
}
}
}