122 lines
3.9 KiB
JavaScript
122 lines
3.9 KiB
JavaScript
import { patchDHWeapon, DEFAULT_AUGMENTS } 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`);
|
|
|
|
// Global Augments List
|
|
game.settings.register(MODULE_ID, "augmentsList", {
|
|
scope: "world",
|
|
config: false,
|
|
type: Array,
|
|
default: DEFAULT_AUGMENTS
|
|
});
|
|
|
|
// Default Bonded Feature
|
|
game.settings.register(MODULE_ID, "defaultBondedUuid", {
|
|
scope: "world",
|
|
config: false,
|
|
type: String,
|
|
default: ""
|
|
});
|
|
|
|
// Slot Scaling for Tiers 1, 2, 3, 4
|
|
[1, 2, 3, 4].forEach(tier => {
|
|
game.settings.register(MODULE_ID, `slotsTier${tier}`, {
|
|
name: `Slots at Tier ${tier}`,
|
|
hint: `How many augment slots a weapon gets at Tier ${tier}.`,
|
|
scope: "world",
|
|
config: true,
|
|
type: Number,
|
|
default: tier >= 2 ? 3 : 2
|
|
});
|
|
});
|
|
|
|
// 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
|
|
});
|
|
});
|
|
|
|
Hooks.on('setup', () => {
|
|
patchDHWeapon();
|
|
patchIkonisSheet();
|
|
});
|
|
|
|
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); });
|
|
}
|
|
});
|
|
|
|
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); },
|
|
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
|
|
});
|
|
}
|
|
});
|
|
|
|
/**
|
|
* 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.`);
|
|
}
|
|
}
|
|
}
|