Token

Token

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

Constructor

new Token()

Source:
Example
Token.create({
  name: "Token Name",
  x: 1000,
  y: 1000,
  displayName: 3,
  img: "path/to/token-artwork.png",
  width: 2,
  height: 2,
  scale: 1.2,
  elevation: 50,
  lockRotation: false,
  rotation: 30,
  effects: ["icons/stun.png"],
  overlayEffect: "icons/dead.png",
  vision: true,
  dimSight: 60,
  brightSight: 0,
  dimLight: 40,
  brightLight: 20,
  sightAngle: 60,
  hidden: false,
  actorId: "dfgkjt43jkvdfkj34t",
  actorLink: true,
  actorData: {},
  disposition: 1,
  displayBars: 3,
  bar1: {attribute: "attributes.hp"},
  bar2: {attribute: "attributes.sp"}
}

Extends

Members

(static) layer

Source:

_noAnimate :Boolean

Source:

Provide a temporary flag through which this Token can be overridden to bypass any movement animation

Type:
  • Boolean

actor :Actor

Source:

An Actor entity constructed using this Token's data If actorLink is true, then the entity is the true Actor entity Otherwise, the Actor entity is a synthetic, constructed using the Token actorData

Type:

brightLightRadius

Source:

The radius of bright light that the Token emits

brightRadius

Source:

Translate the token's bright light distance in units into a radius in pixels.

canViewSheet :boolean

Source:

Does the current user have at least LIMITED permission to the Token

Type:
  • boolean

center :Object

Source:
Overrides:
Properties:
Name Type Description
x

The central x-coordinate

y

The central y-coordinate

The Token's current central position

Type:
  • Object

controlIcon :ControlIcon

Source:
Overrides:

A control icon for interacting with the object

Type:

coords :Array

Source:
Overrides:

The [x,y] coordinates of the placeable object within the Scene container

Type:

data :Object

Source:
Overrides:

The underlying data object which provides the basis for this placeable object

Type:
  • Object

dimLightRadius

Source:

The radius of dim light that the Token emits

dimRadius

Source:

Translate the token's sight distance in units into a radius in pixels.

emitsLight :boolean

Source:

Test whether the Token emits light (or darkness) at any radius

Type:
  • boolean

fov :PIXI.Polygon

Source:
Overrides:

The Token's most recently computed field-of-vision polygon

Type:
  • PIXI.Polygon

h :number

Source:

Translate the token's grid height into a pixel height based on the canvas size

Type:
  • number

hasActiveHUD

Source:

Is the HUD display active for this token?

hasLimitedVisionAngle :boolean

Source:

Test whether the Token has a limited angle of vision or light emission which would require sight to update on Token rotation

Type:
  • boolean

hasSight :boolean

Source:

Test whether the Token has sight (or blindness) at any radius

Type:
  • boolean

id :string

Source:
Overrides:

The EmbeddedDocument id of the underlying data object

Type:
  • string

inCombat :boolean

Source:

An indicator for whether or not this token is currently involved in the active combat encounter.

Type:
  • boolean

isTargeted :boolean

Source:

An indicator for whether the Token is currently targeted by the active game User

Type:
  • boolean

isVisible :boolean

Source:

Determine whether the Token is visible to the calling user's perspective. If the user is a GM, all tokens are visible If the user is a player, owned tokens which are not hidden are visible Otherwise only tokens whose corner or center are within the vision polygon are visible.

Type:
  • boolean

layer :PlaceablesLayer

Source:
Overrides:

Return a reference to the singleton layer instance which contains placeables of this type

Type:

los :PIXI.Polygon

Source:

The Token's most recently computed line-of-sight polygon

Type:
  • PIXI.Polygon

name :string

Source:

Convenience access to the token's nameplate string

Type:
  • string

owner :boolean

Source:
Overrides:

A Boolean flag for whether the current game User has permission to control this token

Type:
  • boolean

scene :Scene

Source:
Overrides:

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

Type:

sheet :TokenConfig

Source:
Overrides:

Provide a singleton reference to the TileConfig sheet for this Tile instance

Type:

targeted :Set.<User>

Source:

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

Type:

uuid :string

Source:
Overrides:

A Universally Unique Identifier (uuid) for this Embedded Entity instance

Type:
  • string

w :number

Source:

Translate the token's grid width into a pixel width based on the canvas size

Type:
  • number

Methods

_drawNameplate() → {PIXI.Text}

Source:

Draw the token's nameplate as a text object

Returns:

The Text object for the Token nameplate

Type
PIXI.Text

_getLightRadius(units) → {number}

Source:

A generic transformation to turn a certain number of grid units into a radius in canvas pixels

Parameters:
Name Type Description
units Number

The radius in grid units

Returns:

The radius in canvas units

Type
number

_onDoubleRight()

Source:

(async) animateMovement(ray)

Source:

Animate Token movement along a certain path which is defined by a Ray object

Parameters:
Name Type Description
ray Ray

The path along which to animate Token movement

checkCollision(destination, drag) → {Boolean}

Source:

Check for collision when attempting a move to a new position

Parameters:
Name Type Description
destination Object

An Object containing data for the attempted movement

drag Boolean

Whether we are checking collision for a drag+drop movement

Returns:

A true/false indicator for whether the attempted movement caused a collision

Type
Boolean

clear()

Source:
Overrides:

Clear the display of the existing object

clone() → {PlaceableObject}

Source:
Overrides:

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:

A new object with identical data

Type
PlaceableObject

computeFOV() → {Object}

Source:

Compute the field-of-vision for an object, determining its effective line-of-sight and field-of-vision polygons

Returns:

An object containing the rays, LOS polygon, and FOV polygon for the light

Type
Object

control(releaseOthers, initializeSight) → {Boolean}

Source:
Overrides:

Assume control over a PlaceableObject, flagging it as controlled and enabling downstream behaviors See PlaceableObject.control() for full details

Parameters:
Name Type Description
releaseOthers Boolean

Release any other controlled objects first

initializeSight Boolean

Reinitialize the sight layer

Returns:

A Boolean flag denoting whether or not control was successful.

Type
Boolean

(async) delete()

Source:
Overrides:

displayToFront()

Source:
Overrides:

Shift the display of the PlaceableObject to the top of the rendering stack, above all other siblings

(async) draw() → {Promise}

Source:
Overrides:

Draw the token, returning a promise once the token's texture is loaded

Returns:
Type
Promise

drawEffects()

Source:

Draw the active effects and overlay effect icons which are present upon the Token

drawTooltip()

Source:

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

getBarAttribute(barName) → {Object}

Source:

A helper method to retrieve the underlying data behind one of the Token's attribute bars

Parameters:
Name Type Description
barName
Returns:
Type
Object

getCenter(x, y) → {Object}

Source:

Get the center-point coordinate for a given grid position

Parameters:
Name Type Description
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:

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

Type
Object

getFlag(scope, key) → {*}

Source:
Overrides:

Get the value of a "flag" for this PlaceableObject See the setFlag method for more details on flags

Parameters:
Name Type Description
scope String

The flag scope which namespaces the key

key String

The flag key

Returns:

The flag value

Type
*

getSightOrigin() → {Object}

Source:

Return the token's sight origin, tailored for the direction of their movement velocity to break ties with walls

Returns:
Type
Object

refresh()

Source:
Overrides:

Update display of the Token, pulling latest data and re-rendering the display of Token components

release(resetSight) → {Boolean}

Source:
Overrides:

Release control over a PlaceableObject, removing it from the controlled set See PlaceableObject.release() for full details

Parameters:
Name Type Description
resetSight Boolean

Trigger a re-initialization of the sight layer, this may not be necessary

Returns:

A Boolean flag confirming the object was released.

Type
Boolean

rotate()

Source:
Overrides:

Extend the PlaceableObject.rotate method to prevent rotation if the Token is in the midst of a movement animation

(async) setFlag(scope, key, value) → {Promise}

Source:
Overrides:

Assign a "flag" to this Entity. Flags represent key-value type data which can be used to store flexible or arbitrary data required by either the core software, game systems, or user-created modules.

Each flag should be set using a scope which provides a namespace for the flag to help prevent collisions.

Flags set by the core software use the "core" scope. Flags set by game systems or modules should use the canonical name attribute for the module Flags set by an individual world should "world" as the scope.

Flag values can assume almost any data type. Setting a flag value to null will delete that flag.

Parameters:
Name Type Description
scope String

The flag scope which namespaces the key

key String

The flag key

value *

The flag value

Returns:

A Promise resolving to the updated PlaceableObject

Type
Promise

(async) setPosition(x, y) → {Promise}

Source:

Set the token's position by comparing its center position vs the nearest grid vertex Return a Promise that resolves to the Token once the animation for the movement has been completed

Parameters:
Name Type Description
x Number

The x-coordinate of the token center

y Number

The y-coordinate of the token center

Returns:

The Token after animation has completed

Type
Promise

setTarget(targeted, user, releaseOthers, groupSelection)

Source:

Set this Token as an active target for the current game User

Parameters:
Name Type Default Description
targeted boolean true

Is the Token now targeted?

user User | null

Assign the token as a target for a specific User

releaseOthers boolean

Release other active targets for the same player?

groupSelection boolean

Is this target being set as part of a group selection workflow?

(async) shiftPosition(dx, dy) → {Promise}

Source:

Perform an incremental token movement, shifting the token's position by some number of grid units. The offset parameters will move the token by that number of grid spaces in one or both directions.

Parameters:
Name Type Description
dx Number

The number of grid units to shift along the X-axis

dy Number

The number of grid units to shift along the Y-axis

Returns:
Type
Promise

sortToBack()

Source:
Overrides:

Sort the PlaceableObject to the back of the rendering stack, behind all other siblings. Update the database with the new minimal Z-index

sortToFront()

Source:
Overrides:

Sort the PlaceableObject to the front of the rendering stack, above all other siblings. Update the database with the new maximal Z-index

(async) toggleCombat() → {Promise}

Source:

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

Returns:
Type
Promise

(async) toggleEffect(texture)

Source:

Toggle an active effect by it's texture path. Copy the existing Array in order to ensure the update method detects the data as changed.

Parameters:
Name Type Description
texture String

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

(async) toggleOverlay(texture) → {Promise}

Source:

Set or remove the overlay texture for the Token by providing a new texture path

Parameters:
Name Type Description
texture String

The texture file-path of the effect to set as the Token overlay icon

Returns:
Type
Promise

(async) toggleVisibility() → {Promise}

Source:

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

Returns:
Type
Promise

(async) unsetFlag(scope, key) → {Promise}

Source:
Overrides:

Remove a flag assigned to the Entity

Parameters:
Name Type Description
scope string

The flag scope which namespaces the key

key string

The flag key

Returns:

A Promise resolving to the updated Entity

Type
Promise

(async) update()

Source:
Overrides: