The virtual tabletop environment is implemented using a WebGL powered HTML 5 canvas using the powerful PIXI.js library. The canvas is comprised by an ordered sequence of layers which define rendering groups and collections of objects that are drawn on the canvas itself.

Hook Events

hookEvents.canvasConfig hookEvents.canvasInit hookEvents.canvasReady hookEvents.canvasPan hookEvents.canvasTearDown

Example: Canvas State

canvas.ready; // Is the canvas ready for use?
canvas.scene; // The currently viewed Scene document.
canvas.dimensions; // The dimensions of the current Scene.

Example: Canvas Methods

canvas.draw(); // Completely re-draw the game canvas (this is usually unnecessary).
canvas.pan(x, y, zoom); // Pan the canvas to new coordinates and scale.
canvas.recenter(); // Re-center the canvas on the currently controlled Token.

Properties

Accessors

Methods

Properties

blurFilters: Set<filters> = ...

A set of blur filter instances which are modified by the zoom level and the "soft shadows" setting

currentMouseManager: MouseInteractionManager = null

A reference to the MouseInteractionManager that is currently controlling pointer-based interaction, or null.

loadTexturesOptions: {
    expireCache: boolean;
    additionalSources: string[];
}

Configure options passed to the texture loaded for the Scene. This object can be configured during the canvasInit hook before textures have been loaded.

Type declaration

  • expireCache: boolean
  • additionalSources: string[]
visibilityOptions: {
    persistentVision: boolean;
}

Configure options used by the visibility framework for special effects This object can be configured during the canvasInit hook before visibility is initialized.

Type declaration

  • persistentVision: boolean
blurOptions: {
    enabled: boolean;
    blurClass: Class;
    strength: number;
    passes: number;
    kernels: number;
}

Configure options passed to initialize blur for the Scene and override normal behavior. This object can be configured during the canvasInit hook before blur is initialized.

Type declaration

  • enabled: boolean
  • blurClass: Class
  • strength: number
  • passes: number
  • kernels: number
sceneTextures: {} = {}

Configure the Textures to apply to the Scene. Textures registered here will be automatically loaded as part of the TextureLoader.loadSceneTextures workflow. Textures which need to be loaded should be configured during the "canvasInit" hook.

