Add default implementations for create/delete tables
This commit is contained in:
parent
dfc75fceaf
commit
ed845b2189
1 changed files with 28 additions and 2 deletions
|
|
@ -3,7 +3,20 @@
|
||||||
export class Database {
|
export class Database {
|
||||||
// MARK: Table Ops
|
// MARK: Table Ops
|
||||||
static createTable(tableConfig) {
|
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<Table>} */
|
/** @returns {Array<Table>} */
|
||||||
|
|
@ -19,7 +32,20 @@ export class Database {
|
||||||
};
|
};
|
||||||
|
|
||||||
static deleteTable(tableID) {
|
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
|
// MARK: Row Ops
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue