Add setting to disable token auto-rotation (closes #12)

This commit is contained in:
Oliver 2025-12-09 20:59:46 -07:00
parent 2484f6a598
commit baea567f24
3 changed files with 55 additions and 1 deletions

View file

@ -21,6 +21,10 @@
"name": "Hotbar Button Size", "name": "Hotbar Button Size",
"hint": "(v13+) Changes the size of the hotbar buttons to a size you prefer." "hint": "(v13+) Changes the size of the hotbar buttons to a size you prefer."
}, },
"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": { "preventUserConfigOpen": {
"name": "Prevent Auto User Config", "name": "Prevent Auto User Config",
"hint": "(v13+) 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."

View file

@ -7,6 +7,7 @@ import { autoUnpauseOnLoad } from "./settings/autoUnpauseOnLoad.mjs";
import { chatSidebarBackground } from "./settings/chatSidebarBackground.mjs"; import { chatSidebarBackground } from "./settings/chatSidebarBackground.mjs";
import { hotbarButtonGap } from "./settings/hotbarButtonGap.mjs"; import { hotbarButtonGap } from "./settings/hotbarButtonGap.mjs";
import { hotbarButtonSize } from "./settings/hotbarButtonSize.mjs"; import { hotbarButtonSize } from "./settings/hotbarButtonSize.mjs";
import { preventTokenRotation } from "./settings/preventTokenRotation.mjs";
import { preventUserConfigOpen } from "./settings/preventUserConfigOpen.mjs"; import { preventUserConfigOpen } from "./settings/preventUserConfigOpen.mjs";
import { repositionHotbar } from "./settings/repositionHotbar.mjs"; import { repositionHotbar } from "./settings/repositionHotbar.mjs";
import { startingSidebarTab } from "./settings/startingSidebarTab.mjs"; import { startingSidebarTab } from "./settings/startingSidebarTab.mjs";
@ -14,10 +15,10 @@ import { startSidebarExpanded } from "./settings/startSidebarExpanded.mjs";
// Apps // Apps
import { DevSettingsMenu } from "./apps/DevSettingsMenu.mjs"; import { DevSettingsMenu } from "./apps/DevSettingsMenu.mjs";
import { HotbarSettingsMenu } from "./apps/HotbarSettingsMenu.mjs";
// Misc // Misc
import { __ID__ } from "./consts.mjs"; import { __ID__ } from "./consts.mjs";
import { HotbarSettingsMenu } from "./apps/HotbarSettingsMenu.mjs";
Hooks.on(`setup`, () => { Hooks.on(`setup`, () => {
@ -45,5 +46,6 @@ Hooks.on(`setup`, () => {
chatSidebarBackground(); chatSidebarBackground();
startSidebarExpanded(); startSidebarExpanded();
startingSidebarTab(); startingSidebarTab();
preventTokenRotation();
preventUserConfigOpen(); preventUserConfigOpen();
}); });

View file

@ -0,0 +1,48 @@
import { __ID__ } from "../consts.mjs";
import { Logger } from "../utils/Logger.mjs";
const key = `preventTokenRotation`;
export function preventTokenRotation() {
const prevented = Hooks.call(`${__ID__}.preventSetting`, key);
if (!prevented) {
Logger.log(`Preventing setting "${key}" from being registered`);
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
};
// #region Helpers
function preMoveTokenHandler(_token, update) {
update.autoRotate = false;
};
// #endregion Helpers