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
|
## Features
|
||||||
|
|
||||||
### 🛠️ The Ikonis Hardware Tab
|
### The Ikonis Hardware Tab
|
||||||
Every weapon sheet now includes a dedicated **Ikonis** tab.
|
Every weapon sheet now includes a dedicated **Ikonis** tab.
|
||||||
- **Install Tech**: Drag and drop features or select from the pre-defined list.
|
- **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.
|
- **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).
|
- **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:
|
GMs can access the **Global Hardware Manager** in the module settings to:
|
||||||
- Define the global pool of available Augments.
|
- Define the global pool of available Augments.
|
||||||
- Set the cost, effect, and name of each augment.
|
- Set the cost, effect, and name of each augment.
|
||||||
- Link augments to specific **Features** (items) for automated description and icon fetching.
|
- Link augments to specific **Features** (items) for automated description and icon fetching.
|
||||||
- Configure the default "Bonded" feature for all Ikonis weapons.
|
- 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.
|
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.
|
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:
|
The module automatically overrides the game's homebrew settings to establish a streamlined, high-tech economy:
|
||||||
- **Quantum**: Replaces traditional gold with "Quantum" credits.
|
- **Quantum**: Replaces traditional gold with "Quantum" credits.
|
||||||
- **Unified Economy**: Disables multi-tier currency (bags, chests) in favor of a single, tech-focused value system.
|
- **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}`);
|
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) {
|
export function getSlotCount(item) {
|
||||||
const flags = item.getFlag('dh-ikonis') || {};
|
const flags = item.getFlag('dh-ikonis') || {};
|
||||||
if (typeof flags.slotOverride === "number") return flags.slotOverride;
|
if (typeof flags.slotOverride === "number") return flags.slotOverride;
|
||||||
|
|
@ -121,15 +130,27 @@ export function patchDhCharacter(DhCharacter) {
|
||||||
|
|
||||||
if (!this.parent) return lists;
|
if (!this.parent) return lists;
|
||||||
|
|
||||||
for (const item of this.parent.items) {
|
const weapons = this.parent.items.filter(i => i.type === 'weapon');
|
||||||
if (item.type !== 'weapon' || !item.system.equipped) continue;
|
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 installedIds = item.getFlag('dh-ikonis', 'installedAugments') || [];
|
||||||
const bondedUuid = item.getFlag('dh-ikonis', 'bondedFeatureUuid');
|
const bondedUuid = item.getFlag('dh-ikonis', 'bondedFeatureUuid');
|
||||||
|
|
||||||
if (bondedUuid) {
|
if (bondedUuid) {
|
||||||
const feature = _featureCache.get(bondedUuid) || fromUuidSync(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();
|
const allAugs = getAugments();
|
||||||
|
|
@ -138,7 +159,10 @@ export function patchDhCharacter(DhCharacter) {
|
||||||
if (!aug?.featureUuid) continue;
|
if (!aug?.featureUuid) continue;
|
||||||
|
|
||||||
const feature = _featureCache.get(aug.featureUuid) || fromUuidSync(aug.featureUuid);
|
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
|
restricted: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Try to patch character model early if available
|
||||||
|
const DhCharacter = CONFIG.Actor.dataModels?.character;
|
||||||
|
if (DhCharacter) {
|
||||||
|
patchDhCharacter(DhCharacter);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Hooks.on('setup', () => {
|
Hooks.on('setup', () => {
|
||||||
patchDHWeapon();
|
patchDHWeapon();
|
||||||
patchIkonisLogic();
|
patchIkonisLogic();
|
||||||
patchIkonisSheet();
|
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
|
// Watch for Tier/Ikonis changes and force a refresh
|
||||||
|
|
@ -93,7 +105,7 @@ Hooks.once('ready', async () => {
|
||||||
// Load features into memory for sync getters
|
// Load features into memory for sync getters
|
||||||
await loadIkonisFeatures();
|
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;
|
const DhCharacter = game.system.api?.models?.actors?.DhCharacter || CONFIG.Actor.dataModels?.character;
|
||||||
if (DhCharacter) {
|
if (DhCharacter) {
|
||||||
patchDhCharacter(DhCharacter);
|
patchDhCharacter(DhCharacter);
|
||||||
|
|
@ -103,18 +115,35 @@ Hooks.once('ready', async () => {
|
||||||
|
|
||||||
// Force re-render of open character sheets to show newly patched features
|
// Force re-render of open character sheets to show newly patched features
|
||||||
Object.values(ui.windows).forEach(w => {
|
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() {
|
async function overrideCurrency() {
|
||||||
const homebrew = game.settings.get('daggerheart', 'homebrew');
|
// Robust key check for Daggerheart Homebrew settings
|
||||||
// Only override if not already set to Quantum to avoid spamming updates
|
let key = 'Homebrew';
|
||||||
if (homebrew.currency?.title !== "Quantum") {
|
if (!game.settings.settings.has('daggerheart.Homebrew')) {
|
||||||
console.log("DH-Ikonis | Overriding currency settings to Quantum...");
|
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 homebrew = game.settings.get('daggerheart', key);
|
||||||
const newHomebrew = homebrew.toObject();
|
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 = {
|
newHomebrew.currency = {
|
||||||
title: "Quantum",
|
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