The Tokens Container.

Hierarchy (View Summary)

Properties

_configPreview: null | Container<DisplayObject> = null

Preview container for config previews

_draggedToken: null | canvas.placeables.Token = null

The Token that the drag workflow was initiated on, if there's a drag workflow in progress. Set in foundry.canvas.placeables.Token#_onDragLeftStart and foundry.canvas.placeables.Token#_onDragLeftCancel.

_dragMovementAction: null | string = null

The currently selected movement action override.

_rulerPaths: Container<DisplayObject>

The ruler paths.

_tabIndex: null | number = null

The current index position in the tab cycle

clipboard: { cut: boolean; objects: PlaceableObject[] } = ...

Keep track of objects copied with CTRL+C/X which can be pasted later.

eventMode: string = "passive"
highlightObjects: boolean = false

Track whether "highlight all objects" is currently active

history: CanvasHistoryEvent[] = []

Keep track of history so that CTRL+Z can undo changes.

interactiveChildren: boolean = false

Whether this event target has any children that need UI events. This can be used optimize event propagation.

objects: null | Container<DisplayObject> = null

Placeable Layer Objects

options: { name: string } = ...

Options for this layer instance.

preview: null | Container<DisplayObject> = null

Preview Object Placement

quadtree: null | Quadtree = ...

A Quadtree which partitions and organizes Walls into quadrants for efficient target identification.

turnMarkers: Set<canvas.placeables.Token> = ...

A Set of Token objects which currently display a combat turn marker.

CREATION_STATES: {
    COMPLETED: number;
    CONFIRMED: number;
    NONE: number;
    POTENTIAL: number;
} = ...

Creation states affected to placeables during their construction.

documentName: string = "Token"

A reference to the named Document type which is contained within this Canvas Layer.

SORT_ORDER: number = 0

Sort order for placeables belonging to this layer.

Accessors

  • get active(): boolean

    Is this layer currently active

    Returns boolean

  • get controlled(): PlaceableObject[]

    An Array of placeable objects in this layer which have the _controlled attribute

    Returns PlaceableObject[]

  • get controlledObjects(): Map<string, PlaceableObject>

    Track the set of PlaceableObjects on this layer which are currently controlled.

    Returns Map<string, PlaceableObject>

  • get documentCollection(): null | DocumentCollection

    Obtain a reference to the Collection of embedded Document instances within the currently viewed Scene

    Returns null | DocumentCollection

  • get hasPreview(): boolean

    To know wheter this layer has a preview object or not.

    Returns boolean

  • get hookName(): string

    The name used by hooks to construct their hook string. Note: You should override this getter if hookName should not return the class constructor name.

    Returns string

  • get hover(): null | PlaceableObject

    Track the PlaceableObject on this layer which is currently hovered upon.

    Returns null | PlaceableObject

  • get name(): string

    The canonical name of the CanvasLayer is the name of the constructor that is the immediate child of the defined baseClass for the layer type.

    Returns string

    canvas.lighting.name -> "LightingLayer"
    
  • get placeables(): PlaceableObject[]

    A convenience method for accessing the placeable object instances contained in this layer

    Returns PlaceableObject[]

  • get instance(): CanvasLayer

    Return a reference to the active instance of this canvas layer

    Returns CanvasLayer

  • get layerOptions(): object

    Configuration options for the PlaceablesLayer.

    Returns object

  • get placeableClass(): typeof PlaceableObject

    Obtain a reference to the PlaceableObject class definition which represents the Document type in this layer.

    Returns typeof PlaceableObject

Methods

  • Internal

    Create a preview of this layer's object type from a world document and show its sheet to be finalized.

    Parameters

    • createData: object

      The data to create the object with.

    • Optionaloptions: { left?: number; renderSheet?: boolean; top?: number } = {}

      Options which configure preview creation

      • Optionalleft?: number

        The offset-left position where the sheet should be rendered

      • OptionalrenderSheet?: boolean

        Render the preview object config sheet?

      • Optionaltop?: number

        The offset-top position where the sheet should be rendered

    Returns PlaceableObject

    The created preview object

  • Parameters

    • options: any

    Returns Promise<void>

  • Internal

    An internal helper method to identify the array of PlaceableObjects which can be moved or rotated.

    Parameters

    • ids: any

      An explicit array of IDs requested.

    • includeLocked: any

      Include locked objects which would otherwise be ignored?

    Returns PlaceableObject[]

    An array of objects which can be moved or rotated

    If any explicitly requested ID is not valid

  • Handle double left-click events which originate from the Canvas stage.

    Parameters

    • event: any

      The PIXI InteractionEvent which wraps a PointerEvent

    Returns void

  • Handle double right mouse-click events which originate from the Canvas stage.

    Parameters

    • event: any

      The PIXI InteractionEvent which wraps a PointerEvent

    Returns void

  • Internal

    Handle dropping of Actor data onto the Scene canvas

    Parameters

    • event: DragEvent
    • data: { elevation?: number; type: "Actor"; uuid: string; x: number; y: number }

    Returns Promise<any>

  • Parameters

    • objects: any
    • dx: any
    • dy: any
    • dz: any

    Returns ({ _id: any }[] | { movement: {} })[]

  • Internal

    Send the controlled objects of this layer to the back or bring them to the front.

    Parameters

    • front: boolean

      Bring to front instead of send to back?

    Returns boolean

    Returns true if the layer has sortable object, and false otherwise

  • The inner _tearDown method which may be customized by each CanvasLayer subclass.

    Parameters

    • options: any

      Options which configure how the layer is deconstructed

    Returns Promise<void>

  • Internal

    Handle broadcast planned movement update.

    Parameters

    • user: documents.User

      The User the planned movement data belongs to

    • plannedMovements: null | { [tokenId: string]: null | TokenPlannedMovement }

      The planned movement data

    Returns void

  • Activate the InteractionLayer, deactivating other layers and marking this layer's children as interactive.

    Parameters

    • Optionaloptions: { tool?: string } = {}

      Options which configure layer activation

      • Optionaltool?: string

        A specific tool in the control palette to set as active

    Returns InteractionLayer

    The layer instance, now activated

  • Clear the contents of the preview container, restoring visibility of original (non-preview) objects.

    Returns void

  • Immediately conclude the animation of any/all tokens

    Returns void

  • Acquire control over all PlaceableObject instances which are visible and controllable within the layer.

    Parameters

    • options: object = {}

      Options passed to the control method of each object

    Returns PlaceableObject[]

    An array of objects that were controlled

  • Copy (or cut) currently controlled PlaceableObjects, ready to paste back into the Scene later.

    Parameters

    • Optionaloptions: { cut?: boolean } = {}

      Additional options

      • Optionalcut?: boolean

        Cut instead of copy?

    Returns readonly PlaceableObject[]

    The Array of copied PlaceableObject instances

  • Cycle the controlled token by rotating through the list of Owned Tokens that are available within the Scene Tokens are currently sorted in order of their TokenID

    Parameters

    • forwards: boolean

      Which direction to cycle. A truthy value cycles forward, while a false value cycles backwards.

    • reset: boolean

      Restart the cycle order back at the beginning?

    Returns null | canvas.placeables.Token

    The Token object which was cycled to, or null

  • A helper method to prompt for deletion of all PlaceableObject instances within the Scene Renders a confirmation dialogue to confirm with the requester that all objects will be deleted

    Returns Promise<Document[]>

    An array of Document objects which were deleted by the operation

  • Draw the canvas layer, rendering its internal components and returning a Promise. The Promise resolves to the drawn layer once its contents are successfully rendered.

    Parameters

    • Optionaloptions: object = {}

      Options which configure how the layer is drawn

    Returns Promise<CanvasLayer>

  • Get a PlaceableObject contained in this layer by its ID. Returns undefined if the object doesn't exist or if the canvas is not rendering a Scene.

    Parameters

    • objectId: string

      The ID of the contained object to retrieve

    Returns PlaceableObject

    The object instance, or undefined

  • Get the maximum sort value of all placeables.

    Returns number

    The maximum sort value (-Infinity if there are no objects)

  • Get the zIndex that should be used for ordering this layer vertically relative to others in the same Container.

    Returns number

  • Simultaneously move multiple PlaceableObjects via keyboard movement offsets. This executes a single database operation using Scene#updateEmbeddedDocuments.

    Parameters

    • options: {
          dx?: 0 | 1 | -1;
          dy?: 0 | 1 | -1;
          dz?: 0 | 1 | -1;
          ids?: string[];
          includeLocked?: boolean;
          rotate?: boolean;
      } = {}

      Options which configure how multiple objects are moved

      • Optionaldx?: 0 | 1 | -1

        Horizontal movement direction

      • Optionaldy?: 0 | 1 | -1

        Vertical movement direction

      • Optionaldz?: 0 | 1 | -1

        Movement direction along the z-axis (elevation)

      • Optionalids?: string[]

        An Array of object IDs to target for movement. The default is the IDs of controlled objects.

      • OptionalincludeLocked?: boolean

        Move objects whose documents are locked?

      • Optionalrotate?: boolean

        Rotate the placeable to direction instead of moving

    Returns Promise<PlaceableObject[]>

    An array of objects which were moved during the operation

    An error if an explicitly provided id is not valid

  • Paste currently copied PlaceableObjects back to the layer by creating new copies

    Parameters

    • position: Point

      The destination position for the copied data.

    • Optionaloptions: { hidden?: boolean; snap?: boolean } = {}

      Options which modify the paste operation

      • Optionalhidden?: boolean

        Paste data in a hidden state, if applicable. Default is false.

      • Optionalsnap?: boolean

        Snap the resulting objects to the grid. Default is true.

    Returns Promise<Document[]>

    An Array of created Document instances

  • Recalculate the planned movement paths of all Tokens for the current User.

    Returns void

  • Release all controlled PlaceableObject instance from this layer.

    Parameters

    • options: object = {}

      Options passed to the release method of each object

    Returns number

    The number of PlaceableObject instances which were released

  • Simultaneously rotate multiple PlaceableObjects using a provided angle or incremental. This executes a single database operation using Scene#updateEmbeddedDocuments.

    Parameters

    • options: {
          angle?: number;
          delta?: number;
          ids?: any[];
          includeLocked?: boolean;
          snap?: number;
      } = {}

      Options which configure how multiple objects are rotated

      • Optionalangle?: number

        A target angle of rotation (in degrees) where zero faces "south"

      • Optionaldelta?: number

        An incremental angle of rotation (in degrees)

      • Optionalids?: any[]

        An Array of object IDs to target for rotation

      • OptionalincludeLocked?: boolean

        Rotate objects whose documents are locked?

      • Optionalsnap?: number

        Snap the resulting angle to a multiple of some increment (in degrees)

    Returns Promise<PlaceableObject[]>

    An array of objects which were rotated

    An error if an explicitly provided id is not valid

  • Select all PlaceableObject instances which fall within a coordinate rectangle.

    Parameters

    • Optionaloptions: {
          controlOptions?: object;
          height?: number;
          releaseOptions?: object;
          width?: number;
          x?: number;
          y?: number;
      } = {}
      • OptionalcontrolOptions?: object

        Optional arguments provided to any called control() method.

      • Optionalheight?: number

        The height of the selection rectangle.

      • OptionalreleaseOptions?: object

        Optional arguments provided to any called release() method.

      • Optionalwidth?: number

        The width of the selection rectangle.

      • Optionalx?: number

        The top-left x-coordinate of the selection rectangle.

      • Optionaly?: number

        The top-left y-coordinate of the selection rectangle.

    • Optionalaoptions: { releaseOthers?: boolean } = {}

      Additional options to configure selection behaviour.

      • OptionalreleaseOthers?: boolean

        Whether to release other selected objects.

    Returns boolean

    A boolean for whether the controlled set was changed in the operation.

  • Assign a set of render flags to all placeables in this layer.

    Parameters

    • flags: Record<string, boolean>

      The flags to set

    Returns void

  • Assign multiple token targets

    Parameters

    • targetIds: string[] | Set<string>

      The array or set of Token IDs.

    • Optionaloptions: { mode?: "replace" | "acquire" | "release" } = {}

      Additional options to configure targeting behaviour.

      • Optionalmode?: "replace" | "acquire" | "release"

        The mode that determines the targeting behavior.

        • "replace" (default): Replace the current set of targeted Tokens with provided set of Tokens.
        • "acquire": Acquire the given Tokens as targets without releasing already targeted Tokens.
        • "release": Release the given Tokens as targets.

    Returns void

  • Parameters

    • type: any
    • data: any
    • options: any

    Returns void

  • Target all Token instances which fall within a coordinate rectangle.

    Parameters

    • rectangle: Rectangle

      The selection rectangle.

    • Optionaloptions: { releaseOthers?: boolean } = {}

      Additional options to configure targeting behaviour.

      • OptionalreleaseOthers?: boolean

        Whether or not to release other targeted tokens

    Returns void

  • Deconstruct data used in the current layer in preparation to re-draw the canvas

    Parameters

    • Optionaloptions: object = {}

      Options which configure how the layer is deconstructed

    Returns Promise<CanvasLayer>

  • Undo a change to the objects in this layer This method is typically activated using CTRL+Z while the layer is active

    Returns Promise<Document[]>

    An array of documents which were modified by the undo operation

  • Update all objects in this layer with a provided transformation. Conditionally filter to only apply to objects which match a certain condition.

    Parameters

    • transformation: object | Function

      An object of data or function to apply to all matched objects

    • condition: null | Function = null

      A function which tests whether to target each object

    • Optionaloptions: object = {}

      Additional options passed to Document.update

    Returns Promise<Document[]>

    An array of updated data once the operation is complete

  • Protected

    Get the world-transformed drop position.

    Parameters

    • event: DragEvent
    • Optionaloptions: { center?: boolean } = {}
      • Optionalcenter?: boolean

        Return the coordinates of the center of the nearest grid element.

    Returns boolean | number[]

    Returns the transformed x, y coordinates, or false if the drag event was outside the canvas.

  • Protected

    Provide an array of Tokens which are eligible subjects for tile occlusion. By default, only tokens which are currently controlled or owned by a player are included as subjects.

    Returns canvas.placeables.Token[]

  • Protected

    Undo creation with deletion workflow

    Parameters

    • event: Event

    Returns Promise<Document[]>

    An array of documents which were modified by the undo operation

  • Protected

    Undo deletion with creation workflow.

    Parameters

    • event: Event

    Returns Promise<Document[]>

    An array of documents which were modified by the undo operation

  • Protected

    Undo updates with update workflow.

    Parameters

    • event: Event

    Returns Promise<Document[]>

    An array of documents which were modified by the undo operation

  • Protected

    Record a new CRUD event in the history log so that it can be undone later. Updates without changes are filtered out unless the diff option is set to false. This function may not be overridden.

    Parameters

    • type: "update" | "delete" | "create"

      The event type

    • data: object[]

      The create/update/delete data

    • Optionaloptions: object = {}

      The options of the undo operation

    Returns void

  • Returns {
        activeTool: string;
        icon: string;
        name: string;
        onChange: (event: any, active: any) => void;
        onToolChange: () => any;
        order: number;
        title: string;
        tools: {
            ruler: {
                icon: string;
                name: string;
                order: number;
                title: string;
                toolclip: { heading: string; items: ToolclipConfigurationItem[] };
            };
            select: {
                icon: string;
                name: string;
                order: number;
                title: string;
                toolclip: {
                    heading: string;
                    items: ToolclipConfigurationItem[];
                    src: string;
                };
            };
            target: {
                icon: string;
                name: string;
                order: number;
                title: string;
                toolclip: {
                    heading: string;
                    items: ToolclipConfigurationItem[];
                    src: string;
                };
            };
            unconstrainedMovement: {
                active: boolean;
                icon: string;
                name: string;
                order: number;
                title: string;
                toggle: boolean;
                toolclip: { heading: string; items: ToolclipConfigurationItem[] };
                visible: boolean;
            };
        };
    }