From ed845b2189364dca70ad1a724690ab725520ad59 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sat, 3 May 2025 14:00:13 -0600 Subject: [PATCH] Add default implementations for create/delete tables --- module/utils/databases/Database.mjs | 30 +++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/module/utils/databases/Database.mjs b/module/utils/databases/Database.mjs index e9400d7..4a1c3d1 100644 --- a/module/utils/databases/Database.mjs +++ b/module/utils/databases/Database.mjs @@ -3,7 +3,20 @@ export class Database { // MARK: Table Ops static createTable(tableConfig) { - throw new Error(`createTable() must be defined`); + if (!game.user.isGM) { + ui.notifications.error(`You do not have the required permission to create a new table`); + return false; + }; + + const tables = game.settings.get(__ID__, `tables`); + if (tables[tableConfig.name]) { + ui.notifications.error(`Cannot create table that already exists`); + return false; + }; + + tables[tableConfig.name] = tableConfig; + game.settings.set(__ID__, `tables`, tables); + return true; }; /** @returns {Array} */ @@ -19,7 +32,20 @@ export class Database { }; static deleteTable(tableID) { - throw new Error(`deleteTable() must be defined`); + if (!game.user.isGM) { + ui.notifications.error(`You do not have the required permission to delete a table`); + return false; + }; + + const tables = game.settings.get(__ID__, `tables`); + if (!tables[tableID]) { + ui.notifications.error(`Cannot delete a table that doesn't exist`); + return false; + }; + + delete tables[tableID]; + game.settings.set(__ID__, `tables`, tables); + return true; }; // MARK: Row Ops