Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    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.

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

    canvas.ready; // Is the canvas ready for use?
    canvas.scene; // The currently viewed Scene document.
    canvas.dimensions; // The dimensions of the current Scene.
    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.
    Index

    Properties

    _frameId: number = 0

    Frame ID. Each frame has its own unique value, incremented each frame.

    _viewOptions: SceneViewOptions = {}

    The view options.

    app: Application<ICanvas>

    The singleton PIXI.Application instance rendered on the Canvas.

    blurFilters: Set<Filter> = ...

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

    blurOptions: {
        blurClass: typeof Filter;
        enabled: boolean;
        kernels: number;
        passes: number;
        strength: 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.

    currentMouseManager: MouseInteractionManager | null = null

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

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

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

    The singleton FogManager instance.

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

    Record framerate performance data.

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

    initializing: Promise<void> | null = null

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

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

    loading: boolean = false

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

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

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

    mouseInteractionManager: MouseInteractionManager

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

    mousePosition: Point = ...

    Position of the mouse on stage.

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

    pendingRenderFlags: {
        OBJECTS: Set<RenderFlagObject>;
        PERCEPTION: Set<RenderFlagObject>;
    }

    Track objects which have pending render flags.

    perception: PerceptionManager

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

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

    photosensitiveMode: boolean

    Is the photosensitive mode enabled?

    previousMousePosition: Point = ...

    Previous position of the mouse on stage.

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

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

    root: Container<DisplayObject>

    The root container

    sceneTextures: Record<
        string,
        string
        | Texture<Resource>
        | Spritesheet<ISpritesheetData>,
    > = {}

    Configure the Textures to apply to the Scene.

    Textures registered here will be automatically loaded as part of the TextureLoader.loadSceneTextures workflow. To be loaded, a texture must be added to this record before or during the "canvasInit" hook.

    After textures are loaded for the Scene, the values of this record are replaced with direct references to the PIXI.Textures that were loaded.

    screenDimensions: number[] = ...

    The renderer screen dimensions.

    The framenbuffer snapshot.

    stage: Container<DisplayObject>

    The primary stage container of the PIXI.Application.

    A list of supported webGL capabilities and limitations.

    The transition container specialized in smooth scene transitions

    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.

    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.

    MOUSE_MOVE_HANDLER_PRIORITIES: Readonly<{ HIGH: 75; LOW: 25; MEDIUM: 50 }> = ...

    Mouse move handler priorities. number

    Accessors

    • get colors(): Color

      The colors bound to this scene and handled by the color manager.

      Returns Color

    • get darknessLevel(): number

      The currently displayed darkness level, which may override the saved Scene value.

      Returns number

    • get dimensions(): Readonly<CanvasDimensions> | null

      The current pixel dimensions of the displayed Scene, or null if the Canvas is blank.

      Returns Readonly<CanvasDimensions> | null

    • get edges(): CanvasEdges | null

      A reference to the edges of the currently displayed Level document.

      Returns CanvasEdges | null

    • get forceSnapVertices(): boolean

      Force snapping to grid vertices?

      Returns boolean

    • get id(): string | null

      The id of the currently displayed Scene.

      Returns string | null

    • get initialized(): boolean

      A flag for whether the game Canvas is fully initialized and ready for additional content to be drawn.

      Returns boolean

    • get layers(): CanvasLayer[]

      An Array of all CanvasLayer instances which are active on the Canvas board

      Returns CanvasLayer[]

    • get level(): documents.Level | null

      A reference to the currently displayed Level document, or null if the Canvas is currently blank.

      Returns documents.Level | null

    • get manager(): SceneManager | null

      A SceneManager instance which adds behaviors to this Scene, or null if there is no manager.

      Returns SceneManager | null

    • get masks(): Container<DisplayObject>

      Shortcut to get the masks container from HiddenCanvasGroup.

      Returns Container<DisplayObject>

    • 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 scene(): documents.Scene | null

      A reference to the currently displayed Scene document, or null if the Canvas is currently blank.

      Returns documents.Scene | null

    • get layers(): Record<string, CanvasLayer>

      A mapping of named CanvasLayer classes which defines the layers which comprise the Scene.

      Returns Record<string, CanvasLayer>

    Methods

    • 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<boolean> | undefined

    • Internal

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

      Parameters

      • event: FederatedEvent<UIEvent | PixiTouch>

      Returns void

    • Internal

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

      Parameters

      • event: FederatedEvent<UIEvent | PixiTouch>

      Returns void

    • Internal

      Handle right-mouse drag events occurring on the Canvas.

      Parameters

      • event: FederatedEvent<UIEvent | PixiTouch>

      Returns void

    • Internal

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

      Parameters

      • event: FederatedEvent<UIEvent | PixiTouch>

      Returns void

    • Internal

      Handle mousewheel events which adjust the scale of the canvas

      Parameters

      • event: WheelEvent

        The mousewheel event that zooms the canvas

      Returns void

    • Internal

      Handle window resizing with the dimensions of the window viewport change

      Returns false | undefined

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

      Returns void

    • Add a filter to the blur filter list if it has the blur property.

      Parameters

      • filter: Filter

        The filter instance to add

      Returns Filter

      The filter that was passed to this function

    • 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

      • view: any = {}

        The desired view parameters

      Returns Promise<boolean>

      A Promise which resolves once the animation has been completed

    • Convert client viewport coordinates to canvas coordinates.

      Parameters

      • origin: Point

        The client coordinates.

      Returns Point

      The corresponding canvas coordinates.

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

    • 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

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

      Returns void

    • 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

    • Get the value of a GL parameter

      Parameters

      • parameter: string

        The GL parameter to retrieve

      Returns any

      The GL parameter value

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

      Parameters

      • embeddedName: string

      Returns PlaceablesLayer | null

    • Highlight objects on any layers which are visible

      Parameters

      • active: boolean

      Returns void

    • Infer the Level for a given elevation. The inferred Level is always a visible one. Returns the viewed Level if there's no Level with the given elevation in range, or null if there's no viewed Level.

      Parameters

      • elevation: number

        The elevation

      • Optionaloptions: { levels?: Set<string> } = {}

        Additional options

        • Optionallevels?: Set<string>

          Restrict to these Levels (empty means all Levels)

      Returns documents.Level | null

    • 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

    • 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

    • Determine whether given canvas coordinates are off-screen.

      Parameters

      • position: Point

        The canvas coordinates.

      Returns boolean

      Is the coordinate outside the screen bounds?

    • Pan the canvas to a certain position and a certain zoom level.

      Parameters

      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

      • Optionaloptions: PingOptions

        Additional options to configure how the ping is drawn.

      Returns Promise<boolean>

    • 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

    • Register a new onMouseMove handler with an optional priority.

      Parameters

      • handler: Function

        The function to call on mouse move.

      • Optionalpriority: number = 0

        Optional priority. Higher values are called earlier.

      • Optionalcontext: object = ...

        The context in which the handler should be executed.

      • Optionalstrict: boolean = false

        To know if the handler should be called on real pointer move only (not simulated)

      Returns void

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

      Returns Promise<void>

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

      Parameters

      • Optionalstrength: number

        Optional blur strength to apply

      Returns void

    • 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 } = {}
        • OptionalclearColor?: number[]

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

        • OptionaltextureConfiguration?: object

          The render texture configuration.

      Returns RenderTexture