Move the tweak prevention into a helper function and rename the module hooks w/ compatibility code

This commit is contained in:
Oliver 2025-12-18 22:32:46 -07:00
parent 3d4376aa81
commit 9c8b6f37f9
20 changed files with 102 additions and 102 deletions

View file

@ -1,6 +1,6 @@
// Settings
import { preventMovementHistory } from "../settings/preventMovementHistory.mjs";
import { toggleMouseBroadcast } from "../settings/toggleMouseBroadcast.mjs";
import { preventMovementHistory } from "../tweaks/preventMovementHistory.mjs";
import { toggleMouseBroadcast } from "../tweaks/toggleMouseBroadcast.mjs";
// Utils
import { Logger } from "../utils/Logger.mjs";

View file

@ -0,0 +1,19 @@
/*
This hook is used to give external modules or systems the ability to interact
with the tweak registration lifecycle to do something before a tweak is registered
or being able to prevent registration of incompatible tweaks.
The hook receives a string indicating which tweak this hook is being called for
and a boolean value indicating if the tweak is considered invasive. Returning
explicit false prevents that tweak from being registered.
Invasive tweaks are additions that manipulate or override Document or helper
classes. An example of an invasive tweak is the "toggleMouseBroadcast",
tweak which replaces the existing "CONFIG.Canvas.layers.controls.layerClass"
class, most of these tweaks do smartly extend from the same CONFIG class
that they replace, however if they override a part of the class that
other modules/systems rely on, then that is a good time to block that
specific tweak's registration.
Call Signature: (tweakKey: string, isInvasive: boolean) => (void | boolean)
*/

View file

@ -1,12 +0,0 @@
/*
This hook is used for invasive hooks that we want to provide the
option for systems and other modules to be able to disable in case
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.
Call Signature: (settingKey: string) => (void | boolean)
*/

View file

@ -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<string, boolean>) => void
*/

View file

@ -0,0 +1,9 @@
/*
This hook is used to broadcast the final status of all tweaks within the module,
allowing them to either confirm their registration didn't happen or to do
something once all of the module setup has been finalized. Tweak statuses cannot
be blocked or changed from this hook, to prevent a tweak from being registered
you should use the "oft.preRegisterTweak" hook.
Call Signature: (settings: Record<string, string>) => void
*/

View file

@ -1,15 +1,15 @@
// 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";
import { addGlobalDocReferrer } from "../tweaks/addGlobalDocReferrer.mjs";
import { autoUnpauseOnLoad } from "../tweaks/autoUnpauseOnLoad.mjs";
import { chatImageLinks } from "../tweaks/chatImageLinks.mjs";
import { chatSidebarBackground } from "../tweaks/chatSidebarBackground.mjs";
import { hotbarButtonGap } from "../tweaks/hotbarButtonGap.mjs";
import { hotbarButtonSize } from "../tweaks/hotbarButtonSize.mjs";
import { preventTokenRotation } from "../tweaks/preventTokenRotation.mjs";
import { preventUserConfigOpen } from "../tweaks/preventUserConfigOpen.mjs";
import { repositionHotbar } from "../tweaks/repositionHotbar.mjs";
import { startingSidebarTab } from "../tweaks/startingSidebarTab.mjs";
import { startSidebarExpanded } from "../tweaks/startSidebarExpanded.mjs";
// Apps
import { DevSettingsMenu } from "../apps/DevSettingsMenu.mjs";
@ -51,7 +51,16 @@ Hooks.on(`setup`, () => {
preventTokenRotation();
preventUserConfigOpen();
Hooks.callAll(`oft.settingStatuses`, deepFreeze(status));
// Compatibility Code
if (Hooks.events[`oft.settingStatuses`] != null) {
foundry.utils.logCompatibilityWarning(
`The hook "${__ID__}.settingStatuses" has been renamed "${__ID__}.tweakStatuses".`,
{ since: `v1.2.0`, until: `v2.0.0`, stack: false, once: true },
);
Hooks.callAll(`oft.settingStatuses`, deepFreeze(status));
};
Hooks.callAll(`${__ID__}.tweakStatuses`, deepFreeze(status));
game.modules.get(__ID__).api = deepFreeze({
settings: status,
});