Hard-override any configured database handler that is erroneous and freeze the config after ready.

This commit is contained in:
Oliver-Akins 2025-05-27 23:34:27 -06:00
parent a354629839
commit 47deb24d67
2 changed files with 46 additions and 1 deletions

View file

@ -1,12 +1,23 @@
import { Database } from "../utils/databases/Database.mjs";
import { Logger } from "../utils/Logger.mjs";
import { NilDatabase } from "../utils/databases/NilDatabase.mjs";
Hooks.on(`ready`, () => {
Logger.log(`Version: ${__VERSION__}`);
// Alert GMs when the configured DB is invalid
if (!(CONFIG.stats.db.prototype instanceof Database) && game.user.isGM) {
ui.notifications.error(`The database handler does not conform to the required heirarchy, the stats tracker module will almost certainly not work correctly.`, { permanent: true });
ui.notifications.error(`The database adapter does not conform to the required specification, the stats tracker module overrode the configured database adapter with a stub to protect data that exists already.`, { permanent: true });
CONFIG.stats.db = NilDatabase;
};
/*
Prevent any run-time modifications to the CONFIG API so that users can't wreck
themselves nor their data by fooling around with the values.
*/
if (import.meta.env.PROD) {
Object.freeze(CONFIG.stats);
};
CONFIG.stats.db.registerListeners();
});