simplify augment system to resolve features dynamically via native configuration instead of manual synchronization
This commit is contained in:
parent
01fc302b43
commit
e21e66d6c2
4 changed files with 40 additions and 221 deletions
130
scripts/main.js
130
scripts/main.js
|
|
@ -1,28 +1,12 @@
|
|||
import { patchDHWeapon, patchIkonisLogic, patchDhCharacter, loadIkonisFeatures, DEFAULT_AUGMENTS } from './ikonis-data.js';
|
||||
import { patchDHWeapon, patchIkonisLogic, patchDhCharacter } from './ikonis-data.js';
|
||||
import { patchIkonisSheet } from './ikonis-sheet.js';
|
||||
import { IkonisAugmentConfig } from './ikonis-config.js';
|
||||
|
||||
const MODULE_ID = 'dh-ikonis';
|
||||
|
||||
Hooks.once('init', () => {
|
||||
console.log(`${MODULE_ID} | Initializing Ikonis Module`);
|
||||
|
||||
// --- Settings Registration ---
|
||||
|
||||
game.settings.register(MODULE_ID, "augmentsList", {
|
||||
scope: "world",
|
||||
config: false,
|
||||
type: Array,
|
||||
default: DEFAULT_AUGMENTS
|
||||
});
|
||||
|
||||
game.settings.register(MODULE_ID, "defaultBondedUuid", {
|
||||
scope: "world",
|
||||
config: false,
|
||||
type: String,
|
||||
default: ""
|
||||
});
|
||||
|
||||
// --- Slot Settings ---
|
||||
[1, 2, 3, 4].forEach(tier => {
|
||||
game.settings.register(MODULE_ID, `slotsTier${tier}`, {
|
||||
name: `Slots at Tier ${tier}`,
|
||||
|
|
@ -54,21 +38,6 @@ Hooks.once('init', () => {
|
|||
default: true
|
||||
});
|
||||
|
||||
// Configuration Menu
|
||||
game.settings.registerMenu(MODULE_ID, "augmentsMenu", {
|
||||
name: "Manage Ikonis Augments",
|
||||
label: "Open Augment Manager",
|
||||
hint: "Add, remove, or edit the global list of Ikonis augments.",
|
||||
icon: "fa-solid fa-microchip",
|
||||
type: class extends foundry.applications.api.ApplicationV2 {
|
||||
render() {
|
||||
IkonisAugmentConfig.open();
|
||||
return this;
|
||||
}
|
||||
},
|
||||
restricted: true
|
||||
});
|
||||
|
||||
const DhCharacter = CONFIG.Actor.dataModels?.character;
|
||||
if (DhCharacter) patchDhCharacter(DhCharacter);
|
||||
});
|
||||
|
|
@ -76,7 +45,6 @@ Hooks.once('init', () => {
|
|||
Hooks.on('setup', () => {
|
||||
// Damage Type Rename
|
||||
if (game.settings.get(MODULE_ID, "enableTechRename")) {
|
||||
console.log(`${MODULE_ID} | Renaming Magical damage to Tech...`);
|
||||
const mag = CONFIG.DH?.GENERAL?.damageTypes?.magical;
|
||||
if (mag) {
|
||||
mag.label = "Tech";
|
||||
|
|
@ -88,55 +56,17 @@ Hooks.on('setup', () => {
|
|||
patchDHWeapon();
|
||||
patchIkonisLogic();
|
||||
patchIkonisSheet();
|
||||
|
||||
const DhCharacter = CONFIG.Actor.dataModels?.character;
|
||||
if (DhCharacter) patchDhCharacter(DhCharacter);
|
||||
});
|
||||
|
||||
Hooks.on('updateItem', (item, changes, options, userId) => {
|
||||
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) {
|
||||
Object.values(item.apps || {}).forEach(app => {
|
||||
if (app.render) app.render(true);
|
||||
});
|
||||
|
||||
if (item.actor) {
|
||||
item.actor.prepareData();
|
||||
item.actor.sheet?.render(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Hooks.once('ready', async () => {
|
||||
console.log(`${MODULE_ID} | Ready hook triggered.`);
|
||||
console.log(`${MODULE_ID} | Ready.`);
|
||||
|
||||
if (game.user.isGM) {
|
||||
await syncIkonisFeatures();
|
||||
|
||||
// Currency Override
|
||||
if (game.settings.get(MODULE_ID, "enableCurrencyOverride")) {
|
||||
await overrideCurrency();
|
||||
}
|
||||
|
||||
// Sync to Native Homebrew
|
||||
await syncIkonisToHomebrew();
|
||||
if (game.user.isGM && game.settings.get(MODULE_ID, "enableCurrencyOverride")) {
|
||||
await overrideCurrency();
|
||||
}
|
||||
|
||||
await loadIkonisFeatures();
|
||||
|
||||
const DhCharacter = game.system.api?.models?.actors?.DhCharacter || CONFIG.Actor.dataModels?.character;
|
||||
if (DhCharacter) patchDhCharacter(DhCharacter);
|
||||
|
||||
Object.values(ui.windows).forEach(w => {
|
||||
if (w.document?.type === 'character') w.render(true);
|
||||
});
|
||||
|
||||
if (game.user.isGM) {
|
||||
ui.notifications.info("DH-Ikonis | Ikonis Module initialized.");
|
||||
}
|
||||
});
|
||||
|
||||
async function overrideCurrency() {
|
||||
|
|
@ -147,45 +77,17 @@ async function overrideCurrency() {
|
|||
}
|
||||
|
||||
const homebrew = game.settings.get('daggerheart', key);
|
||||
if (!homebrew) return;
|
||||
if (!homebrew || homebrew.currency?.title === "Quantum") return;
|
||||
|
||||
if (homebrew.currency?.title !== "Quantum") {
|
||||
console.log(`${MODULE_ID} | Overriding currency settings to Quantum...`);
|
||||
const newHomebrew = (typeof homebrew.toObject === 'function') ? homebrew.toObject() : foundry.utils.deepClone(homebrew);
|
||||
|
||||
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" }
|
||||
};
|
||||
const newHomebrew = (typeof homebrew.toObject === 'function') ? homebrew.toObject() : foundry.utils.deepClone(homebrew);
|
||||
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', key, newHomebrew);
|
||||
ui.notifications.info("DH-Ikonis | Currency system updated to Quantum Credits.");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
return aug;
|
||||
});
|
||||
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);
|
||||
}
|
||||
await game.settings.set('daggerheart', key, newHomebrew);
|
||||
console.log(`${MODULE_ID} | Currency system updated to Quantum Credits.`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue