The core Game instance which encapsulates the data, settings, and states relevant for managing the game experience. The singleton instance of the Game class is available as the global variable game.

Constructors

  • Initialize a singleton Game instance for a specific view using socket data retrieved from the server.

    Parameters

    • view: string

      The named view which is active for this game instance.

    • data: object

      An object of all the World data vended by the server when the client first connects

    • sessionId: string

      The ID of the currently active client session retrieved from the browser cookie

    • socket: Socket<DefaultEventsMap, DefaultEventsMap>

      The open web-socket which should be used to transact game-state data

    Returns Game

Properties

actors: Actors

The collection of Actor documents which exists in the World.

The singleton Audio Helper.

canvas: canvas.Canvas

The singleton game Canvas.

cards: CardStacks

The collection of Cards documents which exists in the World.

clipboard: ClipboardHelper

The singleton Clipboard Helper.

collections: Collection<string, WorldCollection>

A mapping of WorldCollection instances, one per primary Document type.

The collection of Combat documents which exists in the World.

compendiumArt: CompendiumArt

The singleton compendium art manager.

compendiumUUIDRedirects: StringTree

The UUID redirects tree.

data: object

The object of world data passed from the server.

debug: boolean = false

Whether the Game is running in debug mode

documentIndex: DocumentIndex

The singleton DocumentIndex instance.

folders: Folders

The collection of Folder documents which exists in the World.

The singleton Gamepad Manager.

Localization support.

issues: ClientIssues

The singleton ClientIssues manager.

items: Items

The collection of Item documents which exists in the World.

journal: Journal

The collection of JournalEntry documents which exists in the World.

keybindings: ClientKeybindings

Client keybindings which are used to configure application behavior

keyboard: KeyboardManager

The singleton Keyboard Manager.

loading: boolean = false

A flag for whether texture assets for the game canvas are currently loading

macros: Macros

The collection of Macro documents which exists in the World.

messages: ChatMessages

The collection of ChatMessage documents which exists in the World.

modules: Collection<string, Module>

A Map of active Modules which are currently eligible to be enabled in this World. The subset of Modules which are designated as active are currently enabled.

The singleton Mouse Manager.

The singleton New User Experience manager.

A mapping of CompendiumCollection instances, one per Compendium pack.

permissions: Record<string, number[]>

The user role permissions setting.

playlists: Playlists

The collection of Playlist documents which exists in the World.

ready: boolean = false

A flag for whether the Game has successfully reached the hookEvents.ready hook

release: ReleaseData

The Release data for this version of Foundry

scenes: Scenes

The collection of Scene documents which exists in the World.

sessionId: string

The client session id which is currently active.

settings: ClientSettings

Client settings which are used to configure application behavior.

socket: null | Socket<DefaultEventsMap, DefaultEventsMap>

A reference to the open Socket.io connection.

system: System

The System which is used to power this game World.

tables: RollTables

The collection of RollTable documents which exists in the World.

time: GameTime

A singleton GameTime instance which manages the progression of time within the game world.

The singleton TooltipManager.

The singleton Tours collection.

userId: null | string

The id of the active World user, if any.

users: Users

The collection of User documents which exists in the World.

The singleton Video Helper.

view:
    | "game"
    | "stream"
    | "auth"
    | "license"
    | "setup"
    | "players"
    | "join"
    | "update"

The named view which is currently active.

workers: WorkerManager

A singleton web Worker manager.

world: World

The game World which is currently active.

