Options
All
  • Public
  • Public/Protected
  • All
Menu

A Token is an implementation of PlaceableObject which represents an Actor within a viewed Scene on the game canvas.

see

{TokenDocument}

see

{TokenLayer}

Hierarchy

Index

Constructors

Properties

Accessors

Methods

Constructors

  • new Token(document: any): Token

Properties

border: any

A Graphics instance which renders the border frame for this Token inside the GridLayer.

targeted: Set<User> = ...

Track the set of User documents which are currently targeting this Token

mesh: TokenMesh

A reference to the SpriteMesh which displays this Token in the PrimaryCanvasGroup.

vision: VisionSource = ...

A reference to the VisionSource object which defines this vision source area of effect

light: LightSource = ...

A reference to the LightSource object which defines this light source area of effect

_animation: Promise<any> = null

A reference to an animation that is currently in progress for this Token, if any

internal
texture: any
visible: any
bars: any
tooltip: any
effects: any
target: any
nameplate: any
hitArea: Rectangle
buttonMode: boolean
scene: Scene

Retain a reference to the Scene within which this Placeable Object resides

document: Document

A reference to the Scene embedded Document instance which this object represents

controlIcon: ControlIcon

A control icon for interacting with the object

mouseInteractionManager: MouseInteractionManager

A mouse interaction manager instance which handles mouse workflows related to this object.

cullable: boolean
_isHoverIn: boolean = false

Know if a placeable is in the hover-in state.

internal
zIndex: number
alpha: number
_dragPassthrough: boolean = false

Passthrough certain drag operations on locked objects.

#priorMovement: { dx: number; dy: number; ox: number; oy: number }

An Object which records the Token's prior velocity dx and dy. This can be used to determine which direction a Token was previously moving.

Type declaration

  • dx: number
  • dy: number
  • ox: number
  • oy: number
#adjustedCenter: Point

The Token central coordinate, adjusted for its most recent movement vector.

#validPosition: Point

The Token's most recent valid position and rotation.

#unlinkedVideo: boolean = false

A flag to capture whether this Token has an unlinked video texture

#detectionFilter: any
#animationAttributes: TokenAttributesSnapshot

A point-in-time snapshot of the display attributes for the Token which provides a baseline for animation.

#controlled: boolean = false
#hover: boolean = false
embeddedName: string = "Token"

Identify the official Document name for this PlaceableObject class

