A CanvasLayer for displaying UI controls which are overlayed on top of other layers.

We track three types of events:

  1. Cursor movement
  2. Ruler measurement
  3. Map pings

Hierarchy (view full)

Properties

doors: Container

A container of DoorControl instances

cursors: Container

A container of cursor interaction elements. Contains cursors, rulers, interaction rectangles, and pings

rulers: Container

Ruler tools, one per connected user

debug: Graphics

A graphics instance used for drawing debugging visualization

select: Graphics

The Canvas selection rectangle

_cursors: Record<string, Cursor> = {}

A mapping of user IDs to Cursor instances for quick access

eventMode: string = "passive"
options: {
    name: string;
} = ...

Options for this layer instance.

Type declaration

  • name: string
_rulers: Record<string, Ruler> = {}

A mapping of user IDs to Ruler instances for quick access

_offscreenPings: Record<string, Point> = {}

The positions of any offscreen pings we are tracking.

#drawing: Promise<CanvasLayer> = ...

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

#drawn: boolean = false

Is the layer drawn?

Accessors

  • get ruler(): Ruler
  • A convenience accessor to the Ruler for the active game user

    Returns Ruler

  • get active(): boolean
  • Is this layer currently active

    Returns boolean

  • 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

    Example

    canvas.lighting.name -> "LightingLayer"
    
  • 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 layerOptions(): any
  • Returns any

  • get instance(): CanvasLayer
  • Return a reference to the active instance of this canvas layer

    Returns CanvasLayer

Methods

  • Get the Ruler display for a specific User ID

    Parameters

    • userId: string

    Returns Ruler

  • Draw the cursors container

    Returns void

  • Create and add Ruler graphics instances for every game User.

    Returns void

  • Draw door control icons to the doors container.

    Returns void

  • Draw the select rectangle given an event originated within the base canvas layer

    Parameters

    • coords: any

      The rectangle coordinates of the form {x, y, width, height}

    Returns void

  • Handle mousemove events on the game canvas to broadcast activity of the user's cursor position

    Returns void

  • Create and draw the Cursor object for a given User

    Parameters

    • user: User

      The User document for whom to draw the cursor Container

    Returns any

  • Update the cursor when the user moves to a new position

    Parameters

    • user: User

      The User for whom to update the cursor

    • position: Point

      The new cursor position

    Returns void

  • Update display of an active Ruler object for a user given provided data

    Parameters

    • user: User

      The User for whom to update the ruler

    • rulerData: RulerMeasurementData

      Data which describes the new ruler measurement to display

    Returns void

  • Handle a broadcast ping.

    Parameters

    • user: User

      The user who pinged.

    • position: Point

      The position on the canvas that was pinged.

    • Optional data: PingData = {}

      The broadcast ping data.

    Returns Promise<boolean>

    A promise which resolves once the Ping has been drawn and animated

    See

    Ping#drawPing

  • Draw a ping at the edge of the viewport, pointing to the location of an off-screen ping.

    Parameters

    • position: Point

      The coordinates of the off-screen ping.

    • Optional options: PingOptions = {}

      Additional options to configure how the ping is drawn.

    Returns Promise<boolean>

    A promise which resolves once the Ping has been drawn and animated

    See

    Ping#drawPing

  • Draw a ping on the canvas.

    Parameters

    • position: Point

      The position on the canvas that was pinged.

    • Optional options: PingOptions = {}

      Additional options to configure how the ping is drawn.

    Returns Promise<boolean>

    A promise which resolves once the Ping has been drawn and animated

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

    Parameters

    • Optional options: {
          tool: string;
      } = {}

      Options which configure layer activation

      • tool: string

        A specific tool in the control palette to set as active

    Returns InteractionLayer

    The layer instance, now activated

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

    Returns number

  • 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

    • Optional options: any = {}

      Options which configure how the layer is drawn

    Returns Promise<CanvasLayer>

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

    Parameters

    • Optional options: any = {}

      Options which configure how the layer is deconstructed

    Returns Promise<CanvasLayer>

  • Protected

    Handle pinging the canvas.

    Parameters

    • event: FederatedEvent

      The triggering canvas interaction event.

    • origin: Point

      The local canvas coordinates of the mousepress.

    Returns any

  • Protected

    Handle the canvas panning to a new view.

    Returns void

  • Protected

    The inner _activate method which may be defined by each InteractionLayer subclass.

    Returns void

  • Protected

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

    Parameters

    • event: FederatedEvent

      The PIXI InteractionEvent which wraps a PointerEvent

    Returns void

    See

    Canvas._onClickLeft

  • Protected

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

    Parameters

    • event: FederatedEvent

      The PIXI InteractionEvent which wraps a PointerEvent

    Returns void

    See

    Canvas.#onClickLeft2

  • Protected

    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

  • Protected

    Start a left-click drag workflow originating from the Canvas stage.

    Parameters

    • event: FederatedEvent

      The PIXI InteractionEvent which wraps a PointerEvent

    Returns void

    See

    Canvas.#onDragLeftStart

  • Protected

    Continue a left-click drag workflow originating from the Canvas stage.

    Parameters

    • event: FederatedEvent

      The PIXI InteractionEvent which wraps a PointerEvent

    Returns void

    See

    Canvas.#onDragLeftMove

  • Protected

    Conclude a left-click drag workflow originating from the Canvas stage.

    Parameters

    • event: FederatedEvent

      The PIXI InteractionEvent which wraps a PointerEvent

    Returns void

    See

    Canvas.#onDragLeftDrop

  • Protected

    Cancel a left-click drag workflow originating from the Canvas stage.

    Parameters

    • event: PointerEvent

      A right-click pointer event on the document.

    Returns void

    See

    Canvas.#onDragLeftDrop

  • Protected

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

    Parameters

    • event: FederatedEvent

      The PIXI InteractionEvent which wraps a PointerEvent

    Returns void

    See

    Canvas._onClickRight

  • Private

    Given off-screen coordinates, determine the closest point at the edge of the viewport to these coordinates.

    Parameters

    • position: Point

      The off-screen coordinates.

    Returns {
        ray: Ray;
        intersection: any;
    }

    The closest point at the edge of the viewport to these coordinates and a ray cast from the centre of the screen towards it.

    • ray: Ray
    • intersection: any