The Ruler - used to measure distances and trigger movements

Hierarchy

  • any
    • Ruler

Constructors

  • The Ruler constructor.

    Parameters

    • Optional user: User = game.user

      The User for whom to construct the Ruler instance

    • Optional options: {
          color: ColorSource;
      } = {}

      Additional options

      • color: ColorSource

        The color of the ruler (defaults to the color of the User)

    Returns Ruler

Properties

user: User

Record the User which this Ruler references

name: string

The ruler name - used to differentiate between players

color: typeof Color

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

ruler: Graphics

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

destination: any = null

The current destination point at the end of the measurement

waypoints: Point[] = []

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

segments: RulerMeasurementSegment[] = []

The array of most recently computed ruler measurement segments

totalDistance: number = 0

The computed total distance of the Ruler.

totalCost: number = 0

The computed total cost of the Ruler.

_state: number = Ruler.STATES.INACTIVE

The current state of the Ruler (one of Ruler.STATES).

#throttleBroadcastMeasurement: (() => any) = ...

A throttled function that broadcasts the measurement data.

Type declaration

    • (): any
    • Returns any

Accessors

  • get origin(): any
  • The origin point of the measurement, which is the first waypoint.

    Returns any

  • get state(): number
  • The current state of the Ruler (one of Ruler.STATES).

    Returns number

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

    Returns boolean

  • get token(): Token
  • The Token that is moved by the Ruler.

    Returns Token

  • get STATES(): Readonly<{
        INACTIVE: 0;
        STARTING: 1;
        MEASURING: 2;
        MOVING: 3;
    }>
  • The possible Ruler measurement states.

    Returns Readonly<{
        INACTIVE: 0;
        STARTING: 1;
        MEASURING: 2;
        MOVING: 3;
    }>

  • get canMeasure(): boolean
  • Is the ruler ready for measure?

    Returns boolean

Methods

  • 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

    • Optional options: {
          snap: boolean;
          force: boolean;
      } = {}

      Additional options

      • snap: boolean

        Snap the destination?

      • force: boolean

        If not forced and the destination matches the current destination of this ruler, no measuring is done and nothing is returned

    Returns void | RulerMeasurementSegment[]

    The array of measured segments if measured

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

  • Update a Ruler instance using data provided through the cursor activity socket

    Parameters

    Returns void

  • Protected

    Get the measurement origin.

    Parameters

    • point: Point

      The waypoint

    • Optional options: {
          snap: boolean;
      } = {}

      Additional options

      • snap: boolean

        Snap the waypoint?

    Returns any

  • Protected

    Get the destination point. By default the point is snapped to grid space centers.

    Parameters

    • point: Point

      The point coordinates

    • Optional options: {
          snap: boolean;
      } = {}

      Additional options

      • snap: boolean

        Snap the point?

    Returns Point

    The snapped destination point

  • Protected

    Handle the start of a Ruler measurement workflow

    Parameters

    • origin: Point

      The origin

    • Optional options: {
          snap: boolean;
          token: Token;
      } = {}

      Additional options

    Returns void

  • Protected

    Handle the conclusion of a Ruler measurement workflow

    Returns void

  • Protected

    Handle the addition of a new waypoint in the Ruler measurement path

    Parameters

    • point: Point

      The waypoint

    • Optional options: {
          snap: boolean;
      } = {}

      Additional options

      • snap: boolean

        Snap the waypoint?

    Returns void

  • Protected

    Handle the removal of a waypoint in the Ruler measurement path

    Returns void

  • Protected

    Get the cost function to be used for Ruler measurements.

    Returns any

  • Protected

    Compute the distance of each segment and the total distance of the measured path.

    Returns void

  • Protected

    Get the text label for a segment of the measured path

    Parameters

    Returns string

  • Protected

    Draw each segment of the measured path.

    Returns void

  • Protected

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

    Parameters

    Returns void

  • Protected

    Acquire a Token, if any, which is eligible to perform a movement based on the starting point of the Ruler

    Parameters

    • origin: Point

      The origin of the Ruler

    Returns Token

    The Token that is to be moved, if any

  • Protected

    Test whether a Token is allowed to execute a measured movement path.

    Parameters

    • token: Token

      The Token being tested

    Returns boolean

    Whether the movement is allowed

    Throws

    A specific Error message used instead of returning false

  • Protected

    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

  • Protected

    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

    • Optional updateOptions: object = {}

      Additional options to configure the TokenDocument update

    Returns Promise<void>

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

  • Protected

    An method which can be extended by a subclass of Ruler to define custom behaviors before a confirmed movement.

    Parameters

    • token: Token

      The Token that will be moving

    Returns Promise<void>

  • Protected

    An event which can be extended by a subclass of Ruler to define custom behaviors before a confirmed movement.

    Parameters

    • token: Token

      The Token that finished moving

    Returns Promise<void>

  • Protected

    Broadcast Ruler measurement if its User is the connected client. The broadcast is throttled to 100ms.

    Returns void

  • Protected Internal

    Handle the beginning of a new Ruler measurement workflow

    Parameters

    • event: FederatedEvent

      The drag start event

    Returns void

    See

  • Protected Internal

    Handle left-click events on the Canvas during Ruler measurement.

    Parameters

    • event: FederatedEvent

      The pointer-down event

    Returns void

    See

  • Protected Internal

    Handle right-click events on the Canvas during Ruler measurement.

    Parameters

    • event: FederatedEvent

      The pointer-down event

    Returns void

    See

  • Protected Internal

    Continue a Ruler measurement workflow for left-mouse movements on the Canvas.

    Parameters

    • event: FederatedEvent

      The mouse move event

    Returns void

    See

  • Protected Internal

    Conclude a Ruler measurement workflow by releasing the left-mouse button.

    Parameters

    • event: FederatedEvent

      The pointer-up event

    Returns void

    See

  • Protected Internal

    Move the Token along the measured path when the move key is pressed.

    Parameters

    • context: KeyboardEventContext

    Returns void

  • Broadcast Ruler measurement.

    Returns void