Options
All
  • Public
  • Public/Protected
  • All
Menu

The Ruler - used to measure distances and trigger movements

param The

User for whom to construct the Ruler instance

Hierarchy

  • any
    • Ruler

Index

Constructors

  • new Ruler(user: any, __namedParameters?: { color: any }): Ruler
  • Parameters

    • user: any
    • __namedParameters: { color: any } = {}
      • color: any

    Returns Ruler

Properties

user: User

Record the User which this Ruler references

name: string

The ruler name - used to differentiate between players

color: typeof utils.Color

The ruler color - by default the color of the active user

waypoints: Point[]

This Array tracks individual waypoints along the ruler's measured path. The first waypoint is always the origin of the route.

ruler: any

The Ruler element is a Graphics instance which draws the line and points of the measured path

labels: Container

The Labels element is a Container of Text elements which label the measured path

_state: number

Track the current measurement state

destination: Point = ...

The current destination point at the end of the measurement

The array of most recently computed ruler measurement segments

STATES: { INACTIVE: number; STARTING: number; MEASURING: number; MOVING: number } = ...

An enumeration of the possible Ruler measurement states.

Type declaration

  • INACTIVE: number
  • STARTING: number
  • MEASURING: number
  • MOVING: number

Accessors

  • get active(): boolean
  • Is the Ruler being actively used to measure distance?

    Returns boolean

Methods

  • clear(): void
  • Clear display of the current Ruler

    Returns void

  • Measure the distance between two points and render the ruler UI to illustrate it

    Parameters

    • destination: Point

      The destination point to which to measure

    • gridSpaces: boolean = {}

      Restrict measurement only to grid spaces

    Returns RulerMeasurementSegment[]

    The array of measured segments

  • moveToken(): Promise<boolean>
  • Determine whether a SPACE keypress event entails a legal token movement along a measured ruler

    Returns Promise<boolean>

    An indicator for whether a token was successfully moved or not. If True the event should be prevented from propagating further, if False it should move on to other handlers.

  • _onDragStart(event: InteractionEvent): void
  • Handle the beginning of a new Ruler measurement workflow

    see

    {Canvas._onDragLeftStart}

    Parameters

    • event: InteractionEvent

      The drag start event

    Returns void

  • _onClickLeft(event: InteractionEvent): void
  • Handle left-click events on the Canvas during Ruler measurement.

    see

    {Canvas._onClickLeft}

    Parameters

    • event: InteractionEvent

      The pointer-down event

    Returns void

  • _onClickRight(event: InteractionEvent): false | void
  • Handle right-click events on the Canvas during Ruler measurement.

    see

    {Canvas._onClickRight}

    Parameters

    • event: InteractionEvent

      The pointer-down event

    Returns false | void

  • _onMouseMove(event: InteractionEvent): void
  • Continue a Ruler measurement workflow for left-mouse movements on the Canvas.

    see

    {Canvas._onDragLeftMove}

    Parameters

    • event: InteractionEvent

      The mouse move event

    Returns void

  • _onMouseUp(event: InteractionEvent): void
  • Conclude a Ruler measurement workflow by releasing the left-mouse button.

    see

    {Canvas._onDragLeftDrop}

    Parameters

    • event: InteractionEvent

      The pointer-up event

    Returns void

  • Package Ruler data to an object which can be serialized to a string.

    Returns RulerData

  • update(data: any): void
  • Update a Ruler instance using data provided through the cursor activity socket

    Parameters

    • data: any

      Ruler data with which to update the display

    Returns void

  • _getMeasurementDestination(destination: Point): Point
  • While measurement is in progress, update the destination to be the central point of the target grid space.

    Parameters

    • destination: Point

      The current pixel coordinates of the mouse movement

    Returns Point

    The destination point, a center of a grid space

  • Translate the waypoints and destination point of the Ruler into an array of Ray segments.

    Returns RulerMeasurementSegment[]

    The segments of the measured path

  • _computeDistance(gridSpaces: boolean): void
  • Compute the distance of each segment and the total distance of the measured path.

    Parameters

    • gridSpaces: boolean

      Base distance on the number of grid spaces moved?

    Returns void

  • Get the text label for a segment of the measured path

    Parameters

    Returns string

  • _drawMeasuredPath(): void
  • Draw each segment of the measured path.

    Returns void

  • Highlight the measurement required to complete the move in the minimum number of discrete spaces

    Parameters

    Returns void

  • _getMovementToken(): Token
  • Acquire a Token, if any, which is eligible to perform a movement based on the starting point of the Ruler

    Returns Token

  • _animateMovement(token: Token): Promise<void>
  • Animate piecewise Token movement along the measured segment path.

    Parameters

    • token: Token

      The Token being animated

    Returns Promise<void>

    A Promise which resolves once all animation is completed

  • Update Token position and configure its animation properties for the next leg of its animation.

    Parameters

    • token: Token

      The Token being updated

    • segment: RulerMeasurementSegment

      The measured segment being moved

    • destination: Point

      The adjusted destination coordinate

    Returns Promise<unknown>

    A Promise which resolves once the animation for this segment is done

  • _addWaypoint(point: Point): void
  • Handle the addition of a new waypoint in the Ruler measurement path

    Parameters

    • point: Point

    Returns void

  • _removeWaypoint(point: Point, [snap]?: boolean): void
  • Handle the removal of a waypoint in the Ruler measurement path

    Parameters

    • point: Point

      The current cursor position to snap to

    • [snap]: boolean = {}

      Snap exactly to grid spaces?

    Returns void

  • _endMeasurement(): void
  • Handle the conclusion of a Ruler measurement workflow

    Returns void