Use references to my apps and Database via a CONFIG object that contains all of them rather than only the DB
This commit is contained in:
parent
d79597d1e2
commit
c5c1c67efe
4 changed files with 19 additions and 16 deletions
|
|
@ -1,6 +1,4 @@
|
||||||
import { filePath } from "../consts.mjs";
|
import { filePath } from "../consts.mjs";
|
||||||
import { StatsViewer } from "./StatsViewer.mjs";
|
|
||||||
import { TableCreator } from "./TableCreator.mjs";
|
|
||||||
|
|
||||||
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
||||||
const { AbstractSidebarTab } = foundry.applications.sidebar;
|
const { AbstractSidebarTab } = foundry.applications.sidebar;
|
||||||
|
|
@ -34,7 +32,7 @@ export class StatSidebar extends HandlebarsApplicationMixin(AbstractSidebarTab)
|
||||||
|
|
||||||
async _prepareContext(options) {
|
async _prepareContext(options) {
|
||||||
const ctx = await super._prepareContext(options);
|
const ctx = await super._prepareContext(options);
|
||||||
const db = CONFIG.StatsDatabase;
|
const db = CONFIG.stats.db;
|
||||||
|
|
||||||
ctx.tableCount = db.getTables().length;
|
ctx.tableCount = db.getTables().length;
|
||||||
|
|
||||||
|
|
@ -63,13 +61,13 @@ export class StatSidebar extends HandlebarsApplicationMixin(AbstractSidebarTab)
|
||||||
|
|
||||||
/** @this {StatSidebar} */
|
/** @this {StatSidebar} */
|
||||||
static async #openStats() {
|
static async #openStats() {
|
||||||
const app = new StatsViewer();
|
const app = new CONFIG.stats.viewer;
|
||||||
app.render({ force: true });
|
app.render({ force: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @this {StatSidebar} */
|
/** @this {StatSidebar} */
|
||||||
static async #createTable() {
|
static async #createTable() {
|
||||||
const app = new TableCreator;
|
const app = new CONFIG.stats.creator;
|
||||||
app.render({ force: true });
|
app.render({ force: true });
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
|
|
||||||
async _onFirstRender(context, options) {
|
async _onFirstRender(context, options) {
|
||||||
await super._onFirstRender(context, options);
|
await super._onFirstRender(context, options);
|
||||||
CONFIG.StatsDatabase.addApp(this);
|
CONFIG.stats.db.addApp(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
async _onRender(context, options) {
|
async _onRender(context, options) {
|
||||||
|
|
@ -123,7 +123,7 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
const tables = new Set();
|
const tables = new Set();
|
||||||
const subtables = {};
|
const subtables = {};
|
||||||
|
|
||||||
for (const tableConfig of CONFIG.StatsDatabase.getTables()) {
|
for (const tableConfig of CONFIG.stats.db.getTables()) {
|
||||||
const [ table, subtable ] = tableConfig.name.split(`/`);
|
const [ table, subtable ] = tableConfig.name.split(`/`);
|
||||||
tables.add(table);
|
tables.add(table);
|
||||||
if (subtable?.length > 0) {
|
if (subtable?.length > 0) {
|
||||||
|
|
@ -182,8 +182,8 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
_graphData = {};
|
_graphData = {};
|
||||||
_privacySetting = `my`;
|
_privacySetting = `my`;
|
||||||
async #prepareGraphContext(_ctx) {
|
async #prepareGraphContext(_ctx) {
|
||||||
const table = CONFIG.StatsDatabase.getTable(this.activeTableID);
|
const table = CONFIG.stats.db.getTable(this.activeTableID);
|
||||||
const userData = CONFIG.StatsDatabase.getRows(
|
const userData = CONFIG.stats.db.getRows(
|
||||||
this.activeTableID,
|
this.activeTableID,
|
||||||
this._selectedUsers,
|
this._selectedUsers,
|
||||||
this._privacySetting,
|
this._privacySetting,
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ export class TableCreator extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
ui.notifications.error(`Cannot create a table without a name`);
|
ui.notifications.error(`Cannot create a table without a name`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const existing = CONFIG.StatsDatabase.getTable(name);
|
const existing = CONFIG.stats.db.getTable(name);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
ui.notifications.error(`A table with the name "${name}" already exists`);
|
ui.notifications.error(`A table with the name "${name}" already exists`);
|
||||||
};
|
};
|
||||||
|
|
@ -123,7 +123,7 @@ export class TableCreator extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
const size = Number(name.replace(`Dice/d`, ``));
|
const size = Number(name.replace(`Dice/d`, ``));
|
||||||
CONFIG.StatsDatabase.createTable(createDiceTable(size));
|
CONFIG.stats.db.createTable(createDiceTable(size));
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import { MemoryDatabase } from "../utils/databases/Memory.mjs";
|
||||||
import { registerCustomComponents } from "../Apps/elements/_index.mjs";
|
import { registerCustomComponents } from "../Apps/elements/_index.mjs";
|
||||||
import { registerMetaSettings } from "../settings/meta.mjs";
|
import { registerMetaSettings } from "../settings/meta.mjs";
|
||||||
import { StatSidebar } from "../Apps/StatSidebar.mjs";
|
import { StatSidebar } from "../Apps/StatSidebar.mjs";
|
||||||
|
import { StatsViewer } from "../Apps/StatsViewer.mjs";
|
||||||
|
import { TableCreator } from "../Apps/TableCreator.mjs";
|
||||||
import { UserFlagDatabase } from "../utils/databases/UserFlag.mjs";
|
import { UserFlagDatabase } from "../utils/databases/UserFlag.mjs";
|
||||||
|
|
||||||
Hooks.on(`init`, () => {
|
Hooks.on(`init`, () => {
|
||||||
|
|
@ -22,13 +24,16 @@ Hooks.on(`init`, () => {
|
||||||
delete CONFIG.ui.sidebar.TABS.settings;
|
delete CONFIG.ui.sidebar.TABS.settings;
|
||||||
CONFIG.ui.sidebar.TABS.settings = temp;
|
CONFIG.ui.sidebar.TABS.settings = temp;
|
||||||
|
|
||||||
|
|
||||||
registerMetaSettings();
|
registerMetaSettings();
|
||||||
|
|
||||||
if (import.meta.env.PROD) {
|
CONFIG.stats = {
|
||||||
CONFIG.StatsDatabase = UserFlagDatabase;
|
db: UserFlagDatabase,
|
||||||
} else {
|
viewer: StatsViewer,
|
||||||
CONFIG.StatsDatabase = MemoryDatabase;
|
creator: TableCreator,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
CONFIG.stats.db = MemoryDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
Handlebars.registerHelper(helpers);
|
Handlebars.registerHelper(helpers);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue