Base class used to operate the game engine

Type Parameters

  • T extends PlayerSessionType

    A type of player session

Hierarchy (View Summary)

Constructors

  • Create a new instance of the game service

    Type Parameters

    • T extends PlayerSessionType

    Parameters

    • sessionAlias: string

      Alias used to distingish stored players sessions

    Returns BaseGameService<T>

Properties

_actions: Map<string, ActionClass>

Map of action aliases to a specific action class

_gameObjects: Map<string, GameObjectClass>

Map of game object aliases to a specific game object class

_sessionAlias: string

Alias used to distingish stored players sessions

Methods

  • Create a new player session object

    Returns T

    New player session object

  • Create a new player session middleware for Express

    Returns ExpressMiddleware

    Middleware instance for Express

    This middleware does this following:

    • Associate a player session of type T with a request, based on the provided X-PlayerSessionId-header.
    • Regularly persist player sessions as JSON-files on the file system

    Keep in mind this middleware is not secure by any means, meaning the X-PlayerSessionId-header can be easily manipulated.

  • Exectute an action and get its result

    Parameters

    • alias: string

      Alias of the action to execute

    • gameObjects: GameObject[]

      List of game objects to execute the action on

    Returns SyncOrAsync<undefined | ActionResult>

    Result of the action or undefined when unhandled.

  • Get a game object instance by its alias

    Parameters

    • alias: string

      Game object alias

    Returns undefined | GameObject

    Game object instance or undefined when not found

  • Get a list of game objects instances by their alias

    Parameters

    • aliases: string[]

      List of game object aliases

    Returns GameObject[]

    List of game object instances. Can be empty when no game objects were found.

  • Get the player session from the current request

    Returns T

    Player session from the current request

  • Register an action class

    Parameters

    • actionClass: ActionClass

      Action class

    Returns void

  • Register a game object class

    Parameters

    • gameObjectClass: GameObjectClass

      Game object class

    Returns void

  • Reset the player session

    Returns void