Close the TableCreator and dice namespace warning when the table is made successfully (closes #25)

This commit is contained in:
Oliver-Akins 2025-05-31 10:17:20 -06:00
parent c7379a48f4
commit 2c733385ef

View file

@ -109,6 +109,7 @@ export class TableCreator extends HandlebarsApplicationMixin(ApplicationV2) {
this.render(); this.render();
}; };
/** @this {TableCreator} */
static async #createTable() { static async #createTable() {
/** @type {string} */ /** @type {string} */
const name = this._name; const name = this._name;
@ -122,17 +123,21 @@ export class TableCreator extends HandlebarsApplicationMixin(ApplicationV2) {
return; return;
}; };
let created = false;
if (name.startsWith(`Dice`)) { if (name.startsWith(`Dice`)) {
if (!name.match(diceNamespacePattern)) { if (!name.match(diceNamespacePattern)) {
ui.notifications.error(`Table name doesn't conform to the "Dice/dX" format required by the Dice namespace.`); ui.notifications.error(`Table name doesn't conform to the "Dice/dX" format required by the Dice namespace.`);
return; return;
}; };
const size = Number(name.replace(`Dice/d`, ``)); const size = Number(name.replace(`Dice/d`, ``));
await CONFIG.stats.db.createTable(createDiceTable(size)); created = await CONFIG.stats.db.createTable(createDiceTable(size));
return; if (created) {
this.close();
ui.notifications.remove(this.#diceNamespaceAlert);
this.#diceNamespaceAlert = null;
}; };
} else {
await CONFIG.stats.db.createTable({ created = await CONFIG.stats.db.createTable({
name, name,
buckets: { buckets: {
type: this._type, type: this._type,
@ -142,5 +147,14 @@ export class TableCreator extends HandlebarsApplicationMixin(ApplicationV2) {
stacked: true, stacked: true,
}, },
}); });
}
if (created) {
this.close();
if (this.#diceNamespaceAlert) {
ui.notifications.remove(this.#diceNamespaceAlert);
this.#diceNamespaceAlert = null;
};
};
}; };
}; };