import { SettingStatusEnum, status } from "../utils/SettingStatus.mjs"; import { __ID__ } from "../consts.mjs"; import { Logger } from "../utils/Logger.mjs"; import { preventTweakRegistration } from "../utils/preRegisterTweak.mjs"; import { SidebarTabRearranger } from "../apps/SidebarTabRearranger.mjs"; export const key = `rearrangeSidebarTabs`; export function rearrangeSidebarTabs() { status[key] = SettingStatusEnum.Unknown; if (preventTweakRegistration(key)) { return }; // #region Registration Logger.log(`Registering tweak: ${key}`); game.settings.registerMenu(__ID__, `${key}Menu`, { name: `OFT.menu.${key}.name`, hint: `OFT.menu.${key}.hint`, label: `OFT.menu.${key}.label`, restricted: false, type: SidebarTabRearranger, }); game.settings.register(__ID__, `${key}World`, { scope: `world`, config: false, type: Array, }); game.settings.register(__ID__, `${key}User`, { scope: `user`, config: false, type: Array, }); // #endregion Registration // #region Implementation updateTabOrder(); // #endregion Implementation status[key] = SettingStatusEnum.Registered; }; function updateTabOrder() { const order = game.settings.get(__ID__, `${key}User`) ?? game.settings.get(__ID__, `${key}World`) ?? null; if (!order) { return }; const tabs = CONFIG.ui.sidebar.TABS; const replaced = {}; // Sort all of the tabs that are provided for (const tabID of order) { if (!tabs[tabID]) { continue }; replaced[tabID] = tabs[tabID]; }; // Add any tabs that are not in the ordering yet for (const tabID in tabs) { if (replaced[tabID] != null) { continue }; replaced[tabID] = tabs[tabID]; }; CONFIG.ui.sidebar.TABS = replaced; };