76 lines
1.7 KiB
JavaScript
76 lines
1.7 KiB
JavaScript
import { api } from "../api.mjs";
|
|
import { __ID__, filePath } from "../consts.mjs";
|
|
import { getFileSize } from "../utils/fs.mjs";
|
|
|
|
const { HandlebarsApplicationMixin } = foundry.applications.api;
|
|
const { AbstractSidebarTab } = foundry.applications.sidebar;
|
|
const { deepClone } = foundry.utils;
|
|
|
|
export class ArtSidebar extends HandlebarsApplicationMixin(AbstractSidebarTab) {
|
|
// #region Options
|
|
static tabName = `art`;
|
|
|
|
static DEFAULT_OPTIONS = {
|
|
classes: [
|
|
__ID__,
|
|
`ArtSidebar`,
|
|
],
|
|
window: {},
|
|
actions: {
|
|
openApp: this.#openApp,
|
|
},
|
|
};
|
|
|
|
static PARTS = {
|
|
tokens: {
|
|
template: filePath(`templates/ArtSidebar/tokens.hbs`),
|
|
},
|
|
artists: {
|
|
template: filePath(`templates/ArtSidebar/artists.hbs`),
|
|
},
|
|
};
|
|
// #endregion Options
|
|
|
|
// #region Data Prep
|
|
async _preparePartContext(partID, ctx) {
|
|
ctx = deepClone(ctx);
|
|
|
|
switch (partID) {
|
|
case `tokens`: {
|
|
await this._prepareTokensContext(ctx);
|
|
break;
|
|
};
|
|
case `artists`: {
|
|
await this._prepareArtistsContext(ctx);
|
|
break;
|
|
};
|
|
};
|
|
|
|
return ctx;
|
|
};
|
|
|
|
async _prepareTokensContext(ctx) {
|
|
const size = await getFileSize(filePath(`storage/db/images.json`));
|
|
ctx.size = size.friendly;
|
|
};
|
|
|
|
async _prepareArtistsContext(ctx) {
|
|
const size = await getFileSize(filePath(`storage/db/artists.json`));
|
|
ctx.size = size.friendly;
|
|
};
|
|
// #endregion Data Prep
|
|
|
|
// #region Actions
|
|
static async #openApp(event, target) {
|
|
const { app: appKey, ...options } = target.dataset;
|
|
delete options.action;
|
|
|
|
if (appKey in api.Apps) {
|
|
const app = new api.Apps[appKey](options);
|
|
await app.render({ force: true });
|
|
} else {
|
|
console.error(`Failed to find app with key: ${appKey}`);
|
|
};
|
|
};
|
|
// #endregion Actions
|
|
};
|