Documentation
Game

Game

⚠️

This page is under construction.

Game is the main class that represents the game itself. It contains all the game's configuration and LiveGames

Game use Singleton pattern, so you can get the instance by calling hook useGame()

Public Properties

preference

the Preference instance

game.preference.setPreference("autoForward", true);

Public Methods

getLiveGame

  • return: LiveGame - the LiveGame instance

configure

Assign a new configuration to the game

Note: This method is designed to be used before the game is initialized.

Calling this method after the game is initialized will not take effect or not taking effect immediately. Settings in the Preference will take effect immediately.

const { game } = useGame();
 
useEffect(() => {
    game.configure({
        ratioUpdateInterval: 0, // update the player size immediately
 
        /* cursor */
        cursor: "cursor.jpeg",
        cursorHeight: 60,
        cursorWidth: 60,
    });
}, []);

use

Register a plugin to the game.

Note: Plugins with the same name will not be registered.

A name consists of namespace and name is recommended.
Ex: "@Namespace/PluginName", "@Author/PluginName", "PluginName"

game.use({
    ... /** plugin register config */
});

dispose

Dispose the game and release all the resources.

Note: This action is irreversible.

game.dispose();

configureAndFreeze

Configure the game and freeze specific fields to prevent further modifications.

Warning: This method is not recommended to be used without using NarraLeaf Engine or Plugin Environment.

game.configureAndFreeze({
    ratioUpdateInterval: 0,
    cursor: "cursor.jpeg"
});
  • config: DeepPartial<GameConfig> - The game configuration to apply and freeze

freeze

Freeze specific configuration fields to prevent further modifications.

Warning: This method is not recommended to be used without using NarraLeaf Engine or Plugin Environment.

game.freeze(["ratioUpdateInterval", "cursor"]);
  • fields: (StringKeyOf<GameConfig>)[] - Array of configuration field names to freeze