Game

Game

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.

Constructor

new Game(view, data, sessionId, socket)

Parameters:
Name Type Description
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

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

Members

activeTool :string

A convenient reference to the currently active canvas tool

Type:
  • string

audio :AudioHelper

A singleton instance of the Audio Helper class

Type:

canvas :Canvas

A singleton reference to the Canvas object which may be used.

Type:

collections :Collection.<string, WorldCollection>

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

Type:

combat :Combat

A convenience accessor for the currently viewed Combat encounter

Type:

data :Object

The object of world data passed from the server

Type:
  • Object

debug :boolean

Whether the Game is running in debug mode

Type:
  • boolean

gamepad :GamepadManager

The Gamepad Manager

Type:

i18n :Localization

Localization support

Type:

isAdmin :boolean

Is the current session user authenticated as an application administrator?

Type:
  • boolean

keybindings :ClientKeybindings

Client keybindings which are used to configure application behavior

Type:

keyboard :KeyboardManager

The Keyboard Manager

Type:

loading :boolean

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

Type:
  • boolean

modules :Map

A mapping of installed modules

Type:
  • Map

modules :Map.<string, Object>

A Map of active modules which are currently enabled in this World

Type:
  • Map.<string, Object>

mouse :MouseManager

The Mouse Manager

Type:

nue :NewUserExperience

The New User Experience manager.

Type:

packs :Collection.<string, CompendiumCollection>

A mapping of CompendiumCollection instances, one per Compendium pack.

Type:

paused :boolean

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

Type:
  • boolean

permissions :Object

The user role permissions setting

Type:
  • Object

ready :boolean

A flag for whether the Game has successfully reached the "ready" hook

Type:
  • boolean

release :ReleaseData

The Release data for this version of Foundry

Type:

sessionId :string

The client session id which is currently active

Type:
  • string

settings :ClientSettings

Client settings which are used to configure application behavior

Type:

socket :WebSocket|null

A reference to the open Socket.io connection

Type:
  • WebSocket | null

time :GameTime

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

Type:

user :User|null

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

Type:

userId :string

The id of the active World user, if any

Type:
  • string

version

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

video :VideoHelper

A singleton instance of the Video Helper class

Type:

view :string

The named view which is currently active. Game views include: join, setup, players, license, game, stream

Type:
  • string

Methods

(async, static) connect(sessionId) → {Promise.<object>}

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

Parameters:
Name Type Description
sessionId string

The client session ID with which to establish the connection

Returns:

A promise which resolves to the connected socket, if successful

Type
Promise.<object>

(async, static) create(view, sessionId) → {Promise.<Game>}

Fetch World data and return a Game instance

Parameters:
Name Type Description
view string

The named view being created

sessionId string | null

The current sessionId of the connecting client

Returns:

A Promise which resolves to the created Game instance

Type
Promise.<Game>

(static) getCookies() → {Object}

Retrieve the cookies which are attached to the client session

Returns:

The session cookies

Type
Object

(async, static) getData(socket, view) → {Promise.<object>}

Request World data from server and return it

Parameters:
Name Type Description
socket Socket

The active socket connection

view string

The view for which data is being requested

Returns:
Type
Promise.<object>

(async, static) getWorldStatus() → {Promise.<boolean>}

Get the current World status upon initial connection.

Returns:
Type
Promise.<boolean>

activateListeners()

Activate Event Listeners which apply to every Game View

activateSocketListeners()

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

getPackageScopes() → {Array.<string>}

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

Returns:

An array of string package scopes

Type
Array.<string>

(async) initialize()

Initialize the Game for the current window location

(async) initializeCanvas() → {Promise.<void>}

Initialize the game Canvas

Returns:
Type
Promise.<void>

initializeDocuments()

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

initializeGamepads()

Initialize Gamepad controls

initializeKeyboard()

Initialize Keyboard controls

initializeMouse()

Initialize Mouse controls

initializePacks() → {Collection.<string, CompendiumCollection>}

Initialize the Compendium packs which are present within this Game Create a Collection which maps each Compendium pack using it's collection ID

Returns:
Type
Collection.<string, CompendiumCollection>

initializeRTC()

Initialize the WebRTC implementation

initializeUI()

Initialize core UI elements

logOut()

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

registerSettings()

Register core game settings

scaleFonts(indexopt)

Scale the base font size according to the user's settings.

Parameters:
Name Type Attributes Description
index number <optional>

Optionally supply a font size index to use, otherwise use the user's setting. Available font sizes, starting at index 1, are: 8, 10, 12, 14, 16, 18, 20, 24, 28, and 32.

(async) setupGame() → {Promise.<void>}

Fully set up the game state, initializing Documents, UI applications, and the Canvas

Returns:
Type
Promise.<void>

setupPackages()

Configure package data that is currently enabled for this world

(async) shutDown() → {Promise.<void>}

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

Returns:
Type
Promise.<void>

toggleCharacterSheet() → {ActorSheet|null}

Open Character sheet for current token or controlled actor

Returns:

The ActorSheet which was toggled, or null if the User has no character

Type
ActorSheet | null

togglePause(pause, pushopt)

Toggle the pause state of the game Trigger the pauseGame Hook when the paused state changes

Parameters:
Name Type Attributes Default Description
pause boolean

The desired pause state. When true, the game will be paused, when false the game will be un-paused.

push boolean <optional>
false

Push the pause state change to other connected clients? Requires an GM user.