UNPKG

narraleaf-react

Version:

A React visual novel player framework

80 lines (79 loc) 2.51 kB
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"; 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]; }; export declare class Game { static GameSettingsNamespace: typeof GameSettingsNamespace; readonly hooks: Hooks<GameHooks>; /** * Game settings */ preference: Preference<GamePreference>; /** * Plugin registry */ plugins: Plugins; /** * Create a new game * @param config - Game configuration */ constructor(config: DeepPartial<GameConfig>); /** * Configure the game */ configure(config: DeepPartial<GameConfig>): 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<GameConfig>): 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<GameConfig>)[]): 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 };