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
10
README.md
10
README.md
|
|
@ -6,26 +6,26 @@ The Ikonis system allows weapons to be upgraded with "Augments" (Tech) that prov
|
|||
|
||||
## Features
|
||||
|
||||
### 🛠️ The Ikonis Hardware Tab
|
||||
### The Ikonis Hardware Tab
|
||||
Every weapon sheet now includes a dedicated **Ikonis** tab.
|
||||
- **Install Tech**: Drag and drop features or select from the pre-defined list.
|
||||
- **Bonded Features**: Link a specific "Bonded" feature to the weapon that follows the user.
|
||||
- **Dynamic Slot Scaling**: The number of available augment slots automatically scales based on the weapon's **Tier** (1-4).
|
||||
|
||||
### ⚙️ Global Hardware Manager
|
||||
### Global Hardware Manager
|
||||
GMs can access the **Global Hardware Manager** in the module settings to:
|
||||
- Define the global pool of available Augments.
|
||||
- Set the cost, effect, and name of each augment.
|
||||
- Link augments to specific **Features** (items) for automated description and icon fetching.
|
||||
- Configure the default "Bonded" feature for all Ikonis weapons.
|
||||
|
||||
### 📚 Integrated Compendium
|
||||
### Integrated Compendium
|
||||
Includes an **Ikonis Features** compendium containing 10 ready-to-use augments and bond effects with custom icons and descriptions.
|
||||
|
||||
### ⚖️ Per-Tier Configuration
|
||||
### Per-Tier Configuration
|
||||
Fine-tune the balance of your game by setting exactly how many slots are provided at each tier (1, 2, 3, and 4) in the module settings.
|
||||
|
||||
### 🧪 Quantum Currency
|
||||
### Quantum Currency
|
||||
The module automatically overrides the game's homebrew settings to establish a streamlined, high-tech economy:
|
||||
- **Quantum**: Replaces traditional gold with "Quantum" credits.
|
||||
- **Unified Economy**: Disables multi-tier currency (bags, chests) in favor of a single, tech-focused value system.
|
||||
|
|
|
|||
|
|
@ -43,6 +43,15 @@ export async function loadIkonisFeatures() {
|
|||
console.log(`DH-Ikonis | Cache size: ${_featureCache.size}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Robust feature fetching. Tries cache first, then async fromUuid.
|
||||
*/
|
||||
export async function getAttachedFeature(uuid) {
|
||||
if (!uuid) return null;
|
||||
if (_featureCache.has(uuid)) return _featureCache.get(uuid);
|
||||
return await fromUuid(uuid);
|
||||
}
|
||||
|
||||
export function getSlotCount(item) {
|
||||
const flags = item.getFlag('dh-ikonis') || {};
|
||||
if (typeof flags.slotOverride === "number") return flags.slotOverride;
|
||||
|
|
@ -121,15 +130,27 @@ export function patchDhCharacter(DhCharacter) {
|
|||
|
||||
if (!this.parent) return lists;
|
||||
|
||||
for (const item of this.parent.items) {
|
||||
if (item.type !== 'weapon' || !item.system.equipped) continue;
|
||||
const weapons = this.parent.items.filter(i => i.type === 'weapon');
|
||||
if (weapons.length > 0) {
|
||||
console.log(`DH-Ikonis | Checking ${weapons.length} weapons on ${this.parent.name} for augments...`);
|
||||
}
|
||||
|
||||
for (const item of weapons) {
|
||||
if (!item.system.equipped) continue;
|
||||
|
||||
const installedIds = item.getFlag('dh-ikonis', 'installedAugments') || [];
|
||||
const bondedUuid = item.getFlag('dh-ikonis', 'bondedFeatureUuid');
|
||||
|
||||
if (bondedUuid) {
|
||||
const feature = _featureCache.get(bondedUuid) || fromUuidSync(bondedUuid);
|
||||
if (feature) ikonisFeatures.push(feature);
|
||||
if (feature) {
|
||||
ikonisFeatures.push(feature);
|
||||
console.log(`DH-Ikonis | Resolved bonded feature: ${feature.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (installedIds.length > 0) {
|
||||
console.log(`DH-Ikonis | Found ${installedIds.length} installed augments on ${item.name}`);
|
||||
}
|
||||
|
||||
const allAugs = getAugments();
|
||||
|
|
@ -138,7 +159,10 @@ export function patchDhCharacter(DhCharacter) {
|
|||
if (!aug?.featureUuid) continue;
|
||||
|
||||
const feature = _featureCache.get(aug.featureUuid) || fromUuidSync(aug.featureUuid);
|
||||
if (feature) ikonisFeatures.push(feature);
|
||||
if (feature) {
|
||||
ikonisFeatures.push(feature);
|
||||
console.log(`DH-Ikonis | Resolved augment feature: ${feature.name}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
// We must work with a plain object for settings updates
|
||||
const newHomebrew = homebrew.toObject();
|
||||
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})...`);
|
||||
|
||||
// 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