Added domain registration and global features
This commit is contained in:
parent
e2dd2eff07
commit
56f2281835
7 changed files with 120 additions and 1 deletions
14
scripts/features.js
Normal file
14
scripts/features.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* Library of Void Features
|
||||
* Export functions here to make them available globally under window.Void
|
||||
*/
|
||||
|
||||
export function ComboStrikes() {
|
||||
console.log("Combo Strikes executed!");
|
||||
// Logic for Combo Strikes
|
||||
}
|
||||
|
||||
export function NewFunction() {
|
||||
console.log("New Void Function executed!");
|
||||
// Logic for New Function
|
||||
}
|
||||
95
scripts/voidborne.js
Normal file
95
scripts/voidborne.js
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
// Import generic features from the library file
|
||||
import * as VoidFeatures from './features.js';
|
||||
|
||||
const MODULE_ID = 'daggerheart-voidborne';
|
||||
|
||||
console.log(`${MODULE_ID} | Module JS Loaded`);
|
||||
|
||||
Hooks.once('init', () => {
|
||||
console.log(`${MODULE_ID} | Initializing The Void (Unofficial)`);
|
||||
|
||||
// Expose the Void features globally
|
||||
// This allows Void.ComboStrikes(), Void.NewFunction(), etc.
|
||||
window.Void = window.Void || {};
|
||||
|
||||
// Assign all exported functions from features.js to window.Void
|
||||
Object.assign(window.Void, VoidFeatures);
|
||||
|
||||
console.log(`${MODULE_ID} | Void features registered:`, Object.keys(VoidFeatures));
|
||||
});
|
||||
|
||||
Hooks.on('ready', async () => {
|
||||
// Only run if the system is Daggerheart
|
||||
if (game.system.id !== 'daggerheart') return;
|
||||
|
||||
// Register Blood and Dread domains in system settings
|
||||
await registerVoidDomains();
|
||||
});
|
||||
|
||||
async function registerVoidDomains() {
|
||||
// Access Daggerheart Homebrew Settings
|
||||
// The system stores homebrew config in a setting named 'Homebrew' (case sensitive check needed)
|
||||
|
||||
// Check if the setting exists
|
||||
let homebrewSettings;
|
||||
try {
|
||||
homebrewSettings = game.settings.get('daggerheart', 'Homebrew');
|
||||
} catch (e) {
|
||||
try {
|
||||
homebrewSettings = game.settings.get('daggerheart', 'homebrew');
|
||||
} catch (e2) {
|
||||
console.warn(`${MODULE_ID} | Could not find Daggerheart 'Homebrew' or 'homebrew' setting.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!homebrewSettings) return;
|
||||
|
||||
const domainData = {
|
||||
'blood': {
|
||||
id: 'blood',
|
||||
label: 'Blood',
|
||||
src: `modules/${MODULE_ID}/icons/blood.png`,
|
||||
description: 'The Blood domain.'
|
||||
},
|
||||
'dread': {
|
||||
id: 'dread',
|
||||
label: 'Dread',
|
||||
src: `modules/${MODULE_ID}/icons/dread.png`,
|
||||
description: 'The Dread domain.'
|
||||
}
|
||||
};
|
||||
|
||||
let updates = false;
|
||||
// user domains are in homebrewSettings.domains
|
||||
const currentDomains = { ...(homebrewSettings.domains || {}) };
|
||||
|
||||
for (const [key, data] of Object.entries(domainData)) {
|
||||
if (!currentDomains[key]) {
|
||||
console.log(`${MODULE_ID} | Registering missing domain: ${data.label}`);
|
||||
currentDomains[key] = data;
|
||||
updates = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (updates) {
|
||||
// Update the setting
|
||||
try {
|
||||
// We need to keep the structure of homebrewSettings intact
|
||||
const newSettings = {
|
||||
...homebrewSettings,
|
||||
domains: currentDomains
|
||||
};
|
||||
|
||||
// We need to know the Key used to set it.
|
||||
let key = 'Homebrew';
|
||||
if (game.settings.settings.has('daggerheart.homebrew')) key = 'homebrew';
|
||||
|
||||
await game.settings.set('daggerheart', key, newSettings);
|
||||
|
||||
ui.notifications.info(`${MODULE_ID} | Registered missing domains (Blood/Dread) in Homebrew Settings.`);
|
||||
} catch (err) {
|
||||
console.error(`${MODULE_ID} | Failed to update settings:`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue