Added setting registration status (closes #20)

This commit is contained in:
Oliver 2025-12-09 21:54:29 -07:00
parent b3119f5287
commit dfcbef81ef
16 changed files with 68 additions and 19 deletions

2
dev/dev.mjs Normal file
View file

@ -0,0 +1,2 @@
// Hooks
import "./hooks/ready.mjs";

5
dev/hooks/ready.mjs Normal file
View file

@ -0,0 +1,5 @@
import { __ID__ } from "../../module/consts.mjs";
Hooks.on(`ready`, () => {
console.table(game.modules.get(__ID__).api.registered);
});

View file

@ -14,7 +14,8 @@
"maximum": 13 "maximum": 13
}, },
"esmodules": [ "esmodules": [
"module/oft.mjs" "module/oft.mjs",
"dev/dev.mjs"
], ],
"styles": [ "styles": [
{ {

View file

@ -5,7 +5,8 @@ of incompatabilities for whatever reason. This can also be used
internally within this module if we discover incompatabilites with internally within this module if we discover incompatabilites with
systems and want to disable it on our side. systems and want to disable it on our side.
This file is more as documentation than anything at this point in time. This file is meant more documentation than anything at this point in
time.
Call Signature: (settingKey: string) => {} Call Signature: (settingKey: string) => (void | boolean)
*/ */

View file

@ -0,0 +1,13 @@
/*
This hook is used to enable any modules that attempt to disable settings
or just want to investigate what settings are enabled to be able to get
a ping with information about which settings where registered entirely
and which weren't. The object that is passed to this is frozen and is
not meant to be edited as you cannot de-register nor prevent setting
registration from this hook. For that see the "oft.preventSetting" hook.
This file is meant more documentation than anything at this point in
time.
Call Signature: (settings: Record<string, boolean>) => void
*/

View file

@ -20,6 +20,9 @@ import { HotbarSettingsMenu } from "./apps/HotbarSettingsMenu.mjs";
// Misc // Misc
import { __ID__ } from "./consts.mjs"; import { __ID__ } from "./consts.mjs";
const { deepFreeze } = foundry.utils;
const status = {};
Hooks.on(`setup`, () => { Hooks.on(`setup`, () => {
game.settings.registerMenu(__ID__, `devSettings`, { game.settings.registerMenu(__ID__, `devSettings`, {
@ -29,8 +32,8 @@ Hooks.on(`setup`, () => {
restricted: false, restricted: false,
type: DevSettingsMenu, type: DevSettingsMenu,
}); });
addGlobalDocReferrer(); status.addGlobalDocReferrer = addGlobalDocReferrer();
autoUnpauseOnLoad(); status.autoUnpauseOnLoad = autoUnpauseOnLoad();
game.settings.registerMenu(__ID__, `hotbarSettings`, { game.settings.registerMenu(__ID__, `hotbarSettings`, {
name: `OFT.menu.hotbarSettings.name`, name: `OFT.menu.hotbarSettings.name`,
@ -39,13 +42,18 @@ Hooks.on(`setup`, () => {
restricted: false, restricted: false,
type: HotbarSettingsMenu, type: HotbarSettingsMenu,
}); });
hotbarButtonSize(); status.hotbarButtonSize = hotbarButtonSize();
hotbarButtonGap(); status.hotbarButtonGap = hotbarButtonGap();
repositionHotbar(); status.repositionHotbar = repositionHotbar();
chatSidebarBackground(); status.chatSidebarBackground = chatSidebarBackground();
startSidebarExpanded(); status.startSidebarExpanded = startSidebarExpanded();
startingSidebarTab(); status.startingSidebarTab = startingSidebarTab();
preventTokenRotation(); status.preventTokenRotation = preventTokenRotation();
preventUserConfigOpen(); status.preventUserConfigOpen = preventUserConfigOpen();
Hooks.callAll(`oft.settingStatuses`, deepFreeze(status));
game.modules.get(__ID__).api = deepFreeze({
registered: status,
});
}); });

View file

@ -33,4 +33,5 @@ export function addGlobalDocReferrer() {
}); });
// #endregion Implementation // #endregion Implementation
return true;
}; };

View file

@ -9,7 +9,7 @@ export function autoUnpauseOnLoad() {
const prevented = Hooks.call(`${__ID__}.preventSetting`, key); const prevented = Hooks.call(`${__ID__}.preventSetting`, key);
if (!prevented) { if (!prevented) {
Logger.log(`Preventing setting "${key}" from being registered`); Logger.log(`Preventing setting "${key}" from being registered`);
return; return false;
}; };
// #region Registration // #region Registration
@ -34,4 +34,6 @@ export function autoUnpauseOnLoad() {
}; };
}); });
// #endregion Implementation // #endregion Implementation
return true;
}; };

