From b8b8f8f16b157a2ccb1da32b26e3375f0bbcc201 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sat, 3 May 2025 21:38:25 -0600 Subject: [PATCH] Add data validation to the abstract Database table methods --- module/utils/databases/Database.mjs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/module/utils/databases/Database.mjs b/module/utils/databases/Database.mjs index 4a1c3d1..99f79ed 100644 --- a/module/utils/databases/Database.mjs +++ b/module/utils/databases/Database.mjs @@ -8,14 +8,27 @@ export class Database { return false; }; + const name = tableConfig.name; + if (name.split(`/`).length > 2) { + ui.notifications.error(`Subtables are not able to have subtables`); + return false; + } + const tables = game.settings.get(__ID__, `tables`); - if (tables[tableConfig.name]) { + const [ table, subtable ] = name.split(`/`); + if (subtable && tables[table]) { + ui.notifications.error(`Cannot add subtable for a table that already exists`); + return false; + } + + if (tables[name]) { ui.notifications.error(`Cannot create table that already exists`); return false; }; - tables[tableConfig.name] = tableConfig; + tables[name] = tableConfig; game.settings.set(__ID__, `tables`, tables); + this.render(); return true; }; @@ -96,9 +109,9 @@ export class Database { * Rerenders all of the applications that are displaying data from * this database */ - static render() { - for (const app of Object.values(this.apps)) { - app.render(); + static render(opts) { + for (const app of this._apps.values()) { + app.render(opts); }; };