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

    The Regions Container.

    Index

    Properties

    Accessors

    Methods

    Properties

    _configPreview: Container<DisplayObject> | null = null

    Preview container for config previews

    _highlights: Container<DisplayObject> = ...

    The highlight meshes of the Regions.

    _mouseWheelContext: { preview: PlaceableObject; shape: BaseShapeData } | null = null

    The mouse wheel context.

    _placementContext: {
        allowRotation: boolean;
        attachToToken: boolean;
        create: boolean;
        createOptions: Partial<Omit<DatabaseCreateOperation, "parent">>;
        data: RegionData;
        onMove: {
            count: number;
            document: RegionDocument;
            event: FederatedEvent;
            index: number;
            position: Point;
            preview: canvas.placeables.Region;
            shape: BaseShapeData;
            snap: boolean;
        };
        preview: canvas.placeables.Region;
        reject: (error: Error) => void;
        resolve: (document: RegionDocument | null) => void;
        shape: BaseShapeData;
        shapes: BaseShapeData[];
    } = null

    The placement context.

    _shapeClipboard: { cut: boolean; shape: BaseShapeData | null } = ...

    The shape clipboard.

    _throttleRotateMany: (options: object) => Promise<PlaceableObject[]> = ...

    A throttled function that rotates many placeables.

    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: Container<DisplayObject> | null = null

    Placeable Layer Objects

    options: { name: string } = ...

    Options for this layer instance.

    preview: Container<DisplayObject> | null = null

    Preview Object Placement

    quadtree: Quadtree | null = ...

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

    documentName: string = "Region"
    paletteClass: typeof RegionPalette = RegionPalette
    SORT_ORDER: number = 0

    Sort order for placeables belonging to this layer.

    TOGGLE_PALETTE: Partial<SceneControlTool> = ...

    The shared palette tool.

    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(): DocumentCollection<any> | null

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

      Returns DocumentCollection<any> | null

    • get hasPreview(): boolean

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

      Returns boolean

    • get hookName(): string

      Returns string

    • get hover(): PlaceableObject | null

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

      Returns PlaceableObject | null

    • get hud(): BasePlaceableHUD<any, any, any> | null

      If objects on this PlaceablesLayer have a HUD UI, provide a reference to its instance

      Returns BasePlaceableHUD<any, any, any> | null

    • 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 paletteCreateData(): object

      The default creation data sourced from this layer's palette, if it has one.

      Returns object

    • get placeables(): PlaceableObject[]

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

      Returns PlaceableObject[]

    • get templateMode(): boolean

      Is Measured Template Mode enabled?

      Returns boolean

    • get instance(): CanvasLayer

      Return a reference to the active instance of this canvas layer

      Returns CanvasLayer

    • get layerOptions(): object

      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

    • Returns void

    • Internal

      Cancel the placement.

      Returns void

    • Parameters

      • user: any
      • event: any

      Returns boolean

    • Parameters

      • event: any

      Returns Promise<void>

    • Parameters

      • documents: any

      Returns true | Promise<boolean>

    • Parameters

      • event: any

      Returns {
          color: any;
          displayMeasurements: boolean;
          highlightMode: string;
          levels: (string | null)[];
          name: any;
          ownership: {};
          restriction: { enabled: boolean; type: string };
          visibility: 3;
      }

    • 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

    • Returns void

    • Parameters

      • options: any

      Returns Promise<void>

    • Internal

      An internal helper method to identify the array of PlaceableObjects which can be copied/cut.

      Parameters

      • options: { cut: boolean }

        Additional options

        • cut: boolean

          Cut instead of copy?

      Returns PlaceableObject[]

      An array of objects which can be copied/cut

    • Internal

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

      Parameters

      • ids: string[] | undefined

        An explicit array of IDs requested.

      • includeLocked: boolean

        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

    • Parameters

      • active: any

      Returns void

    • Internal

      Highlight the shape or clear the highlight.

      Parameters

      • shape: BaseShapeData | null

        The shape to highlight, or null to clear the highlight

      Returns void

    • Returns boolean

    • Parameters

      • event: any

      Returns void

    • Parameters

      • event: any

      Returns void

    • Parameters

      • event: any

      Returns false | undefined

    • Parameters

      • event: any

      Returns boolean

    • Parameters

      • event: any

      Returns boolean

    • Parameters

      • event: any

      Returns boolean

    • Parameters

      • event: any

      Returns boolean

    • Parameters

      • event: any

      Returns void

    • Parameters

      • event: any

      Returns void

    • Parameters

      • event: any

      Returns void

    • Parameters

      • event: any

      Returns void

    • Parameters

      • event: any

      Returns void

    • Parameters

      • event: any

      Returns boolean

    • Parameters

      • event: any

      Returns boolean

    • Parameters

      • event: any

      Returns boolean

    • Internal

      Prepare the updates and update options for moving the given placeable objects via keyboard.

      Parameters

      Returns [updates: object[], options?: object]

    • Internal

      Prepare the updates and update options for rotating the given placeable objects via keyboard.

      Parameters

      Returns [updates: object[], options?: object]

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

      Returns undefined if the layer does not have sortable object. Returns false if the controlled objects are already at the front/back.

    • Parameters

      • options: any

      Returns Promise<void>

    • Parameters

      • event: any

      Returns void

    • Rotate the shape of the preview.

      Parameters

      • event: WheelEvent

        The mouse wheel event

      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

    • 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

    • Iterates over placeable objects that are eligible for control/select.

      Returns Generator<PlaceableObject, any, any>

      A placeable object

    • Parameters

      • options: any

      Returns readonly PlaceableObject[]

    • Draw a single placeable object

      Parameters

      • document: ClientDocument

        The Document instance used to create the placeable object

      Returns PlaceableObject

    • Deactivate the InteractionLayer, removing interactivity from its children.

      Returns InteractionLayer

      The layer instance, now inactive

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

    • Parameters

      • point: any

      Returns Point

    • Returns any

    • 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

    • Place a Region at the cursor. The Region can have multiple shapes, but none of them can be holes and it must have at least one shape. Each shape is placed one after the other in the given order. Only one Region can be placed at a time. The placed Region shapes can be rotated with the mouse wheel unless allowRotation is false. Left-click confirms the placement of a shape. Right-click skips the placement of a shape.

      Parameters

      • data: Partial<RegionData>

        The data of the Region to place

      • Optionaloptions: {
            allowRotation?: boolean;
            attachToToken?: boolean;
            create?: boolean;
            createOptions?: Partial<Omit<DatabaseCreateOperation, "parent">>;
        } = {}

        Additional options

        • OptionalallowRotation?: boolean

          Allow rotation of the Region? Default: true.

        • OptionalattachToToken?: boolean

          Attach the Region to Tokens? If true, the initial elevation range passed in data is relative to the attached Token. Default: false.

        • Optionalcreate?: boolean

          Create the Region? If false, the preview document is returned. Default: true. Non-GMs cannot create Regions while the game is paused.

        • OptionalcreateOptions?: Partial<Omit<DatabaseCreateOperation, "parent">>

          Optional creation options. By default the creation option controlObject is true.

      Returns Promise<RegionDocument | null>

      The Region document that was placed or null if

      • the placements of all shapes were skipped,
      • the dismiss key was pressed,
      • the game is paused, the user is not a GM, and the create option is true, or
      • the Region creation was rejected by preCreate.

      If the Region creation failed

      const radius = 40 * canvas.dimensions.distancePixels;
      const shapes = [];
      for ( let i = 0; i < 4; i++ ) shapes.push({type: "circle", x: 0, y: 0, radius, gridBased: true});
      await canvas.regions.placeRegion({
      name: "Meteor Swarm",
      shapes,
      color: game.user.color,
      restriction: {enabled: true},
      levels: [canvas.level.id],
      highlightMode: "coverage",
      displayMeasurements: true,
      visibility: CONST.REGION_VISIBILITY.OBSERVER,
      ownership: {[game.user.id]: CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER}
      });
      ui.notifications.info("Choose the placement for the spawn area.");
      const spawnArea = await canvas.regions.placeRegion({
      name: "Spawn Area",
      shapes: [{
      type: "circle",
      x: 0,
      y: 0,
      radius: canvas.dimensions.distancePixels * 30
      }],
      restriction: {enabled: true},
      levels: [canvas.level.id]
      }, {create: false});
      if ( spawnArea ) {
      const {count: numTokensToSpawn=0} = await foundry.applications.api.DialogV2.input({
      window: {
      title: "How many tokens to you want to spawn?"
      },
      content: `<input type="number" name="count" min="0" step="1" value="10">`
      }) ?? {};
      const actors = game.actors.contents;
      const tokensToSpawn = [];
      for ( let i = 0; i < numTokensToSpawn; i++ ) {
      const actor = actors[Math.floor(Math.random() * actors.length)];
      const token = await actor.getTokenDocument({
      rotation: Math.random() * 360
      }, {parent: spawnArea.parent});
      tokensToSpawn.push(token);
      }
      const spawnedTokens = await spawnArea.spawnTokens(tokensToSpawn);
      }
    • 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

    • Parameters

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

      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: Function | null = 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

    • Iterate over all documents which are viewed in the current Level.

      Returns Generator<any, void, unknown>

    • Protected

      Cancel mouse wheel rotation.

      Returns void

    • 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

      Create the shape data from the drag start event.

      Parameters

      • event: FederatedEvent<UIEvent | PixiTouch>

        The pointer event

      Returns object

      The initial shape data

    • Protected

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

      Parameters

      • event: FederatedEvent<UIEvent | PixiTouch>

        The PIXI InteractionEvent which wraps a PointerEvent

      Returns void

    • Protected

      Handle a Cycle View keypress while this layer is active.

      Parameters

      • event: KeyboardEvent

        The cycle-view key press event

      Returns boolean

      Was the event handled?

    • 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

      Prepare the database update that should occur as the result of a mouse wheel rotation.

      Returns object | [data: object, options?: object]

      The update data and options (optional)

    • 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: "create" | "update" | "delete"

        The event type

      • data: object[]

        The create/update/delete data

      • Optionaloptions: object = {}

        The options of the undo operation

      Returns void

    • Protected

      Update the mouse wheel rotation preview.

      Returns void

    • Returns {
          activeTool: string;
          icon: string;
          layer: string;
          name: string;
          onChange: (event: any, active: any) => void;
          onToolChange: (event: any, tool: any, active: any) => void;
          order: number;
          title: string;
          tools: {
              circle: {
                  hasPalette: boolean;
                  icon: string;
                  name: string;
                  order: number;
                  title: string;
                  toolclip: { heading: string; items: ToolclipConfigurationItem[] };
              };
              clear: {
                  button: boolean;
                  icon: string;
                  name: string;
                  onChange: () => any;
                  order: number;
                  title: string;
                  visible: boolean;
              };
              cone: {
                  hasPalette: boolean;
                  icon: string;
                  name: string;
                  order: number;
                  title: string;
                  toolclip: { heading: string; items: ToolclipConfigurationItem[] };
              };
              ellipse: {
                  hasPalette: boolean;
                  icon: string;
                  name: string;
                  order: number;
                  title: string;
                  toolclip: {
                      heading: string;
                      items: ToolclipConfigurationItem[];
                      src: string;
                  };
                  visible: boolean;
              };
              emanation: {
                  hasPalette: boolean;
                  icon: string;
                  name: string;
                  order: number;
                  title: string;
                  toolclip: { heading: string; items: ToolclipConfigurationItem[] };
              };
              hole: {
                  active: boolean;
                  icon: string;
                  name: string;
                  order: number;
                  title: string;
                  toggle: boolean;
                  toolclip: {
                      heading: string;
                      items: ToolclipConfigurationItem[];
                      src: string;
                  };
                  visible: boolean;
              };
              line: {
                  hasPalette: boolean;
                  icon: string;
                  name: string;
                  order: number;
                  title: string;
                  toolclip: { heading: string; items: ToolclipConfigurationItem[] };
              };
              polygon: {
                  hasPalette: boolean;
                  icon: string;
                  name: string;
                  order: number;
                  title: string;
                  toolclip: {
                      heading: string;
                      items: ToolclipConfigurationItem[];
                      src: string;
                  };
                  visible: boolean;
              };
              rectangle: {
                  hasPalette: boolean;
                  icon: string;
                  name: string;
                  order: number;
                  title: string;
                  toolclip: {
                      heading: string;
                      items: ToolclipConfigurationItem[];
                      src: string;
                  };
              };
              ring: {
                  hasPalette: boolean;
                  icon: string;
                  name: string;
                  order: number;
                  title: string;
                  toolclip: { heading: string; items: ToolclipConfigurationItem[] };
              };
              select: {
                  hasPalette: boolean;
                  icon: string;
                  name: string;
                  order: number;
                  title: string;
                  toolclip: {
                      heading: string;
                      items: ToolclipConfigurationItem[];
                      src: string;
                  };
              };
              snap: {
                  active: boolean;
                  icon: string;
                  name: string;
                  onChange: (event: any, toggled: any) => any;
                  order: number;
                  title: string;
                  toggle: boolean;
                  toolclip: {
                      heading: string;
                      items: ToolclipConfigurationItem[];
                      src: string;
                  };
                  visible: boolean;
              };
              templateMode: {
                  active: boolean;
                  icon: string;
                  name: string;
                  onChange: (event: any, toggled: any) => void;
                  order: number;
                  title: string;
                  toggle: boolean;
              };
              togglePalette: {
                  active: boolean;
                  button?: boolean;
                  createData?: object;
                  hasPalette?: boolean;
                  icon?: string;
                  name?: string;
                  onChange?: (event: Event, active: boolean) => void;
                  order: number;
                  title?: string;
                  toggle?: boolean;
                  toolclip?: ToolclipConfiguration;
                  visible: boolean;
              };
          };
          visible: boolean;
      }