import type { GameConfig, GamePreference } from "./gameTypes"; import { DeepPartial, Hooks, StringKeyOf } from "../../util/data"; import { LogicAction } from "./action/logicAction"; import { LiveGame } from "./game/liveGame"; import { Preference } from "./game/preference"; import { Plugins, IGamePluginRegistry } from "./game/plugin/plugin"; import { LayoutRouter } from "../player/lib/PageRouter/router"; import { KeyMap } from "./game/keyMap"; declare enum GameSettingsNamespace { game = "game" } export type GameHooks = { /** * Hook when the game is initialized * * This hook's behavior is similar to the `useEffect` hook in React. It will be called twice when the strict mode is enabled. * It is used to configure the game. */ "init": []; /** * Hook when preloading images * * @param src - The source of the image * @param set - Calling this function will set the src and options of the fetch request. This is useful to proxy * - **Note**: "signal" is preserved from the original options */ "preloadImage": [src: string, set: (src: string, options?: RequestInit) => void]; /** * Hook before deserializing the game state */ "beforeRestore": []; /** * Hook after deserializing the game state */ "afterRestore": []; }; export declare class Game { static GameSettingsNamespace: typeof GameSettingsNamespace; readonly hooks: Hooks; /** * Game settings */ preference: Preference; /** * Game key bindings */ keyMap: KeyMap; /** * Plugin registry */ plugins: Plugins; router: LayoutRouter; /** * Create a new game * @param config - Game configuration */ constructor(config: DeepPartial); /** * Configure the game */ configure(config: DeepPartial): this; /** * Configure the game and freeze the fields * * This method is not recommended to be used without using NarraLeaf Engine or Plugin Environment. * @param config - Game configuration */ configureAndFreeze(config: DeepPartial): this; /** * Freeze the fields * * This method is not recommended to be used without using NarraLeaf Engine or Plugin Environment. * @param fields - The fields to freeze */ freeze(fields: (StringKeyOf)[]): this; /** * Use a plugin * @param plugin - The plugin to use */ use(plugin: IGamePluginRegistry): this; getLiveGame(): LiveGame; /** * Dispose the game and all its resources * * **Note**: This action is irreversible. */ dispose(): void; } declare const _default: { Game: typeof Game; LiveGame: typeof LiveGame; }; export default _default; export type { LogicAction };