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) embeddedName

Source:

_noAnimate :Boolean

Source:

Provide a temporary flag through which th6is 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.

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:

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|null

Source:
Overrides:

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

Type:
  • PIXI.Polygon | null

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 _id of the underlying EmbeddedEntity

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:
See:

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.

Type:
  • boolean

los :PIXI.Polygon|null

Source:
Overrides:

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

Type:
  • PIXI.Polygon | null

mouseInteractionManager :MouseInteractionManager

Source:
Overrides:

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

Type:

name :string

Source:

Convenience access to the token's nameplate string

Type:
  • string

observer :boolean

Source:

A boolean flag for whether the current game User has observer permission for the Token

Type:
  • boolean

owner :boolean

Source:

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 :FormApplication

Source:
Overrides:

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

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 EmbeddedEntity

Type:
  • string

vision :Object

Source:
Overrides:

Track the field of vision for the placeable object. This is necessary to determine whether a player has line-of-sight towards a placeable object or vice-versa

Type:
  • Object

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

_updateRotation(angleopt, deltaopt, snapopt) → {number}

Source:
Overrides:

Determine a new angle of rotation for a PlaceableObject either from an explicit angle or from a delta offset.

Parameters:
Name Type Attributes Description
angle number <optional>

An explicit angle, either this or delta must be provided

delta number <optional>

A relative angle delta, either this or the angle must be provided

snap number <optional>

A precision (in degrees) to which the resulting angle should snap. Default is 0.

Returns:

The new rotation angle for the object

Type
number

activateListeners()

Source:
Overrides:

Activate interactivity for the Placeable Object

(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

can(user, action) → {boolean}

Source:
Overrides:

Test whether a user can perform a certain interaction with regards to a Placeable Object

Parameters:
Name Type Description
user User

The User performing the action

action string

The named action being attempted

Returns:

Does the User have rights to perform the action?

Type
boolean

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() → {PlaceableObject}

Source:
Overrides:

Clear the display of the existing object

Returns:

The cleared object

Type
PlaceableObject

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

control(options) → {boolean}

Source:
Overrides:

Assume control over a PlaceableObject, flagging it as controlled and enabling downstream behaviors

Parameters:
Name Type Description
options Object

Additional options which modify the control request

Properties
Name Type Description
releaseOthers boolean

Release any other controlled objects first

Returns:

A flag denoting whether or not control was successful

Type
boolean

(async) delete()

Source:
Overrides:

(async) draw() → {PlaceableObject}

Source:
Overrides:

Draw the placeable object into its parent container

Returns:

The drawn object

Type
PlaceableObject

(async) 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, alternative) → {Object|null}

Source:

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

Parameters:
Name Type Description
barName string

The named bar to retrieve the attribute for

alternative string

An alternative attribute path to get instead of the default one

Returns:

The attribute displayed on the Token bar, if any

Type
Object | null

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
*

getLightRadius(units) → {number}

Source:

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

The radius in grid units

Returns:

The radius in canvas units

Type
number

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(options) → {Boolean}

Source:
Overrides:

Release control over a PlaceableObject, removing it from the controlled set

Parameters:
Name Type Description
options Object

Options which modify the releasing workflow

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, animateopt) → {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 Attributes Description
x number

The x-coordinate of the token center

y number

The y-coordinate of the token center

animate boolean <optional>

Animate the movement path, default is true

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

stopAnimation()

Source:

Terminate animation of this particular Token

(async) toggleCombat(combat) → {Promise}

Source:

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

Parameters:
Name Type Default Description
combat Combat | null null

A Combat encounter from which to add or remove the Token

Returns:
Type
Promise

(async) toggleEffect(texture) → {Promise.<boolean>}

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.

Returns:

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

Type
Promise.<boolean>

(async) toggleOverlay(texture) → {Promise.<boolean>}

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:

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

Type
Promise.<boolean>

(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: