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

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

    Returns Game

Properties

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

The named view which is currently active.

data: object

The object of world data passed from the server.

sessionId: string

The client session id which is currently active.

socket: WebSocket

A reference to the open Socket.io connection.

userId: string

The id of the active World user, if any.

world: World

The game World which is currently active.

system: System

The System which is used to power this game World.

modules: Map<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.

packs: any

A mapping of CompendiumCollection instances, one per Compendium pack.

documentIndex: DocumentIndex

The singleton DocumentIndex instance.

compendiumUUIDRedirects: StringTree

The UUID redirects tree.

collections: Collection<string, WorldCollection>

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

actors: Actors

The collection of Actor documents which exists in the World.

cards: CardStacks

The collection of Cards documents which exists in the World.

The collection of Combat documents which exists in the World.

folders: Folders

The collection of Cards documents which exists in the World.

items: Items

The collection of Item documents which exists in the World.

journal: Journal

The collection of JournalEntry documents which exists in the World.

macros: Macros

The collection of Macro documents which exists in the World.

messages: Messages

The collection of ChatMessage documents which exists in the World.

playlists: Playlists

The collection of Playlist documents which exists in the World.

scenes: Scenes

The collection of Scene documents which exists in the World.

tables: RollTables

The collection of RollTable documents which exists in the World.

users: Users

The collection of User documents which exists in the World.

release: ReleaseData

The Release data for this version of Foundry

debug: boolean = false

Whether the Game is running in debug mode

loading: boolean = false

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

permissions: object

The user role permissions setting.

ready: boolean = false

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

compendiumArt: CompendiumArt

The singleton compendium art manager.

audio: AudioHelper

The singleton Audio Helper.

canvas: Canvas

The singleton game Canvas.

clipboard: ClipboardHelper

The singleton Clipboard Helper.

Localization support.

issues: ClientIssues

The singleton ClientIssues manager.

The singleton Gamepad Manager.

keyboard: KeyboardManager

The singleton Keyboard Manager.

keybindings: ClientKeybindings

Client keybindings which are used to configure application behavior

The singleton Mouse Manager.

The singleton New User Experience manager.

settings: ClientSettings

Client settings which are used to configure application behavior.

time: GameTime

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

The singleton TooltipManager.

tours: Tours

The singleton Tours collection.

The singleton Video Helper.

workers: WorkerManager

A singleton web Worker manager.

#socketEventBuffer: (readonly [string, any])[] = []

An array of buffered events which are received by the socket before the game is ready to use that data. Buffered events are replayed in the order they are received until the buffer is empty.

Accessors

  • get model(): Record<string, Record<string, object>>
  • A registry of document sub-types and their respective data models.

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

  • get documentTypes(): Record<string, string[]>
  • A registry of document types supported by the active world.

    Returns Record<string, string[]>

  • get version(): string
  • Returns the current version of the Release, usable for comparisons using isNewerVersion

    Returns string

  • get isAdmin(): boolean
  • Is the current session user authenticated as an application administrator?

    Returns boolean

  • get user(): User
  • The currently connected User document, or null if Users is not yet initialized

    Returns User

  • get combat(): Combat
  • A convenience accessor for the currently viewed Combat encounter

    Returns Combat

  • get paused(): boolean
  • A state variable which tracks whether the game session is currently paused

    Returns boolean

  • get activeTool(): string
  • A convenient reference to the currently active canvas tool

    Returns string

Methods

  • Configure package data that is currently enabled for this world

    Parameters

    • data: object

      Game data provided by the server socket

    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

    Returns Promise<void>

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

    Returns Promise<void>

  • Fully set up the game state, initializing Documents, UI applications, and the 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 the Compendium packs which are present within this Game Create a Collection which maps each Compendium pack using it's collection ID

    Returns Collection<string, CompendiumCollection>

  • Initialize the WebRTC implementation

    Returns Promise<boolean>

  • Initialize core UI elements

    Returns void

  • Initialize the game Canvas

    Returns Promise<void>

  • Initialize Keyboard controls

    Returns void

  • Initialize Mouse controls

    Returns void

  • Initialize Gamepad controls

    Returns void

  • Register core game settings

    Returns void

  • Register core Tours

    Returns Promise<void>

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

    Parameters

    • pause: boolean

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

    • Optional push: boolean = false

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

    Returns boolean

    The new paused state

  • Open Character sheet for current token or controlled actor

    Returns ActorSheet

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

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

    Returns void

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

    Parameters

    • Optional index: number

      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.

    Returns void

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

    Returns void

  • Activate Event Listeners which apply to every Game View

    Returns void

  • Set the global CSS theme according to the user's preferred color scheme settings.

    Returns void

  • Private

    Handle a hot reload request from the server

    Parameters

    Returns void

  • Handle hot reloading of CSS files

    Parameters

    Returns void

  • Handle hot reloading of HTML files, such as Handlebars templates

    Parameters

    Returns void

  • Handle hot reloading of JSON files, such as language files

    Parameters

    Returns void

  • Private

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

    Parameters

    • event: MouseEvent

    Returns void

  • Private

    Prevent starting a drag and drop workflow on elements within the document unless the element has the draggable attribute explicitly defined or overrides the dragstart handler.

    Parameters

    • event: DragEvent

      The initiating drag start event

    Returns boolean

  • Private

    Disallow dragging of external content onto anything but a file input element

    Parameters

    • event: DragEvent

      The requested drag event

    Returns void

  • Private

    Disallow dropping of external content onto anything but a file input element

    Parameters

    • event: DragEvent

      The requested drag event

    Returns void

  • Private

    On a left-click event, remove any currently displayed inline roll tooltip

    Parameters

    • event: PointerEvent

      The mousedown pointer event

    Returns any

  • Private

    Fallback handling for mouse-up events which aren't handled further upstream.

    Parameters

    • event: PointerEvent

      The mouseup pointer event

    Returns void

  • Private

    Handle resizing of the game window by adjusting the canvas and repositioning active interface applications.

    Parameters

    • event: Event

      The window resize event which has occurred

    Returns any

  • Private

    Handle window unload operations to clean up any data which may be pending a final save

    Parameters

    • event: Event

      The window unload event which is about to occur

    Returns any

  • Private

    Handle cases where the browser window loses focus to reset detection of currently pressed keys

    Parameters

    • event: Event

      The originating window.blur event

    Returns void

  • Private

    Initialize elements required for the current view

    Returns Promise<void>

  • Private

    Initialization steps for the primary Game view

    Returns Promise<void>

  • Private

    Initialization steps for the Stream helper view

    Returns Promise<void>

  • Fetch World data and return a Game instance

    Parameters

    • view: string

      The named view being created

    • sessionId: string

      The current sessionId of the connecting client

    Returns Promise<Game>

    A Promise which resolves to the created Game instance

  • 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<object>

    A promise which resolves to the connected socket, if successful

  • 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

      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

      The active client socket connection

    Returns Promise<boolean>

  • Place a buffered socket event into the queue

    Parameters

    • Rest ...args: [string, ...any[]]

      Arguments of the socket event

    Returns void

  • Apply the queue of buffered socket events to game data once the game is ready.

    Returns void

  • Private

    Support mousewheel control for range type input elements

    Parameters

    • event: WheelEvent

      A Mouse Wheel scroll event

    Returns void