Hooks
⚠️
This page is under construction.
⚠️
Beta feature, subject to change.
Hooks are a way to inject custom logic into the game. It is useful for creating plugins.
game.hooks.hook("init", () => {
console.log("Game initialized");
});
Public Methods
hook
Add a hook to the game.
const token = game.hooks.hook("init", () => {
console.log("Game initialized");
});
return function cleanup() {
token.cancel();
}
key: Hooks
- The key of the hook. For a list of keys, see the Hooks section.hook: (...value: T[K]) => VoidFunction | void
- The callback function that returns a cleanup function.- Returns
LiveGameEventToken
- See LiveGameEventToken
unhook
Remove a hook from the game.
const listener = function () { /* ... */ };
game.hooks.hook("init", listener); // add a hook
game.hooks.unhook("init", listener); // remove the hook
key: Hooks
- The key of the hook. For a list of keys, see the Hooks section.listener: (...value: T[K]) => VoidFunction | void
- The listener function that was added to the hook.
Hooks
init
This hook is called when the game is initialized and before the player has rendered.
game.hooks.hook("init", () => {
console.log("let's do something cool here");
});
preloadImage
This hook is called when preloading images. This is useful for creating proxy logic for images.
src: string
- The source of the image.set: (src: string, options?: RequestInit) => void
- A function to set the image source.
game.hooks.hook("preloadImage", (src, set) => {
const newSrc = `https://example.com/proxy?url=${src}`;
set(newSrc, {
credentials: "include",
});
});