diff --git a/dev/dev.mjs b/dev/dev.mjs deleted file mode 100644 index ccb796e..0000000 --- a/dev/dev.mjs +++ /dev/null @@ -1,2 +0,0 @@ -// Hooks -import "./hooks/ready.mjs"; diff --git a/dev/hooks/ready.mjs b/dev/hooks/ready.mjs deleted file mode 100644 index d7bea64..0000000 --- a/dev/hooks/ready.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import { __ID__ } from "../../module/consts.mjs"; - -Hooks.on(`ready`, () => { - console.table(game.modules.get(__ID__).api.settings); -}); diff --git a/langs/en-ca.json b/langs/en-ca.json index d2e091a..fc4f428 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -9,10 +9,6 @@ "name": "Auto Unpause On Load", "hint": "(v13+, GM-Only) Automatically unpauses the game when you load into the world. This will happen EVERY time you load into the world, including if you reload the website." }, - "chatImageLinks": { - "name": "Image Shortcuts", - "hint": "(v13+) When attempting to send an image/gif in chat, this allows you to easily embed the actual image in the text by changing \"http\"/\"https\" into \"image\", automatically displaying the image after sending the message." - }, "chatSidebarBackground": { "name": "Chat Background", "hint": "(v13+) Adds a background to the chat tab of the right-hand sidebar." @@ -25,17 +21,9 @@ "name": "Hotbar Button Size", "hint": "(v13+) Changes the size of the hotbar buttons to a size you prefer." }, - "preventMovementHistory": { - "name": "Prevent Movement History", - "hint": "(v13+, GM-Only) This prevents Foundry from recording movement history of a token, but not disabling the movement ruler." - }, - "preventTokenRotation": { - "name": "Prevent Token Auto-Rotation", - "hint": "(v13+, GM-Only) This prevents tokens from rotating while you are moving them allowing you to more easily use POG-style tokens without them being rotated automatically by Foundry." - }, "preventUserConfigOpen": { "name": "Prevent Auto User Config", - "hint": "(v13+, Non-GMs) Prevents Foundry from opening the User Configuration when a player loads into the world." + "hint": "(v13+) Prevents Foundry from opening the User Configuration when a player loads into the world." }, "repositionHotbar": { "name": "Reposition Hotbar", @@ -58,37 +46,11 @@ "name": "Developer Settings", "hint": "Tweaks that are relevant if you are developing something within Foundry, but are rarely useful outside of that context.", "label": "Configure Dev Settings" - }, - "hotbarSettings": { - "name": "Hotbar Settings", - "hint": "Tweaks that modify Foundry's hotbar", - "label": "Configure Hotbar" - } - }, - "keybindings": { - "toggleMouseBroadcast": { - "name": "Toggle Show Cursor", - "hint": "(v13+) Temporarily turns off the mouse cursor position that other players can see. Hides the cursor until you activate this keybind again." } }, "apps": { "no-settings-to-display": "No settings to display", "make-global-reference": "Make Global Reference" - }, - "dialogs": { - "chatImageLinks": { - "didYouKnowImageLink": "", - "convertAndDontShowAgain": "", - "justConvert": "", - "ignoreAndDontShowAgain": "", - "disableEntirely": "" - } - }, - "notifs": { - "toggleMouseBroadcast": { - "hidingCursor": "Hiding your cursor from others!", - "showingCursor": "Showing your cursor to others!" - } } } } diff --git a/module.json b/module.json index 61d9791..86fedc1 100644 --- a/module.json +++ b/module.json @@ -1,7 +1,7 @@ { "id": "oft", "title": "Oliver's Foundry Tweaks", - "version": "1.1.0", + "version": "1.0.0", "authors": [ { "name": "Oliver" } ], @@ -14,8 +14,7 @@ "maximum": 13 }, "esmodules": [ - "module/oft.mjs", - "dev/dev.mjs" + "module/oft.mjs" ], "styles": [ { diff --git a/module/apps/DevSettingsMenu.mjs b/module/apps/DevSettingsMenu.mjs index 81a14e8..909fbab 100644 --- a/module/apps/DevSettingsMenu.mjs +++ b/module/apps/DevSettingsMenu.mjs @@ -1,4 +1,4 @@ -import { categories } from "../utils/SubMenuSettings.mjs"; +import { devSettings } from "../utils/DevSettings.mjs"; import { OFTSettingsMenu } from "./OFTSettingsMenu.mjs"; export class DevSettingsMenu extends OFTSettingsMenu { @@ -9,7 +9,6 @@ export class DevSettingsMenu extends OFTSettingsMenu { }; static get _SETTINGS() { - const devSettings = categories.get(`dev`); const settingIDs = []; for (const [settingID, shown] of devSettings.entries()) { if (shown) { diff --git a/module/apps/HotbarSettingsMenu.mjs b/module/apps/HotbarSettingsMenu.mjs deleted file mode 100644 index 0c7fb9e..0000000 --- a/module/apps/HotbarSettingsMenu.mjs +++ /dev/null @@ -1,21 +0,0 @@ -import { categories } from "../utils/SubMenuSettings.mjs"; -import { OFTSettingsMenu } from "./OFTSettingsMenu.mjs"; - -export class HotbarSettingsMenu extends OFTSettingsMenu { - static DEFAULT_OPTIONS = { - window: { - title: `OFT.menu.hotbarSettings.name`, - }, - }; - - static get _SETTINGS() { - const settings = categories.get(`hotbar`); - const settingIDs = []; - for (const [settingID, shown] of settings.entries()) { - if (shown) { - settingIDs.push(settingID); - }; - }; - return settingIDs; - }; -}; diff --git a/module/apps/OFTSettingsMenu.mjs b/module/apps/OFTSettingsMenu.mjs index 74ddf97..1506c25 100644 --- a/module/apps/OFTSettingsMenu.mjs +++ b/module/apps/OFTSettingsMenu.mjs @@ -1,4 +1,4 @@ -import { __ID__, filePath } from "../consts.mjs"; +import { filePath } from "../consts.mjs"; const { HandlebarsApplicationMixin: HAM, ApplicationV2 } = foundry.applications.api; @@ -7,7 +7,6 @@ export class OFTSettingsMenu extends HAM(ApplicationV2) { // #region Options static DEFAULT_OPTIONS = { tag: `form`, - classes: [ __ID__ ], window: { icon: `fa-solid fa-gears`, resizable: true, diff --git a/module/hooks/init.mjs b/module/hooks/init.mjs deleted file mode 100644 index d8bae1f..0000000 --- a/module/hooks/init.mjs +++ /dev/null @@ -1,19 +0,0 @@ -// Settings -import { preventMovementHistory } from "../settings/preventMovementHistory.mjs"; -import { toggleMouseBroadcast } from "../settings/toggleMouseBroadcast.mjs"; - -// Utils -import { Logger } from "../utils/Logger.mjs"; - -/* -This is only here for setting that **require** being registered during -initialization due to documentClass changes. If there is any way that -these settings can be implemented to work during the setup hook, that is -where they ideally should be implemented. -*/ -Hooks.on(`init`, () => { - Logger.log(`Initializing`); - - preventMovementHistory(); - toggleMouseBroadcast(); -}); diff --git a/module/hooks/oft.preventSetting.mjs b/module/hooks/oft.preventSetting.mjs index 500dc8e..31026ac 100644 --- a/module/hooks/oft.preventSetting.mjs +++ b/module/hooks/oft.preventSetting.mjs @@ -5,8 +5,7 @@ of incompatabilities for whatever reason. This can also be used internally within this module if we discover incompatabilites with systems and want to disable it on our side. -This file is meant more documentation than anything at this point in -time. +This file is more as documentation than anything at this point in time. -Call Signature: (settingKey: string) => (void | boolean) +Call Signature: (settingKey: string) => {} */ diff --git a/module/hooks/oft.settingStatuses.mjs b/module/hooks/oft.settingStatuses.mjs deleted file mode 100644 index 46bef18..0000000 --- a/module/hooks/oft.settingStatuses.mjs +++ /dev/null @@ -1,13 +0,0 @@ -/* -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) => void -*/ diff --git a/module/hooks/setup.mjs b/module/hooks/setup.mjs deleted file mode 100644 index ae63ec6..0000000 --- a/module/hooks/setup.mjs +++ /dev/null @@ -1,58 +0,0 @@ -// Settings -import { addGlobalDocReferrer } from "../settings/addGlobalDocReferrer.mjs"; -import { autoUnpauseOnLoad } from "../settings/autoUnpauseOnLoad.mjs"; -import { chatImageLinks } from "../settings/chatImageLinks.mjs"; -import { chatSidebarBackground } from "../settings/chatSidebarBackground.mjs"; -import { hotbarButtonGap } from "../settings/hotbarButtonGap.mjs"; -import { hotbarButtonSize } from "../settings/hotbarButtonSize.mjs"; -import { preventTokenRotation } from "../settings/preventTokenRotation.mjs"; -import { preventUserConfigOpen } from "../settings/preventUserConfigOpen.mjs"; -import { repositionHotbar } from "../settings/repositionHotbar.mjs"; -import { startingSidebarTab } from "../settings/startingSidebarTab.mjs"; -import { startSidebarExpanded } from "../settings/startSidebarExpanded.mjs"; - -// Apps -import { DevSettingsMenu } from "../apps/DevSettingsMenu.mjs"; -import { HotbarSettingsMenu } from "../apps/HotbarSettingsMenu.mjs"; - -// Misc -import { __ID__ } from "../consts.mjs"; -import { status } from "../utils/SettingStatus.mjs"; - -const { deepFreeze } = foundry.utils; - -Hooks.on(`setup`, () => { - - game.settings.registerMenu(__ID__, `devSettings`, { - name: `OFT.menu.devSettings.name`, - hint: `OFT.menu.devSettings.hint`, - label: `OFT.menu.devSettings.label`, - restricted: false, - type: DevSettingsMenu, - }); - addGlobalDocReferrer(); - autoUnpauseOnLoad(); - - game.settings.registerMenu(__ID__, `hotbarSettings`, { - name: `OFT.menu.hotbarSettings.name`, - hint: `OFT.menu.hotbarSettings.hint`, - label: `OFT.menu.hotbarSettings.label`, - restricted: false, - type: HotbarSettingsMenu, - }); - hotbarButtonSize(); - hotbarButtonGap(); - repositionHotbar(); - - chatImageLinks(); - chatSidebarBackground(); - startSidebarExpanded(); - startingSidebarTab(); - preventTokenRotation(); - preventUserConfigOpen(); - - Hooks.callAll(`oft.settingStatuses`, deepFreeze(status)); - game.modules.get(__ID__).api = deepFreeze({ - settings: status, - }); -}); diff --git a/module/oft.mjs b/module/oft.mjs index 8740d00..5765c9d 100644 --- a/module/oft.mjs +++ b/module/oft.mjs @@ -1,4 +1,40 @@ // Hooks -import "./hooks/init.mjs"; -import "./hooks/setup.mjs"; import "./hooks/renderSettingsConfig.mjs"; + +// Settings +import { addGlobalDocReferrer } from "./settings/addGlobalDocReferrer.mjs"; +import { autoUnpauseOnLoad } from "./settings/autoUnpauseOnLoad.mjs"; +import { chatSidebarBackground } from "./settings/chatSidebarBackground.mjs"; +import { hotbarButtonGap } from "./settings/hotbarButtonGap.mjs"; +import { hotbarButtonSize } from "./settings/hotbarButtonSize.mjs"; +import { preventUserConfigOpen } from "./settings/preventUserConfigOpen.mjs"; +import { repositionHotbar } from "./settings/repositionHotbar.mjs"; +import { startingSidebarTab } from "./settings/startingSidebarTab.mjs"; +import { startSidebarExpanded } from "./settings/startSidebarExpanded.mjs"; + +// Apps +import { DevSettingsMenu } from "./apps/DevSettingsMenu.mjs"; + +// Misc +import { __ID__ } from "./consts.mjs"; + +Hooks.on(`setup`, () => { + + game.settings.registerMenu(__ID__, `devSettings`, { + name: `OFT.menu.devSettings.name`, + hint: `OFT.menu.devSettings.hint`, + label: `OFT.menu.devSettings.label`, + restricted: false, + type: DevSettingsMenu, + }); + addGlobalDocReferrer(); + autoUnpauseOnLoad(); + + chatSidebarBackground(); + startSidebarExpanded(); + startingSidebarTab(); + hotbarButtonSize(); + hotbarButtonGap(); + repositionHotbar(); + preventUserConfigOpen(); +}); diff --git a/module/settings/addGlobalDocReferrer.mjs b/module/settings/addGlobalDocReferrer.mjs index d955d40..0700606 100644 --- a/module/settings/addGlobalDocReferrer.mjs +++ b/module/settings/addGlobalDocReferrer.mjs @@ -1,12 +1,10 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; import { __ID__ } from "../consts.mjs"; import { Logger } from "../utils/Logger.mjs"; -import { registerDevSetting } from "../utils/SubMenuSettings.mjs"; +import { registerDevSetting } from "../utils/DevSettings.mjs"; const key = `addGlobalDocReferrer`; export function addGlobalDocReferrer() { - status[key] = SettingStatusEnum.Unknown; // #region Registration Logger.log(`Registering setting: ${key}`); @@ -35,5 +33,4 @@ export function addGlobalDocReferrer() { }); // #endregion Implementation - status[key] = SettingStatusEnum.Registered; }; diff --git a/module/settings/autoUnpauseOnLoad.mjs b/module/settings/autoUnpauseOnLoad.mjs index de15fa4..03ddea4 100644 --- a/module/settings/autoUnpauseOnLoad.mjs +++ b/module/settings/autoUnpauseOnLoad.mjs @@ -1,17 +1,14 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; import { __ID__ } from "../consts.mjs"; import { Logger } from "../utils/Logger.mjs"; -import { registerDevSetting } from "../utils/SubMenuSettings.mjs"; +import { registerDevSetting } from "../utils/DevSettings.mjs"; const key = `autoUnpauseOnLoad`; export function autoUnpauseOnLoad() { - status[key] = SettingStatusEnum.Unknown; const prevented = Hooks.call(`${__ID__}.preventSetting`, key); if (!prevented) { Logger.log(`Preventing setting "${key}" from being registered`); - status[key] = SettingStatusEnum.Blocked; return; }; @@ -37,6 +34,4 @@ export function autoUnpauseOnLoad() { }; }); // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; }; diff --git a/module/settings/chatImageLinks.mjs b/module/settings/chatImageLinks.mjs deleted file mode 100644 index c25d56f..0000000 --- a/module/settings/chatImageLinks.mjs +++ /dev/null @@ -1,130 +0,0 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; -import { __ID__ } from "../consts.mjs"; -import { Logger } from "../utils/Logger.mjs"; - -const { DialogV2 } = foundry.applications.api; - -const key = `chatImageLinks`; -const IMAGE_TYPES = [ - `png`, - `jpg`, - `jpeg`, - `webp`, - `svg`, -]; - -export function chatImageLinks() { - status[key] = SettingStatusEnum.Unknown; - - const prevented = Hooks.call(`${__ID__}.preventSetting`, key); - if (!prevented) { - Logger.log(`Preventing setting "${key}" from being registered`); - status[key] = SettingStatusEnum.Blocked; - return; - }; - - // #region Registration - Logger.log(`Registering setting: ${key}`); - game.settings.register(__ID__, key, { - name: `OFT.setting.${key}.name`, - hint: `OFT.setting.${key}.hint`, - scope: `user`, - type: Boolean, - default: true, - config: true, - requiresReload: true, - }); - - game.settings.register(__ID__, key + `-showPromptAgain`, { - scope: `user`, - type: Boolean, - default: true, - config: false, - }); - // #endregion Registration - - // #region Implementation - if (game.settings.get(__ID__, key)) { - Logger.log(`setting:${key} | Adding text enricher`); - - // MARK: Enricher - const pattern = new RegExp( - `(? { - Logger.debug(url); - url = url[0].replace(/^image:\/\//, ``); - const secure = `https://${url}`; - const insecure = `http://${url}`; - - if (await isAcceptableImage(secure)) { - const img = document.createElement(`img`); - img.src = secure; - img.alt = secure; - return img; - }; - - if (await isAcceptableImage(insecure)) { - const img = document.createElement(`img`); - img.src = insecure; - img.alt = insecure; - return img; - }; - - return null; - }, - }); - - // MARK: Chat Input - // Hooks.on(`chatMessage`, (chatLog, message, options) => { - // if (!game.settings.get(__ID__, key)) { return }; - - // const match = message.match(pattern); - // if (!match) { return }; - - // DialogV2.wait({ - // rejectClose: false, - // content: game.i18n.localize(`OFT.dialogs.chatImageLinks.didYouKnowImageLink`), - // buttons: [ - // { action: ``, label: `OFT.dialogs.chatImageLinks.convertAndDontShowAgain` }, - // { action: ``, label: `OFT.dialogs.chatImageLinks.justConvert` }, - // { action: ``, label: `OFT.dialogs.chatImageLinks.ignoreAndDontShowAgain` }, - // { action: ``, label: `OFT.dialogs.chatImageLinks.disableEntirely` }, - // ], - // }) - // .then((selected) => { - // chatLog.processMessage(message, options); - // }); - - // return false; - // }); - } - // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; -}; - -// #region Helpers -async function isAcceptableImage(url) { - try { - const response = await fetch(url, { method: `HEAD` }); - const contentType = response.headers.get(`Content-Type`); - Logger.debug(`Image data:`, { url, contentType }); - let [ superType, subtype ] = contentType.split(`/`); - if (superType !== `image`) { - return false; - }; - if (subtype.includes(`+`)) { - subtype = subtype.split(`+`, 2).at(0); - }; - return IMAGE_TYPES.includes(subtype); - } catch { - return false; - }; -}; -// #endregion Helpers diff --git a/module/settings/chatSidebarBackground.mjs b/module/settings/chatSidebarBackground.mjs index 5fce77a..6fab03d 100644 --- a/module/settings/chatSidebarBackground.mjs +++ b/module/settings/chatSidebarBackground.mjs @@ -1,11 +1,9 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; import { __ID__ } from "../consts.mjs"; import { Logger } from "../utils/Logger.mjs"; const key = `chatSidebarBackground`; export function chatSidebarBackground() { - status[key] = SettingStatusEnum.Unknown; // #region Registration Logger.log(`Registering setting: ${key}`); @@ -30,6 +28,4 @@ export function chatSidebarBackground() { document.body.classList.add(`${__ID__}-${key}`); }; // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; }; diff --git a/module/settings/hotbarButtonGap.mjs b/module/settings/hotbarButtonGap.mjs index 98c7cbf..e381508 100644 --- a/module/settings/hotbarButtonGap.mjs +++ b/module/settings/hotbarButtonGap.mjs @@ -1,24 +1,20 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; import { __ID__ } from "../consts.mjs"; import { Logger } from "../utils/Logger.mjs"; -import { registerCategorySetting } from "../utils/SubMenuSettings.mjs"; const key = `hotbarButtonGap`; export function hotbarButtonGap() { - status[key] = SettingStatusEnum.Unknown; const prevented = Hooks.call(`${__ID__}.preventSetting`, key); if (!prevented) { Logger.log(`Preventing setting "${key}" from being registered`); - status[key] = SettingStatusEnum.Blocked; return; }; // #region Registration Logger.log(`Registering setting: ${key}`); document.body.classList.add(`${__ID__}-${key}`); - registerCategorySetting(`hotbar`, __ID__, key, { + game.settings.register(__ID__, key, { name: `OFT.setting.${key}.name`, hint: `OFT.setting.${key}.hint`, scope: `user`, @@ -40,6 +36,4 @@ export function hotbarButtonGap() { const buttonGap = game.settings.get(__ID__, key); document.body.style.setProperty(`--hotbar-button-gap`, `${buttonGap}px`); // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; }; diff --git a/module/settings/hotbarButtonSize.mjs b/module/settings/hotbarButtonSize.mjs index 7b4797b..6bd1bba 100644 --- a/module/settings/hotbarButtonSize.mjs +++ b/module/settings/hotbarButtonSize.mjs @@ -1,24 +1,20 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; import { __ID__ } from "../consts.mjs"; import { Logger } from "../utils/Logger.mjs"; -import { registerCategorySetting } from "../utils/SubMenuSettings.mjs"; const key = `hotbarButtonSize`; export function hotbarButtonSize() { - status[key] = SettingStatusEnum.Unknown; const prevented = Hooks.call(`${__ID__}.preventSetting`, key); if (!prevented) { Logger.log(`Preventing setting "${key}" from being registered`); - status[key] = SettingStatusEnum.Blocked; return; }; // #region Registration Logger.log(`Registering setting: ${key}`); document.body.classList.add(`${__ID__}-${key}`); - registerCategorySetting(`hotbar`, __ID__, key, { + game.settings.register(__ID__, key, { name: `OFT.setting.${key}.name`, hint: `OFT.setting.${key}.hint`, scope: `user`, @@ -40,6 +36,4 @@ export function hotbarButtonSize() { const hotbarSize = game.settings.get(__ID__, key); document.body.style.setProperty(`--hotbar-size`, `${hotbarSize}px`); // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; }; diff --git a/module/settings/preventMovementHistory.mjs b/module/settings/preventMovementHistory.mjs deleted file mode 100644 index 8f4d18c..0000000 --- a/module/settings/preventMovementHistory.mjs +++ /dev/null @@ -1,42 +0,0 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; -import { __ID__ } from "../consts.mjs"; -import { Logger } from "../utils/Logger.mjs"; - -const key = `preventMovementHistory`; - -export function preventMovementHistory() { - status[key] = SettingStatusEnum.Unknown; - - const prevented = Hooks.call(`${__ID__}.preventSetting`, key); - if (!prevented) { - Logger.log(`Preventing setting "${key}" from being registered`); - status[key] = SettingStatusEnum.Blocked; - return; - }; - - // #region Registration - Logger.log(`Registering setting: ${key}`); - game.settings.register(__ID__, key, { - name: `OFT.setting.${key}.name`, - hint: `OFT.setting.${key}.hint`, - scope: `world`, - type: Boolean, - default: false, - config: true, - reloadRequired: true, - }); - // #endregion Registration - - // #region Implementation - if (game.settings.get(__ID__, key)) { - class OFTTokenDocument extends CONFIG.Token.documentClass { - _shouldRecordMovementHistory() { - return false; - }; - }; - CONFIG.Token.documentClass = OFTTokenDocument; - }; - // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; -}; diff --git a/module/settings/preventTokenRotation.mjs b/module/settings/preventTokenRotation.mjs deleted file mode 100644 index 258920c..0000000 --- a/module/settings/preventTokenRotation.mjs +++ /dev/null @@ -1,53 +0,0 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; -import { __ID__ } from "../consts.mjs"; -import { Logger } from "../utils/Logger.mjs"; - -const key = `preventTokenRotation`; - -export function preventTokenRotation() { - status[key] = SettingStatusEnum.Unknown; - - const prevented = Hooks.call(`${__ID__}.preventSetting`, key); - if (!prevented) { - Logger.log(`Preventing setting "${key}" from being registered`); - status[key] = SettingStatusEnum.Blocked; - return; - }; - - /** @type {number|null} */ - let hookID = null; - - // #region Registration - Logger.log(`Registering setting: ${key}`); - game.settings.register(__ID__, key, { - name: `OFT.setting.${key}.name`, - hint: `OFT.setting.${key}.hint`, - scope: `world`, - type: Boolean, - default: true, - config: true, - requiresReload: false, - onChange: (newValue) => { - if (newValue) { - hookID = Hooks.on(`preMoveToken`, preMoveTokenHandler); - } else if (hookID != null) { - Hooks.off(`preMoveToken`, hookID); - }; - }, - }); - // #endregion Registration - - // #region Implementation - if (game.settings.get(__ID__, key)) { - hookID = Hooks.on(`preMoveToken`, preMoveTokenHandler); - }; - // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; -}; - -// #region Helpers -function preMoveTokenHandler(_token, update) { - update.autoRotate = false; -}; -// #endregion Helpers diff --git a/module/settings/preventUserConfigOpen.mjs b/module/settings/preventUserConfigOpen.mjs index 3b7646d..6377228 100644 --- a/module/settings/preventUserConfigOpen.mjs +++ b/module/settings/preventUserConfigOpen.mjs @@ -1,16 +1,13 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; import { __ID__ } from "../consts.mjs"; import { Logger } from "../utils/Logger.mjs"; const key = `preventUserConfigOpen`; export function preventUserConfigOpen() { - status[key] = SettingStatusEnum.Unknown; const prevented = Hooks.call(`${__ID__}.preventSetting`, key); if (!prevented) { Logger.log(`Preventing setting "${key}" from being registered`); - status[key] = SettingStatusEnum.Blocked; return; }; @@ -22,7 +19,7 @@ export function preventUserConfigOpen() { scope: `user`, type: Boolean, default: false, - config: !game.user.isGM, + config: true, requiresReload: false, }); // #endregion Registration @@ -35,6 +32,4 @@ export function preventUserConfigOpen() { }; }); // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; }; diff --git a/module/settings/repositionHotbar.mjs b/module/settings/repositionHotbar.mjs index cce0c5f..601e580 100644 --- a/module/settings/repositionHotbar.mjs +++ b/module/settings/repositionHotbar.mjs @@ -1,23 +1,19 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; import { __ID__ } from "../consts.mjs"; import { Logger } from "../utils/Logger.mjs"; -import { registerCategorySetting } from "../utils/SubMenuSettings.mjs"; const key = `repositionHotbar`; export function repositionHotbar() { - status[key] = SettingStatusEnum.Unknown; const prevented = Hooks.call(`${__ID__}.preventSetting`, key); if (!prevented) { Logger.log(`Preventing setting "${key}" from being registered`); - status[key] = SettingStatusEnum.Blocked; return; }; // #region Registration Logger.log(`Registering setting: ${key}`); - registerCategorySetting(`hotbar`, __ID__, key, { + game.settings.register(__ID__, key, { name: `OFT.setting.${key}.name`, hint: `OFT.setting.${key}.hint`, scope: `user`, @@ -46,6 +42,4 @@ export function repositionHotbar() { uiPosition.insertAdjacentElement(`beforeend`, container); }; // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; }; diff --git a/module/settings/startSidebarExpanded.mjs b/module/settings/startSidebarExpanded.mjs index 4cf9f2d..0e76033 100644 --- a/module/settings/startSidebarExpanded.mjs +++ b/module/settings/startSidebarExpanded.mjs @@ -1,11 +1,9 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; import { __ID__ } from "../consts.mjs"; import { Logger } from "../utils/Logger.mjs"; const key = `startSidebarExpanded`; export function startSidebarExpanded() { - status[key] = SettingStatusEnum.Unknown; // #region Registration Logger.log(`Registering setting: ${key}`); @@ -28,6 +26,4 @@ export function startSidebarExpanded() { }; }); // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; }; diff --git a/module/settings/startingSidebarTab.mjs b/module/settings/startingSidebarTab.mjs index 02fab17..94c6496 100644 --- a/module/settings/startingSidebarTab.mjs +++ b/module/settings/startingSidebarTab.mjs @@ -1,11 +1,9 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; import { __ID__ } from "../consts.mjs"; import { Logger } from "../utils/Logger.mjs"; const key = `startingSidebarTab`; export function startingSidebarTab() { - status[key] = SettingStatusEnum.Unknown; // #region Registration Logger.log(`Registering setting: ${key}`); @@ -44,19 +42,10 @@ export function startingSidebarTab() { // #region Implementation Hooks.once(`ready`, () => { const defaultTab = game.settings.get(__ID__, key); - if (defaultTab === ``) { return }; - - if (!(defaultTab in CONFIG.ui.sidebar.TABS)) { - Logger.error(`Failed to find starting tab with ID "${defaultTab}", skipping`); - return; - }; - if (defaultTab) { Logger.debug(`Changing tab to:`, defaultTab); ui.sidebar.changeTab(defaultTab, `primary`); }; }); // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; }; diff --git a/module/settings/toggleMouseBroadcast.mjs b/module/settings/toggleMouseBroadcast.mjs deleted file mode 100644 index 3761f47..0000000 --- a/module/settings/toggleMouseBroadcast.mjs +++ /dev/null @@ -1,126 +0,0 @@ -import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; -import { __ID__ } from "../consts.mjs"; -import { Logger } from "../utils/Logger.mjs"; - -const key = `toggleMouseBroadcast`; - -/** @type {number | null} */ -let notifID = null; - -export function toggleMouseBroadcast() { - status[key] = SettingStatusEnum.Unknown; - - // #region Registration - const prevented = Hooks.call(`${__ID__}.preventSetting`, key); - if (!prevented) { - Logger.log(`Preventing setting "${key}" from being registered`); - status[key] = SettingStatusEnum.Blocked; - return; - }; - Logger.log(`Registering setting: ${key}`); - - // MARK: setting - game.settings.register(__ID__, key, { - scope: `client`, - config: false, - default: true, - }); - - // MARK: keybind - game.keybindings.register(__ID__, key, { - name: `OFT.keybindings.${key}.name`, - hint: `OFT.keybindings.${key}.hint`, - precedence: CONST.KEYBINDING_PRECEDENCE.NORMAL, - restricted: true, - editable: [ - { key: `KeyH` }, - ], - onDown: (event) => { - if (!game.user.hasPermission(`SHOW_CURSOR`)) { return }; - event.preventDefault?.(); - const current = game.settings.get(__ID__, key); - - if (current) { - notifID = ui.notifications.warn( - `OFT.notifs.${key}.hidingCursor`, - { console: false, localize: true, permanent: true }, - ).id; - } else { - if (notifID != null) { - ui.notifications.remove(notifID); - notifID = null; - }; - ui.notifications.success( - `OFT.notifs.${key}.showingCursor`, - { console: false, localize: true }, - ); - }; - - game.settings.set(__ID__, key, !current); - - // Hide the existing cursor - game.user.broadcastActivity({ cursor: null }); - return true; - }, - }); - // #endregion Registration - - // #region Implementation - Hooks.on(`renderControlsConfig`, renderControlsConfigHandler); - Hooks.once(`ready`, readyHandler); - - class OFTControlsLayer extends CONFIG.Canvas.layers.controls.layerClass { - _onMouseMove(currentPos) { - if (!game.settings.get(__ID__, key)) { - game.user.broadcastActivity({}); - }; - super._onMouseMove(currentPos); - }; - }; - CONFIG.Canvas.layers.controls.layerClass = OFTControlsLayer; - - // #endregion Implementation - - status[key] = SettingStatusEnum.Registered; -}; - -// #region Helpers -const tabGroup = `categories`; - -/** - * Handle showing the "hiding your cursor" notification when the user - * connects to the server initially, allowing the current state to be - * correctly described to the user. - */ -function readyHandler() { - const hideCursor = !game.settings.get(__ID__, key); - const canShowCursor = game.user.hasPermission(`SHOW_CURSOR`); - if (hideCursor && canShowCursor) { - notifID = ui.notifications.warn( - `OFT.notifs.${key}.hidingCursor`, - { console: false, localize: true, permanent: true }, - ).id; - }; -}; - -/** - * Handles hiding the keybinding from the configuration if and when the user - * does not have the SHOW_CURSOR permission since this keybinding is really - * useless if they can't even broadcast their cursor in the first place. - */ -function renderControlsConfigHandler(_app, element) { - - if (game.user.hasPermission(`SHOW_CURSOR`)) { return }; - - const keybindingList = element.querySelector(`section[data-group="${tabGroup}"][data-tab="${__ID__}"]`); - const tabButton = element.querySelector(`button[data-group="${tabGroup}"][data-tab="${__ID__}"]`); - - const keybind = keybindingList.querySelector(`.form-group[data-action-id="${__ID__}.${key}"]`); - keybind?.remove(); - - if (keybindingList.childElementCount === 0) { - keybindingList.remove(); - tabButton.remove(); - }; -}; -// #endregion Helpers diff --git a/module/utils/DevSettings.mjs b/module/utils/DevSettings.mjs new file mode 100644 index 0000000..7d847fa --- /dev/null +++ b/module/utils/DevSettings.mjs @@ -0,0 +1,9 @@ +/** @type {Map} */ +export const devSettings = new Map(); + +export function registerDevSetting(namespace, key, config) { + const visible = config.config; + config.config = false; + game.settings.register(namespace, key, config); + devSettings.set(`${namespace}.${key}`, visible); +}; diff --git a/module/utils/SettingStatus.mjs b/module/utils/SettingStatus.mjs deleted file mode 100644 index d3f1dd5..0000000 --- a/module/utils/SettingStatus.mjs +++ /dev/null @@ -1,11 +0,0 @@ -/** @typedef {typeof SettingStatusEnum[keyof typeof SettingStatusEnum]} SettingStatus */ - -export const SettingStatusEnum = foundry.utils.deepFreeze({ - Registered: `registered`, - Blocked: `blocked`, - Incompatible: `incompatible`, - Unknown: `unknown`, -}); - -/** @type {Record} */ -export const status = {}; diff --git a/module/utils/SubMenuSettings.mjs b/module/utils/SubMenuSettings.mjs deleted file mode 100644 index 77d73f9..0000000 --- a/module/utils/SubMenuSettings.mjs +++ /dev/null @@ -1,22 +0,0 @@ -/** @type {Map>} */ -export const categories = new Map(); - -export function registerCategorySetting(category, namespace, key, config) { - let cat = categories.get(category); - if (!cat) { - cat = new Map(); - categories.set(category, cat); - }; - const visible = config.config; - config.config = false; - game.settings.register(namespace, key, config); - cat.set(`${namespace}.${key}`, visible); -}; - -/** - * A helper function that registers the setting to the "dev" - * category - */ -export function registerDevSetting(namespace, key, config) { - registerCategorySetting(`dev`, namespace, key, config); -}; diff --git a/styles/apps.css b/styles/apps.css deleted file mode 100644 index 5b2c628..0000000 --- a/styles/apps.css +++ /dev/null @@ -1,8 +0,0 @@ -.application.oft { - > .window-content.standard-form .setting-list { - flex-grow: 1; - display: flex; - flex-direction: column; - gap: 1rem; - } -} diff --git a/styles/main.css b/styles/main.css index 2312044..7c87f40 100644 --- a/styles/main.css +++ b/styles/main.css @@ -3,7 +3,5 @@ @import url("./hotbarButtonSize.css"); @import url("./repositionHotbar.css"); -@import url("./apps.css"); - /* Make the chat sidebar the same width as all the other tabs */ .chat-sidebar:not(.sidebar-popout) { width: unset; }