From 9b3751b28185af30d320bbdd913dae6c1d9a9dde Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sun, 25 May 2025 18:21:29 -0600 Subject: [PATCH] Add a user setting to determine if the sidebar tab should be added --- module/hooks/init.mjs | 31 ++++++++++++++++++------------- module/settings/user.mjs | 11 +++++++++++ public/langs/en-ca.json | 4 ++++ 3 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 module/settings/user.mjs diff --git a/module/hooks/init.mjs b/module/hooks/init.mjs index 1422bce..e7e1d2d 100644 --- a/module/hooks/init.mjs +++ b/module/hooks/init.mjs @@ -14,26 +14,31 @@ import helpers from "../handlebarsHelpers/_index.mjs"; import { Logger } from "../utils/Logger.mjs"; import { registerCustomComponents } from "../Apps/elements/_index.mjs"; import { registerMetaSettings } from "../settings/meta.mjs"; +import { registerUserSettings } from "../settings/user.mjs"; import { registerWorldSettings } from "../settings/world.mjs"; Hooks.on(`init`, () => { Logger.debug(`Initializing`); - // Add a custom sidebar tab for the module - CONFIG.ui.sidebar.TABS.stats = { - active: false, - icon: `fa-solid fa-chart-line`, - tooltip: `Stats!`, - }; - CONFIG.ui.stats = StatSidebar; - - // Inject the tab right before settings; - const temp = CONFIG.ui.sidebar.TABS.settings; - delete CONFIG.ui.sidebar.TABS.settings; - CONFIG.ui.sidebar.TABS.settings = temp; - registerMetaSettings(); registerWorldSettings(); + registerUserSettings(); + + // Add a custom sidebar tab for the module + if (game.settings.get(__ID__, `statsSidebarTab`)) { + CONFIG.ui.sidebar.TABS.stats = { + active: false, + icon: `fa-solid fa-chart-line`, + tooltip: `Stats!`, + }; + CONFIG.ui.stats = StatSidebar; + + // Inject the custom tab right before settings + const temp = CONFIG.ui.sidebar.TABS.settings; + delete CONFIG.ui.sidebar.TABS.settings; + CONFIG.ui.sidebar.TABS.settings = temp; + }; + CONFIG.stats = { db: UserFlagDatabase, diff --git a/module/settings/user.mjs b/module/settings/user.mjs new file mode 100644 index 0000000..41f384d --- /dev/null +++ b/module/settings/user.mjs @@ -0,0 +1,11 @@ +export function registerUserSettings() { + game.settings.register(__ID__, `statsSidebarTab`, { + name: `STAT_TRACKER.settings.statsSidebarTab.name`, + hint: `STAT_TRACKER.settings.statsSidebarTab.hint`, + scope: `user`, + type: Boolean, + config: true, + default: true, + requiresReload: true, + }); +}; diff --git a/public/langs/en-ca.json b/public/langs/en-ca.json index 7b30eea..18bc399 100644 --- a/public/langs/en-ca.json +++ b/public/langs/en-ca.json @@ -14,6 +14,10 @@ "globalAPI": { "name": "Global API", "hint": "Whether or not the module provides a global interface for interacting with the module's backend. This is convenient for macros and using the dev console." + }, + "statsSidebarTab": { + "name": "Stats Sidebar Tab", + "hint": "Adds a custom sidebar tab to view and control the module with ease. With the sidebar tab disabled the only way to control the module is via the public API." } } }