Accessors

  • A convenient reference to the Actor object associated with the Token embedded document.

    Returns Actor

  • get owner(): boolean
  • A convenient reference for whether the current User has full control over the Token document.

    Returns boolean

  • get isOwner(): any
  • Returns any

  • get observer(): boolean
  • A boolean flag for whether the current game User has observer permission for the Token

    Returns boolean

  • get hasActiveHUD(): boolean
  • Is the HUD display active for this token?

    Returns boolean

  • get name(): string
  • Convenience access to the token's nameplate string

    Returns string

  • override

    Returns Rectangle

  • set detectionFilter(filter: any): void
  • Defines the filter to use for detection.

    Parameters

    • filter: any

    Returns void

  • get w(): number
  • Translate the token's grid width into a pixel width based on the canvas size

    Returns number

  • get h(): number
  • Translate the token's grid height into a pixel height based on the canvas size

    Returns number

  • get center(): Point
  • The Token's current central position

    Returns Point

  • get sourceElement(): HTMLImageElement | HTMLVideoElement
  • The HTML source element for the primary Tile texture

    Returns HTMLImageElement | HTMLVideoElement

  • get sourceId(): string
  • override

    Returns string

  • get isVideo(): boolean
  • Does this Tile depict an animated video texture?

    Returns boolean

  • get inCombat(): boolean
  • An indicator for whether or not this token is currently involved in the active combat encounter.

    Returns boolean

  • Return a reference to a Combatant that represents this Token, if one is present in the current encounter.

    Returns Combatant

  • get isTargeted(): boolean
  • An indicator for whether the Token is currently targeted by the active game User

    Returns boolean

  • get detectionModes(): [any]
  • Return a reference to the detection modes array.

    Returns [any]

  • get isVisible(): boolean
  • Determine whether the Token is visible to the calling user's perspective. Hidden Tokens are only displayed to GM Users. Non-hidden Tokens are always visible if Token Vision is not required. Controlled tokens are always visible. All Tokens are visible to a GM user if no Token is controlled.

    see

    {CanvasVisibility#testVisibility}

    Returns boolean

  • get animationName(): string
  • The animation name used for Token movement

    Returns string

  • get hasSight(): boolean
  • Test whether the Token has sight (or blindness) at any radius

    Returns boolean

  • get emitsLight(): boolean
  • Does this Token actively emit light given its properties and the current darkness level of the Scene?

    Returns boolean

  • get hasLimitedSourceAngle(): boolean
  • Test whether the Token uses a limited angle of vision or light emission.

    Returns boolean

  • get dimRadius(): number
  • Translate the token's dim light distance in units into a radius in pixels.

    Returns number

  • get brightRadius(): number
  • Translate the token's bright light distance in units into a radius in pixels.

    Returns number

  • get sightRange(): number
  • Translate the token's vision range in units into a radius in pixels.

    Returns number

  • get optimalSightRange(): number
  • Translate the token's maximum vision range that takes into account lights.

    Returns number

  • get interactionState(): { NONE: number; HOVER: number; CLICKED: number; DRAG: number; DROP: number }
  • The mouse interaction state of this placeable.

    Returns { NONE: number; HOVER: number; CLICKED: number; DRAG: number; DROP: number }

    • NONE: number
    • HOVER: number
    • CLICKED: number
    • DRAG: number
    • DROP: number
  • get id(): string
  • The id of the corresponding Document which this PlaceableObject represents.

    Returns string

  • get objectId(): string
  • A unique identifier which is used to uniquely identify elements on the canvas related to this object.

    Returns string

  • get isPreview(): boolean
  • Is this placeable object a temporary preview?

    Returns boolean

  • The field-of-vision polygon for the object, if it has been computed

    Returns Circle

  • Provide a reference to the CanvasLayer which contains this PlaceableObject.

    Returns PlaceablesLayer

  • The line-of-sight polygon for the object, if it has been computed

    Returns PointSourcePolygon

  • A Form Application which is used to configure the properties of this Placeable Object or the Document it represents.

    Returns FormApplication

  • get controlled(): boolean
  • An indicator for whether the object is currently controlled

    Returns boolean

  • get hover(): boolean
  • set hover(state: boolean): void
  • An indicator for whether the object is currently a hover target

    Returns boolean

  • An indicator for whether the object is currently a hover target

    Parameters

    • state: boolean

    Returns void

Methods

  • getMovementAdjustedPoint(point: any, __namedParameters?: { offsetX: any; offsetY: any }): { x: any; y: any }
  • The Token's central position, adjusted in each direction by one or zero pixels to offset it relative to walls.

    Parameters

    • point: any
    • __namedParameters: { offsetX: any; offsetY: any } = {}
      • offsetX: any
      • offsetY: any

    Returns { x: any; y: any }

    • x: any
    • y: any
  • Clone the placeable object, returning a new object with identical attributes. The returned object is non-interactive, and has no assigned ID. If you plan to use it permanently you should call the create method.

    Returns PlaceableObject

    A new object with identical data

  • updateSource([options={}]?: { defer: boolean; deleted: boolean }): void
  • Update the light and vision source objects associated with this Token.

    Parameters

    • [options={}]: { defer: boolean; deleted: boolean } = {}

      Options which configure how perception sources are updated

      • defer: boolean
      • deleted: boolean

    Returns void

  • updateLightSource([options={}]?: { defer: boolean; deleted: boolean }): void
  • Update an emitted light source associated with this Token.

    Parameters

    • [options={}]: { defer: boolean; deleted: boolean } = {}
      • defer: boolean
      • deleted: boolean

    Returns void

  • updateVisionSource([options]?: { defer: boolean; deleted: boolean }): void
  • Update the VisionSource instance associated with this Token.

    Parameters

    • [options]: { defer: boolean; deleted: boolean } = {}

      Options which affect how the vision source is updated

      • defer: boolean
      • deleted: boolean

    Returns void

  • render(renderer: any): void
  • override

    Parameters

    • renderer: any

    Returns void

  • _destroy(options: any): void
  • The inner _destroy method which may optionally be defined by each PlaceableObject subclass.

    Parameters

    • options: any

    Returns void

  • _draw(): Promise<void>
  • _refresh(options: any): void
  • refreshHUD(options?: { bars: boolean; border: boolean; effects: boolean; elevation: boolean; nameplate: boolean }): void
  • Refresh display of elements of the Token HUD.

    Parameters

    • options: { bars: boolean; border: boolean; effects: boolean; elevation: boolean; nameplate: boolean } = {}

      Which components of the HUD to refresh?

      • bars: boolean
      • border: boolean
      • effects: boolean
      • elevation: boolean
      • nameplate: boolean

    Returns void

  • drawBars(): boolean
  • Refresh the display of Token attribute bars, rendering its latest resource data If the bar attribute is valid (has a value and max), draw the bar. Otherwise hide it.

    Returns boolean

  • _drawNameplate(): Text
  • Draw the token's nameplate as a text object

    Returns Text

    The Text object for the Token nameplate

  • _getTextStyle(): any
  • Returns any

  • drawEffects(): Promise<void>
  • Draw the active effects and overlay effect icons which are present upon the Token

    Returns Promise<void>

  • getDisplayAttributes(): any
  • Get the display attributes of the TokenDocument which are used to inform refresh.

    Returns any

  • Animate changes to the appearance of the Token. Animations are performed over differences between the TokenDocument and the current Token and TokenMesh appearance.

    Parameters

    • updateData: any

      A record of the differential data which changed, for reference only

    • [options]: CanvasAnimationOptions = {}

      Options which configure the animation behavior

    Returns Promise<void>

    A promise which resolves once the animation is complete

  • stopAnimation(): void
  • Terminate animation of this particular Token.

    Returns void

  • checkCollision(destination: Point, [options={}]?: any): any
  • Check for collision when attempting a move to a new position

    Parameters

    • destination: Point

      The central destination point of the attempted movement

    • [options={}]: any = {}

      Additional options forwarded to WallsLayer#checkCollision

    Returns any

    The result of the WallsLayer#checkCollision test

  • getCenter(x: number, y: number): any
  • Get the center-point coordinate for a given grid position

    Parameters

    • x: number

      The grid x-coordinate that represents the top-left of the Token

    • y: number

      The grid y-coordinate that represents the top-left of the Token

    Returns any

    The coordinate pair which represents the Token's center at position (x, y)

  • updatePosition([options]?: { recenter: boolean }): void
  • Update the tracked position and movement velocity of the Token

    Parameters

    • [options]: { recenter: boolean } = {}

      Options provided as part of a Token update

      • recenter: boolean

    Returns void

  • setTarget(targeted?: boolean, [context={}]?: { user: User; releaseOthers: boolean; groupSelection: boolean }): void
  • Set this Token as an active target for the current game User. Note: If the context is set with groupSelection:true, you need to manually broadcast the activity for other users.

    Parameters

    • targeted: boolean = true

      Is the Token now targeted?

    • [context={}]: { user: User; releaseOthers: boolean; groupSelection: boolean } = {}

      Additional context options

      • user: User
      • releaseOthers: boolean
      • groupSelection: boolean

    Returns void

  • Add or remove the currently controlled Tokens from the active combat encounter

    Parameters

    Returns Promise<Token>

    The Token which initiated the toggle

  • toggleEffect(effect: any, [options]?: { active: boolean; overlay: boolean }): Promise<boolean>
  • Toggle an active effect by its texture path. Copy the existing Array in order to ensure the update method detects the data as changed.

    Parameters

    • effect: any

      The texture file-path of the effect icon to toggle on the Token.

    • [options]: { active: boolean; overlay: boolean } = {}

      Additional optional arguments which configure how the effect is handled.

      • active: boolean
      • overlay: boolean

    Returns Promise<boolean>

    Was the texture applied (true) or removed (false)

  • Toggle the visibility state of any Tokens in the currently selected set

    Returns Promise<TokenDocument[]>

    A Promise which resolves to the updated Token documents

  • getLightRadius(units: number): number
  • A generic transformation to turn a certain number of grid units into a radius in canvas pixels. This function adds additional padding to the light radius equal to half the token width. This causes light to be measured from the outer token edge, rather than from the center-point.

    Parameters

    • units: number

      The radius in grid units

    Returns number

    The radius in canvas units

  • _getShiftedPosition(dx: any, dy: any): { x: any; y: any }
  • _onCreate(options: any, userId: any): void
  • _onUpdate(data: any, options: any, userId: any): void
  • _onDelete(options: any, userId: any): void
  • _onApplyStatusEffect(statusId: string, active: boolean): void
  • Handle changes to Token behavior when a significant status effect is applied

    internal

    Parameters

    • statusId: string

      The status effect ID being applied, from CONFIG.specialStatusEffects

    • active: boolean

      Is the special status effect now active?

    Returns void

  • _onControl(__namedParameters?: { releaseOthers: boolean; pan: boolean }): void
  • Additional events which trigger once control of the object is established

    Parameters

    • __namedParameters: { releaseOthers: boolean; pan: boolean } = {}

      Optional parameters which apply for specific implementations

      • releaseOthers: boolean
      • pan: boolean

    Returns void

  • _onRelease(options: any): void
  • Additional events which trigger once control of the object is released

    Parameters

    • options: any

      Options which modify the releasing workflow

    Returns void

  • _canControl(user: any, event: any): any
  • _canHUD(user: any, event: any): any
  • _canConfigure(user: any, event: any): boolean
  • _canHover(user: any, event: any): boolean
  • _canView(user: any, event: any): any
  • _canDrag(user: any, event: any): any
  • _onHoverIn(event: any, options: any): boolean
  • _onHoverOut(event: any): boolean
  • _onClickLeft(event: any): void
  • _onClickLeft2(event: any): void
  • _onClickRight2(event: any): void
  • _onDragLeftDrop(event: any): any
  • _onDragLeftMove(event: any): void
  • _onDragLeftCancel(event: any): any
  • Callback actions which occur on a mouse-move operation.

    Parameters

    • event: any

      The triggering mouse click event

    Returns any

  • _onDragStart(): void
  • Begin a drag operation from the perspective of the preview clone. Modify the appearance of both the clone (this) and the original (_original) object.

    Returns void

  • _onDragEnd(): void
  • Conclude a drag operation from the perspective of the preview clone. Modify the appearance of both the clone (this) and the original (_original) object.

    Returns void

  • can(user: User, action: string): boolean
  • Test whether a user can perform a certain interaction regarding a Placeable Object

    Parameters

    • user: User

      The User performing the action

    • action: string

      The named action being attempted

    Returns boolean

    Does the User have rights to perform the action?

  • destroy(options: any): any
  • control(options?: { releaseOthers: boolean }): boolean
  • Assume control over a PlaceableObject, flagging it as controlled and enabling downstream behaviors

    Parameters

    • options: { releaseOthers: boolean } = {}

      Additional options which modify the control request

      • releaseOthers: boolean

        Release any other controlled objects first

    Returns boolean

    A flag denoting whether control was successful

  • release(options?: any): boolean
  • Release control over a PlaceableObject, removing it from the controlled set

    Parameters

    • options: any = {}

      Options which modify the releasing workflow

    Returns boolean

    A Boolean flag confirming the object was released.

  • Rotate the PlaceableObject to a certain angle of facing

    Parameters

    • angle: number

      The desired angle of rotation

    • snap: number

      Snap the angle of rotation to a certain target degree increment

    Returns Promise<PlaceableObject>

    The rotated object

  • _updateRotation(options?: { angle: number; delta: number; snap: number }): number
  • Determine a new angle of rotation for a PlaceableObject either from an explicit angle or from a delta offset.

    Parameters

    • options: { angle: number; delta: number; snap: number } = {}

      An object which defines the rotation update parameters

      • angle: number
      • delta: number
      • snap: number

    Returns number

    The new rotation angle for the object

  • activateListeners(): void
  • _onClickRight(event: InteractionEvent): void
  • Callback actions which occur on a single right-click event to configure properties of the object

    see

    MouseInteractionManager#_handleClickRight

    Parameters

    • event: InteractionEvent

      The triggering canvas interaction event

    Returns void

  • _onDragLeftStart(event: InteractionEvent): any
  • Callback actions which occur when a mouse-drag action is first begun.

    see

    MouseInteractionManager#_handleDragStart

    Parameters

    • event: InteractionEvent

      The triggering canvas interaction event

    Returns any

  • _refreshBorder(): void
  • Draw the Token border, taking into consideration the grid type and border color

    Returns void

  • Refresh the target indicators for the Token. Draw both target arrows for the primary User as well as indicator pips for other Users targeting the same Token.

    Parameters

    Returns void

  • Draw the targeting arrows around this token.

    Parameters

    • [reticule]: ReticuleOptions = {}

      Additional parameters to configure how the targeting reticule is drawn.

    Returns void

  • _drawBar(number: number, bar: any, data: any): void
  • Draw a single resource bar, given provided data

    Parameters

    • number: number

      The Bar number

    • bar: any

      The Bar container

    • data: any

      Resource data for this bar

    Returns void

  • _refreshEffects(): void
  • Refresh the display of status effects, adjusting their position for the token width and height.

    Returns void

  • _drawEffect(src: string, tint: number): Promise<any>
  • Draw a status effect icon

    Parameters

    • src: string
    • tint: number

    Returns Promise<any>

  • _drawOverlay(src: string, tint: number): Promise<Sprite>
  • Draw the overlay effect icon

    Parameters

    • src: string
    • tint: number

    Returns Promise<Sprite>

  • _canCreate(user: User, event: any): boolean
  • Does the User have permission to create the underlying Document?

    Parameters

    • user: User

      The User performing the action.

    • event: any

      The event object.

    Returns boolean

    The returned status.

  • _canUpdate(user: User, event: any): boolean
  • Does the User have permission to update the underlying Document?

    Parameters

    • user: User

      The User performing the action.

    • event: any

      The event object.

    Returns boolean

    The returned status.

  • _canDelete(user: User, event: any): boolean
  • Does the User have permission to delete the underlying Document?

    Parameters

    • user: User

      The User performing the action.

    • event: any

      The event object.

    Returns boolean

    The returned status.

  • _onLongPress(event: InteractionEvent, origin: Point): any
  • Callback action which occurs on a long press.

    see

    MouseInteractionManager#_handleLongPress

    Parameters

    • event: InteractionEvent

      The triggering canvas interaction event

    • origin: Point

      The local canvas coordinates of the mousepress.

    Returns any

  • #initialize(): void
  • Establish an initial velocity of the token based on its direction of facing. Assume the Token made some prior movement towards the direction that it is currently facing.

    Returns void

  • _isVisionSource(): boolean
  • Test whether this Token is a viable vision source for the current User

    Returns boolean

  • _cleanData(): void
  • Apply initial sanitizations to the provided input data to ensure that a Token has valid required attributes. Constrain the Token position to remain within the Canvas rectangle.

    Returns void

  • _drawAttributeBars(): any
  • Draw resource bars for the Token

    Returns any

  • _getBorderColor([options]?: { hover: boolean }): number
  • Get the hex color that should be used to render the Token border

    Parameters

    • [options]: { hover: boolean } = {}
      • hover: boolean

    Returns number

    The hex color used to depict the border color

  • Draw a text tooltip for the token which can be used to display Elevation or a resource value

    Returns PreciseText

    The text object used to render the tooltip

  • _getTooltipText(): string
  • Return the text which should be displayed in a token's tooltip field

    Returns string

  • _canViewMode(mode: number): boolean
  • Helper method to determine whether a token attribute is viewable under a certain mode

    Parameters

    • mode: number

      The mode from CONST.TOKEN_DISPLAY_MODES

    Returns boolean

    Is the attribute viewable?

  • #animateFrame(frame: any, config?: { animatePerception: boolean; forceUpdateFog: boolean; sound: boolean }): void
  • Handle a single frame of a token animation.

    Parameters

    • frame: any

      The current animation frame

    • config: { animatePerception: boolean; forceUpdateFog: boolean; sound: boolean } = {}

      The animation configuration

      • animatePerception: boolean
      • forceUpdateFog: boolean
      • sound: boolean

    Returns void

  • Prepare a MovementSource for the document

    Parameters

    • origin: any

    Returns MovementSource

  • #recordMovement(origin: Point, destination: Point): { dx: number; dy: number; ox: number; oy: number }
  • Record that a Token movement has occurred, updating various internal attributes.

    Parameters

    • origin: Point

      The prior token top-left coordinate

    • destination: Point

      The new token top-left coordinate

    Returns { dx: number; dy: number; ox: number; oy: number }

    • dx: number
    • dy: number
    • ox: number
    • oy: number
  • _toggleOverlayEffect(texture: string, root0: { active: boolean }): Promise<any>
  • A helper function to toggle the overlay status icon on the Token

    Parameters

    • texture: string
    • root0: { active: boolean }
      • active: boolean

    Returns Promise<any>

  • _onUpdateAppearance(data: any, changed: any, options: any): Promise<void>
  • Control updates to the appearance of the Token and its linked TokenMesh when a data update occurs.

    Parameters

    • data: any
    • changed: any
    • options: any

    Returns Promise<void>