Accessors

  • get activeTool(): string

    A convenient reference to the currently active canvas tool

    Returns string

  • get compendiumConfiguration(): WorldCompendiumConfiguration

    A shortcut to compendiumConfiguration data settings

    Returns WorldCompendiumConfiguration

  • get documentTypes(): Record<string, string[]>

    A registry of document types supported by the active world.

    Returns Record<string, string[]>

  • get isAdmin(): boolean

    Is the current session user authenticated as an application administrator?

    Returns boolean

  • get model(): Record<string, Record<string, object>>

    A registry of document sub-types and their respective template.json defaults.

    Returns Record<string, Record<string, object>>

  • get paused(): boolean

    A state variable which tracks whether the game session is currently paused

    Returns boolean

  • get user(): null | documents.User

    The currently connected User document, or null if Users is not yet initialized

    Returns null | documents.User

  • get version(): string

    Returns the current version of the Release, usable for comparisons using isNewerVersion

    Returns string

Methods

  • Internal

    Initialize elements required for the current view

    Returns Promise<void>

  • Activate Event Listeners which apply to every Game View

    Returns void

  • Activate Socket event listeners which are used to transact game state data with the server

    Returns void

  • Configure custom cursors.

    Returns void

  • Return the named scopes which can exist for packages. Scopes are returned in the prioritization order that their content is loaded.

    Returns string[]

    An array of string package scopes

  • Initialize the Game for the current window location, triggering the hookEvents.init event.

    Returns Promise<void>

  • Initialize the game Canvas

    Returns Promise<void>

  • Initialize configuration state.

    Returns void

  • Initialize game state data by creating WorldCollection instances for every primary Document type

    Returns void

  • Initialize Gamepad controls

    Returns void

  • Initialize Keyboard controls

    Returns void

  • Initialize Mouse controls

    Returns void

  • Initialize the Compendium packs which are present within this Game Create a Collection which maps each Compendium pack using its collection ID.

    Returns CompendiumPacks

  • Initialize the WebRTC implementation

    Returns Promise<boolean>

  • Initialize collection trees.

    Returns void

  • Initialize core UI elements

    Returns void

  • Log out of the game session by returning to the Join screen

    Returns void

  • Register core game settings

    Returns void

  • Fully set up the game state, initializing Documents, UI applications, and the Canvas. Triggers the hookEvents.setup and hookEvents.ready events.

    Returns Promise<void>

  • Configure package data that is currently enabled for this world

    Parameters

    • data: object

      Game data provided by the server socket

    Returns void

  • Shut down the currently active Game. Requires GameMaster user permission.

    Returns Promise<void>

  • Toggle the pause state of the game, triggering the hookEvents.pauseGame hook when the paused state changes.

    Parameters

    • pause: boolean

      The desired pause state; true for paused, false for un-paused

    • Optionaloptions: { broadcast?: boolean; userId?: string } = {}

      Additional options which modify the pause operation

      • Optionalbroadcast?: boolean

        Broadcast the pause state change to other connected clients? Broadcasting to other clients can only be done by a GM user.

      • OptionaluserId?: string

        The ID of the user who triggered the pause operation. This is populated automatically by the game server.

    Returns boolean

    The new paused state

  • Protected

    On left mouse clicks, check if the element is contained in a valid hyperlink and open it in a new tab.

    Parameters

    • event: PointerEvent

    Returns void

  • Establish a live connection to the game server through the socket.io URL

    Parameters

    • sessionId: string

      The client session ID with which to establish the connection

    Returns Promise<Socket<DefaultEventsMap, DefaultEventsMap>>

    A promise which resolves to the connected socket, if successful

  • Fetch World data and return a Game instance

    Parameters

    • view: string

      The named view being created

    • sessionId: null | string

      The current sessionId of the connecting client

    Returns Promise<Game>

    A Promise which resolves to the created Game instance

  • Retrieve the cookies which are attached to the client session

    Returns object

    The session cookies

  • Request World data from server and return it

    Parameters

    • socket: Socket<DefaultEventsMap, DefaultEventsMap>

      The active socket connection

    • view: string

      The view for which data is being requested

    Returns Promise<object>

  • Get the current World status upon initial connection.

    Parameters

    • socket: Socket<DefaultEventsMap, DefaultEventsMap>

      The active client socket connection

    Returns Promise<boolean>