Type declaration

    fps: {
        average: number;
        values: number[];
        element: HTMLElement;
        render: number;
    } = ...

    Record framerate performance data.

    Type declaration

    • average: number
    • values: number[]
    • element: HTMLElement
    • render: number
    mouseInteractionManager: MouseInteractionManager

    The singleton interaction manager instance which handles mouse interaction on the Canvas.

    Configured performance settings which affect the behavior of the Canvas and its renderer.

    A list of supported webGL capabilities and limitations.

    photosensitiveMode: boolean

    Is the photosensitive mode enabled?

    screenDimensions: number[] = ...

    The renderer screen dimensions.

    loading: boolean = false

    A flag to indicate whether a new Scene is currently being drawn.

    initializing: Promise<void> = null

    A promise that resolves when the canvas is first initialized and ready.

    app: Application

    The singleton PIXI.Application instance rendered on the Canvas.

    stage: Container

    The primary stage container of the PIXI.Application.

    The rendered canvas group which render the environment canvas group and the interface canvas group.

    See

    • environment
    • interface
    edges: CanvasEdges

    A singleton CanvasEdges instance.

    The singleton FogManager instance.

    perception: PerceptionManager

    A perception manager interface for batching lighting, sight, and sound updates.

    The environment canvas group which render the primary canvas group and the effects canvas group.

    See

    • primary
    • effects

    The primary Canvas group which generally contains tangible physical objects which exist within the Scene. This group is a CachedContainer which is rendered to the Scene as a SpriteMesh. This allows the rendered result of the Primary Canvas Group to be affected by a BaseSamplerShader.

    The effects Canvas group which modifies the result of the PrimaryCanvasGroup by adding special effects. This includes lighting, vision, fog of war and related animations.

    visibility: CanvasVisibility

    The visibility Canvas group which handles the fog of war overlay by consolidating multiple render textures, and applying a filter with special effects and blur.

    The interface Canvas group which is rendered above other groups and contains all interactive elements. The various InteractionLayer instances of the interface group provide different control sets for interacting with different types of Documents which can be represented on the Canvas.

    The overlay Canvas group which is rendered above other groups and contains elements not bound to stage transform.

    The singleton HeadsUpDisplay container which overlays HTML rendering on top of this Canvas.

    mousePosition: Point = ...

    Position of the mouse on stage.

    forceSnapVertices: boolean = false

    Force snapping to grid vertices?

    pendingRenderFlags: any

    Track objects which have pending render flags.

    #throttleOnMouseMove: (() => any) = ...

    A throttled function that handles mouse moves.

    Type declaration

      • (): any
      • Returns any

    #drawing: Promise<Canvas> = ...

    An internal reference to a Promise in-progress to draw the canvas.

    #dragDrop: DragDrop

    The DragDrop instance which handles interactivity resulting from DragTransfer events.

    #reload: {
        scene: string;
        layer: string;
        controlledTokens: string[];
        targetedTokens: string[];
    } = {}

    An object of data which caches data which should be persisted across re-draws of the game canvas.

    Type declaration

    • scene: string
    • layer: string
    • controlledTokens: string[]
    • targetedTokens: string[]
    _panTime: number = 0

    Track the last automatic pan time to throttle

    #tickerFunctions: Record<string, Function> = {}

    Cached references to bound ticker functions which can be removed later.

    Accessors

    • get initialized(): boolean
    • A flag for whether the game Canvas is fully initialized and ready for additional content to be drawn.

      Returns boolean

    • get scene(): Scene
    • A reference to the currently displayed Scene document, or null if the Canvas is currently blank.

      Returns Scene

    • get manager(): any
    • A SceneManager instance which adds behaviors to this Scene, or null if there is no manager.

      Returns any

    • get dimensions(): Readonly<CanvasDimensions>
    • The current pixel dimensions of the displayed Scene, or null if the Canvas is blank.

      Returns Readonly<CanvasDimensions>

    • get grid(): any
    • A reference to the grid of the currently displayed Scene document, or null if the Canvas is currently blank.

      Returns any

    • get ready(): boolean
    • A flag for whether the game Canvas is ready to be used. False if the canvas is not yet drawn, true otherwise.

      Returns boolean

    • get colors(): typeof Color
    • The colors bound to this scene and handled by the color manager.

      Returns typeof Color

    • get masks(): Container
    • Shortcut to get the masks container from HiddenCanvasGroup.

      Returns Container

    • get id(): string
    • The id of the currently displayed Scene.

      Returns string

    • get layers(): CanvasLayer[]
    • An Array of all CanvasLayer instances which are active on the Canvas board

      Returns CanvasLayer[]

    • get darknessLevel(): number
    • The currently displayed darkness level, which may override the saved Scene value.

      Returns number

    • get layers(): Record<string, CanvasLayer>
    • A mapping of named CanvasLayer classes which defines the layers which comprise the Scene.

      Returns Record<string, CanvasLayer>

    Methods

    • Initialize the Canvas by creating the HTML element and PIXI application. This step should only ever be performed once per client session. Subsequent requests to reset the canvas should go through Canvas#draw

      Returns void

    • Draw the game canvas.

      Parameters

      • Optional scene: Scene

        A specific Scene document to render on the Canvas

      Returns Promise<Canvas>

      A Promise which resolves once the Canvas is fully drawn

    • When re-drawing the canvas, first tear down or discontinue some existing processes

      Returns Promise<void>

    • Get the value of a GL parameter

      Parameters

      • parameter: string

        The GL parameter to retrieve

      Returns any

      The GL parameter value

    • Initialize the starting view of the canvas stage If we are re-drawing a scene which was previously rendered, restore the prior view position Otherwise set the view to the top-left corner of the scene at standard scale

      Returns void

    • Given an embedded object name, get the canvas layer for that object

      Parameters

      • embeddedName: string

      Returns PlaceablesLayer

    • Get the InteractionLayer of the canvas which manages Documents of a certain collection within the Scene.

      Parameters

      • collectionName: string

        The collection name

      Returns PlaceablesLayer

      The canvas layer

    • Activate framerate tracking by adding an HTML element to the display and refreshing it every frame.

      Returns void

    • Deactivate framerate tracking by canceling ticker updates and removing the HTML element.

      Returns void

    • Pan the canvas to a certain {x,y} coordinate and a certain zoom level

      Parameters

      Returns void

    • Animate panning the canvas to a certain destination coordinate and zoom scale Customize the animation speed with additional options Returns a Promise which is resolved once the animation has completed

      Parameters

      Returns Promise<any>

      A Promise which resolves once the animation has been completed

    • Recenter the canvas with a pan animation that ends in the center of the canvas rectangle.

      Parameters

      Returns Promise<void>

      A Promise which resolves once the animation has been completed

    • Highlight objects on any layers which are visible

      Parameters

      • active: boolean

      Returns void

    • Displays a Ping both locally and on other connected client, following these rules:

      1. Displays on the current canvas Scene
      2. If ALT is held, becomes an ALERT ping
      3. Else if the user is GM and SHIFT is held, becomes a PULL ping
      4. Else is a PULSE ping

      Parameters

      • origin: Point

        Point to display Ping at

      • Optional options: PingOptions

        Additional options to configure how the ping is drawn.

      Returns Promise<boolean>

    • Create a BlurFilter instance and register it to the array for updates when the zoom level changes.

      Parameters

      • blurStrength: number

        The desired blur strength to use for this filter

      • blurQuality: number = CONFIG.Canvas.blurQuality

        The desired quality to use for this filter

      Returns BlurFilter

    • Add a filter to the blur filter list. The filter must have the blur property

      Parameters

      • filter: BlurFilter

        The Filter instance to add

      Returns BlurFilter

      The added filter for method chaining

    • Convert canvas coordinates to the client's viewport.

      Parameters

      • origin: Point

        The canvas coordinates.

      Returns Point

      The corresponding coordinates relative to the client's viewport.

    • Convert client viewport coordinates to canvas coordinates.

      Parameters

      • origin: Point

        The client coordinates.

      Returns Point

      The corresponding canvas coordinates.

    • Determine whether given canvas coordinates are off-screen.

      Parameters

      • position: Point

        The canvas coordinates.

      Returns boolean

      Is the coordinate outside the screen bounds?

    • Internal

      Handle right-mouse start drag events occurring on the Canvas.

      Parameters

      • event: FederatedEvent

      Returns void

      See

    • Internal

      Handle right-mouse drag events occurring on the Canvas.

      Parameters

      • event: FederatedEvent

      Returns void

      See

    • Internal

      Handle the conclusion of a right-mouse drag workflow the Canvas stage.

      Parameters

      • event: FederatedEvent

      Returns void

      See

    • Internal

      Handle the cancellation of a right-mouse drag workflow the Canvas stage.

      Parameters

      • event: FederatedEvent

      Returns void

      See

    • Pan the canvas view when the cursor position gets close to the edge of the frame

      Parameters

      • event: MouseEvent

        The originating mouse movement event

      Returns Promise<any>

    • Initialize custom pixi plugins.

      Returns void

    • Create the PIXI.Application and update references to the created app and stage.

      Parameters

      • canvas: HTMLCanvasElement

        The target canvas view element

      • config: object

        Desired PIXI.Application configuration options

      Returns void

    • Attach specific behaviors to the PIXI runners.

      • contextChange => Remap all the blend modes

      Returns void

    • Map custom blend modes and premultiplied blend modes.

      Returns void

    • Remap premultiplied blend modes/non premultiplied blend modes to fix PIXI bug with custom BM.

      Returns void

    • Initialize the group containers of the game Canvas.

      Parameters

      • parentName: string
      • parent: DisplayObject

      Returns void

    • Private

      TODO: Add a quality parameter Compute the blur parameters according to grid size and performance mode.

      Parameters

      • options: {} = {}

        Blur options.

        Returns void

      • Draw the game canvas. This method is wrapped by a promise that enqueues multiple draw requests.

        Parameters

        • Optional scene: Scene

          A specific Scene document to render on the Canvas

        Returns Promise<void>

      • Handle Region BEHAVIOR_STATUS events that are triggered when the Scene is (un)viewed.

        Parameters

        • viewed: boolean

          Is the scene viewed or not?

        Returns Promise<void>

      • A special workflow to perform when rendering a blank Canvas with no active Scene.

        Returns void

      • Once the canvas is drawn, initialize control, visibility, and audio states

        Returns Promise<void>

      • Initialize a CanvasLayer in the activation state

        Returns void

      • Initialize a token or set of tokens which should be controlled. Restore controlled and targeted tokens from before the re-draw.

        Returns void

      • Safely call a function of the SceneManager instance, catching and logging any errors.

        Parameters

        • fnName: string

          The name of the manager function to invoke

        Returns Promise<void>

      • Measure average framerate per second over the past 30 frames

        Returns void

      • Private

        Update the blur strength depending on the scale of the canvas stage. This number is zero if "soft shadows" are disabled

        Parameters

        • Optional strength: number

          Optional blur strength to apply

        Returns void

      • Attach event listeners to the game canvas to handle click and interaction events

        Returns void

      • Handle mouse movement on the game canvas.

        Returns void

      • Handle left mouse-click events occurring on the Canvas.

        Parameters

        • event: FederatedEvent

        Returns void

        See

      • Handle double left-click events occurring on the Canvas.

        Parameters

        • event: FederatedEvent

        Returns void

        See

      • Handle long press events occurring on the Canvas.

        Parameters

        • event: FederatedEvent

          The triggering canvas interaction event.

        • origin: Point

          The local canvas coordinates of the mousepress.

        Returns void

        See

      • Does the User have permission to left-click drag on the Canvas?

        Parameters

        • user: User

          The User performing the action.

        • event: FederatedEvent

          The event object.

        Returns boolean

      • Handle the beginning of a left-mouse drag workflow on the Canvas stage or its active Layer.

        Parameters

        • event: FederatedEvent

        Returns any

        See

      • Handle mouse movement events occurring on the Canvas.

        Parameters

        • event: FederatedEvent

        Returns any

        See

      • Internal

        Handle the conclusion of a left-mouse drag workflow when the mouse button is released.

        Parameters

        • event: FederatedEvent

        Returns any

        See

      • Internal

        Handle the cancellation of a left-mouse drag workflow

        Parameters

        • event: PointerEvent

        Returns boolean | void

        See

      • Handle right mouse-click events occurring on the Canvas.

        Parameters

        • event: FederatedEvent

        Returns any

        See

      • Handle double right-click events occurring on the Canvas.

        Parameters

        • event: FederatedEvent

        Returns any

        See

      • Determine selection coordinate rectangle during a mouse-drag workflow

        Parameters

        • event: FederatedEvent

        Returns void

      • Private

        Handle window resizing with the dimensions of the window viewport change

        Parameters

        • event: Event = null

          The Window resize event

        Returns boolean

      • Private

        Handle mousewheel events which adjust the scale of the canvas

        Parameters

        • event: WheelEvent

          The mousewheel event that zooms the canvas

        Returns void

      • Private

        Event handler for the drop portion of a drag-and-drop event.

        Parameters

        • event: DragEvent

          The drag event being dropped onto the canvas

        Returns any

      • Activate ticker functions which should be called as part of the render loop. This occurs as part of setup for a newly viewed Scene.

        Returns void

      • Deactivate ticker functions which were previously registered. This occurs during tear-down of a previously viewed Scene.

        Returns void

      • Apply pending render flags which should be handled at a certain ticker priority.

        Parameters

        • queue: Set<RenderFlagObject>

          The queue of objects to handle

        Returns void

      • Test support for some GPU capabilities and update the supported property.

        Parameters

        • renderer: Renderer

        Returns {
            webGL2: boolean;
            readPixelsRED: boolean;
            offscreenCanvas: boolean;
        }

        • webGL2: boolean
        • readPixelsRED: boolean
        • offscreenCanvas: boolean
      • Internal

        Create a SceneManager instance used for this Scene, if any.

        Parameters

        Returns any

      • Remove all children of the display object and call one cleaning method: clean first, then tearDown, and destroy if no cleaning method is found.

        Parameters

        • displayObject: DisplayObject

          The display object to clean.

        • destroy: boolean = true

          If textures should be destroyed.

        Returns void

      • Get a texture with the required configuration and clear color.

        Parameters

        • options: {
              clearColor: number[];
              textureConfiguration: object;
          } = {}
          • clearColor: number[]

            The clear color to use for this texture. Transparent by default.

          • textureConfiguration: object

            The render texture configuration.

        Returns RenderTexture

      • Configure the usage of WebGL for the PIXI.Application that will be created.

        Returns void

        Throws

        an Error if WebGL is not supported by this browser environment.

      • Create the Canvas element which will be the render target for the PIXI.Application instance. Replace the template element which serves as a placeholder in the initially served HTML response.

        Returns HTMLCanvasElement

      • Configure the settings used to initialize the PIXI.Application instance.

        Returns object

        Options passed to the PIXI.Application constructor.