View file

@ -28,4 +28,6 @@ export function chatSidebarBackground() {
document.body.classList.add(`${__ID__}-${key}`); document.body.classList.add(`${__ID__}-${key}`);
}; };
// #endregion Implementation // #endregion Implementation
return true;
}; };

View file

@ -9,7 +9,7 @@ export function hotbarButtonGap() {
const prevented = Hooks.call(`${__ID__}.preventSetting`, key); const prevented = Hooks.call(`${__ID__}.preventSetting`, key);
if (!prevented) { if (!prevented) {
Logger.log(`Preventing setting "${key}" from being registered`); Logger.log(`Preventing setting "${key}" from being registered`);
return; return false;
}; };
// #region Registration // #region Registration
@ -37,4 +37,6 @@ export function hotbarButtonGap() {
const buttonGap = game.settings.get(__ID__, key); const buttonGap = game.settings.get(__ID__, key);
document.body.style.setProperty(`--hotbar-button-gap`, `${buttonGap}px`); document.body.style.setProperty(`--hotbar-button-gap`, `${buttonGap}px`);
// #endregion Implementation // #endregion Implementation
return true;
}; };

View file

@ -9,7 +9,7 @@ export function hotbarButtonSize() {
const prevented = Hooks.call(`${__ID__}.preventSetting`, key); const prevented = Hooks.call(`${__ID__}.preventSetting`, key);
if (!prevented) { if (!prevented) {
Logger.log(`Preventing setting "${key}" from being registered`); Logger.log(`Preventing setting "${key}" from being registered`);
return; return false;
}; };
// #region Registration // #region Registration
@ -37,4 +37,6 @@ export function hotbarButtonSize() {
const hotbarSize = game.settings.get(__ID__, key); const hotbarSize = game.settings.get(__ID__, key);
document.body.style.setProperty(`--hotbar-size`, `${hotbarSize}px`); document.body.style.setProperty(`--hotbar-size`, `${hotbarSize}px`);
// #endregion Implementation // #endregion Implementation
return true;
}; };

View file

@ -8,7 +8,7 @@ export function preventTokenRotation() {
const prevented = Hooks.call(`${__ID__}.preventSetting`, key); const prevented = Hooks.call(`${__ID__}.preventSetting`, key);
if (!prevented) { if (!prevented) {
Logger.log(`Preventing setting "${key}" from being registered`); Logger.log(`Preventing setting "${key}" from being registered`);
return; return false;
}; };
/** @type {number|null} */ /** @type {number|null} */
@ -39,6 +39,8 @@ export function preventTokenRotation() {
hookID = Hooks.on(`preMoveToken`, preMoveTokenHandler); hookID = Hooks.on(`preMoveToken`, preMoveTokenHandler);
}; };
// #endregion Implementation // #endregion Implementation
return true;
}; };
// #region Helpers // #region Helpers

View file

@ -8,7 +8,7 @@ export function preventUserConfigOpen() {
const prevented = Hooks.call(`${__ID__}.preventSetting`, key); const prevented = Hooks.call(`${__ID__}.preventSetting`, key);
if (!prevented) { if (!prevented) {
Logger.log(`Preventing setting "${key}" from being registered`); Logger.log(`Preventing setting "${key}" from being registered`);
return; return false;
}; };
// #region Registration // #region Registration
@ -32,4 +32,6 @@ export function preventUserConfigOpen() {
}; };
}); });
// #endregion Implementation // #endregion Implementation
return true;
}; };

View file

@ -9,7 +9,7 @@ export function repositionHotbar() {
const prevented = Hooks.call(`${__ID__}.preventSetting`, key); const prevented = Hooks.call(`${__ID__}.preventSetting`, key);
if (!prevented) { if (!prevented) {
Logger.log(`Preventing setting "${key}" from being registered`); Logger.log(`Preventing setting "${key}" from being registered`);
return; return false;
}; };
// #region Registration // #region Registration
@ -43,4 +43,6 @@ export function repositionHotbar() {
uiPosition.insertAdjacentElement(`beforeend`, container); uiPosition.insertAdjacentElement(`beforeend`, container);
}; };
// #endregion Implementation // #endregion Implementation
return true;
}; };

View file

@ -26,4 +26,6 @@ export function startSidebarExpanded() {
}; };
}); });
// #endregion Implementation // #endregion Implementation
return true;
}; };

View file

@ -55,4 +55,6 @@ export function startingSidebarTab() {
}; };
}); });
// #endregion Implementation // #endregion Implementation
return true;
}; };