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,25 +123,38 @@ 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 {
created = await CONFIG.stats.db.createTable({
name,
buckets: {
type: this._type,
},
graph: {
type: `bar`,
stacked: true,
},
});
}
await CONFIG.stats.db.createTable({ if (created) {
name, this.close();
buckets: { if (this.#diceNamespaceAlert) {
type: this._type, ui.notifications.remove(this.#diceNamespaceAlert);
}, this.#diceNamespaceAlert = null;
graph: { };
type: `bar`, };
stacked: true,
},
});
}; };
}; };