Global

Members

(constant) CONFIG :Object

Source:

Runtime configuration settings for Foundry VTT which exposes a large number of variables which determine how aspects of the software behaves.

Unlike the CONST analog which is frozen and immutable, the CONFIG object may be updated during the course of a session or modified by system and module developers to adjust how the application behaves.

Type:
  • Object

(constant) CONST :Object

Source:

The global CONSTANTS object

Type:
  • Object

(constant) FONTS :Object

Source:

A configuration of font families which are initialized when the page loads

Type:
  • Object

Methods

colorStringToHex(color) → {Number}

Source:

Convert a string color to a hex integer

Parameters:
Name Type Description
color String

The string color

Returns:

The hexidecimal color code

Type
Number

confirmDialog()

Source:
Deprecated:
  • since 0.4.4
See:

diffObject(original, other) → {Object}

Source:

Deeply difference an object against some other, returning the update keys and values

Parameters:
Name Type Description
original Object
other Object
Returns:
Type
Object

duplicate(original)

Source:

A cheap data duplication trick, surprisingly relatively performant

Parameters:
Name Type Description
original Object

Some sort of data

encodeURL(path) → {string}

Source:

Encode a url-like string by replacing any characters which need encoding

Parameters:
Name Type Description
path string

A fully-qualified URL or url component (like a relative path)

Returns:

An encoded URL string

Type
string

expandObject(obj, _d) → {Object}

Source:

Expand a flattened object to be a standard multi-dimensional nested Object by converting all dot-notation keys to inner objects.

Parameters:
Name Type Default Description
obj Object

The object to expand

_d Number 0

Recursion depth, to prevent overflow

Returns:

An expanded object

Type
Object

filterObject(source, template, keepSpecial, templateValues)

Source:

Filter the contents of some source object using the structure of a template object. Only keys which exist in the template are preserved in the source object.

Example
const source = {foo: {number: 1, name: "Tim", topping: "olives"}, bar: "baz"};
const template = {foo: {number: 0, name: "Mit", style: "bold"}, other: 72};
filterObject(source, template); // {foo: {number: 1, name: "Tim"}};
filterObject(source, template, {templateValues: true}); // {foo: {number: 0, name: "Mit"}};
Parameters:
Name Type Description
source Object

An object which contains the data you wish to filter

template Object

An object which contains the structure you wish to preserve

keepSpecial boolean

Whether to keep special tokens like deletion keys

templateValues boolean

Instead of keeping values from the source, instead draw values from the template

flattenObject(obj, _d) → {Object}

Source:

Flatten a possibly multi-dimensional object to a one-dimensional one by converting all nested keys to dot notation

Parameters:
Name Type Default Description
obj Object

The object to flatten

_d Number 0

Recursion depth, to prevent overflow

Returns:

A flattened object

Type
Object

(async) fromUuid(uuid) → {Promise.<(Entity|Object|null)>}

Source:

Retrieve an Entity or Embedded Entity by its Universally Unique Identifier (uuid).

Parameters:
Name Type Description
uuid string

The uuid of the Entity or Embedded Entity to retrieve

Returns:
Type
Promise.<(Entity|Object|null)>

getProperty(object, key) → {*}

Source:

A helper function which searches through an object to retrieve a value by a string key. The string key supports the notation a.b.c which would return object[a][b][c]

Parameters:
Name Type Description
object Object

The object to traverse

key String

An object property with notation a.b.c

Returns:

The value of the found property

Type
*

(async) getTemplate(path) → {Promise}

Source:

Get a template from the server by fetch request and caching the retrieved result

Parameters:
Name Type Description
path string

The web-accessible HTML template URL

Returns:

A Promise which resolves to the compiled template or null

Type
Promise

getTexture(src) → {PIXI.Texture}

Source:

Get a single texture from the cache

Parameters:
Name Type Description
src string
Returns:
Type
PIXI.Texture

getType(token) → {string}

Source:

Learn the named type of a token - extending the functionality of typeof to recognize some core Object types

Parameters:
Name Type Description
token *

Some passed token

Returns:

The named type of the token

Type
string

hasProperty(object, key) → {Boolean}

Source:

A helper function which tests whether an object has a property or nested property given a string key. The string key supports the notation a.b.c which would return true if object[a][b][c] exists

Parameters:
Name Type Description
object Object

The object to traverse

key String

An object property with notation a.b.c

Returns:

An indicator for whether the property exists

Type
Boolean

hexToRGB(hex) → {Array}

Source:

Convert a hex color code to an RGB array

Parameters:
Name Type Description
hex number

A hex color number

Returns:

An array of [r,g,b] colors normalized on the range of [0,1]

Type
Array

hexToRGBAString(hex, alpha) → {string}

Source:

Convert a hex color code to an RGBA color string which can be used for CSS styling

Parameters:
Name Type Default Description
hex number

A hex color number

alpha number 1

A level of transparency

Returns:

An rgba style string

Type
string

hsvToRgb(Number, Number, Number)

Source:

Converts an HSV color value to RGB. Conversion formula adapted from http://en.wikipedia.org/wiki/HSV_color_space. Assumes h, s, and v are contained in the set [0, 1] and returns r, g, and b in the set [0, 1].

Parameters:
Name Type Description
Number

h The hue

Number

s The saturation

Number

v The value

Returns:

Array The RGB representation

invertObject(obj) → {Object}

Source:

A temporary shim to invert an object, flipping keys and values

Parameters:
Name Type Description
obj Object

Some object where the values are unique

Returns:

An inverted object where the values of the original object are the keys of the new object

Type
Object

isNewerVersion(v0, v1) → {Boolean}

Source:

Return whether or not a version (v1) is more advanced than some other version (v0) Supports numeric or string version numbers

Parameters:
Name Type Description
v0 Number | String
v1 Number | String
Returns:
Type
Boolean

isObjectEmpty(obj) → {Boolean}

Source:

A simple function to test whether or not an Object is empty

Parameters:
Name Type Description
obj Object

The object to test

Returns:

Is the object empty?

Type
Boolean

loadFont(fontName, callback)

Source:

Load font, and perform a callback once the font has been rendered

Parameters:
Name Type Description
fontName
callback

(async) loadSceneTextures(scene) → {Promise}

Source:

Load all the primary textures which are required in order to render a Scene

Parameters:
Name Type Description
scene Scene
Returns:
Type
Promise

(async) loadTemplates(paths) → {Promise}

Source:

Load and cache a set of templates by providing an Array of paths

Parameters:
Name Type Description
paths Array
Returns:
Type
Promise

(async) loadTexture(src) → {PIXI.Texture}

Source:

Load a single texture and return a Promise which resolves once the texture is ready to use

Parameters:
Name Type Description
src string
Returns:
Type
PIXI.Texture

mergeObject(original, other, insert, overwrite, inplace, enforceTypes, _d) → {Object}

Source:

Update a source object by replacing its keys and values with those from a target object.

Parameters:
Name Type Description
original Object

The initial object which should be updated with values from the target

other Object

A new object whose values should replace those in the source

insert boolean

Control whether to insert new parent objects in the structure which did not previously exist in the source object.

overwrite boolean

Control whether to replace existing values in the source, or only merge values which do not exist in the source.

inplace boolean

Update the values of original inplace? Otherwise duplicate the original and return a safe copy.

enforceTypes boolean

Enforce that the type of an inner value in the source object match the type of the new value. Default is false for now, but should be true in the future.

_d number

A privately used parameter to track recursion depth

Returns:

The original source object including updated, inserted, or overwritten records.

Type
Object

randomID(length) → {string}

Source:

Generate a random ID Generate random number and convert it to base 36 and remove the '0.' at the beginning As long as the string is not long enough, generate more random data into it Use substring in case we generated a string with a length higher than the requested length

Parameters:
Name Type Default Description
length number 10

The length of the random ID to generate

Returns:

Return a string containing random letters and numbers

Type
string

readTextFromFile(file) → {Promise.<String>}

Source:

Read text data from a user provided File object

Parameters:
Name Type Description
file File

A File object

Returns:

A Promise which resolves to the loaded text data

Type
Promise.<String>

renderTemplate(path, data) → {Promise.<HTMLElement>}

Source:
See:

Get and render a template using provided data and handle the returned HTML Support asynchronous file template file loading with a client-side caching layer

Allow resolution of prototype methods and properties since this all occurs within the safety of the client.

Parameters:
Name Type Description
path String

The file path to the target HTML template

data Object

A data object against which to compile the template

Returns:

Returns the rendered HTML

Type
Promise.<HTMLElement>

rgbToHex(rgb) → {Number}

Source:

Converts a color as an [R, G, B] array of normalized floats to a hexadecimal number.

Parameters:
Name Type Description
rgb Array.<Number>

Array of numbers where all values are normalized floats from 0.0 to 1.0.

Returns:

Number in hexadecimal.

Type
Number

rgbToHsv(Number, Number, Number)

Source:

Converts an RGB color value to HSV. Conversion formula adapted from http://en.wikipedia.org/wiki/HSV_color_space. Assumes r, g, and b are contained in the set [0, 1] and returns h, s, and v in the set [0, 1].

Parameters:
Name Type Description
Number

r The red color value

Number

g The green color value

Number

b The blue color value

Returns:

Array The HSV representation

saveDataToFile(data, type, filename)

Source:

Export data content to be saved to a local file

Parameters:
Name Type Description
data String

Data content converted to a string

type String

The type of

filename String

The filename of the resulting download

setProperty(object, key, value) → {Boolean}

Source:

A helper function which searches through an object to assign a value using a string key This string key supports the notation a.b.c which would target object[a][b][c]

Parameters:
Name Type Description
object Object

The object to update

key String

The string key

value

The value to be assigned

Returns:

A flag for whether or not the object was updated

Type
Boolean

(async) srcExists(src) → {boolean}

Source:

Test whether a file source exists by performing a HEAD request against it

Parameters:
Name Type Description
src string

The source URL or path to test

Returns:

Does the file exist at the provided url?

Type
boolean

timeSince(timeStamp) → {string}

Source:

Express a timestamp as a relative string

Parameters:
Name Type Description
timeStamp Date
Returns:
Type
string

Events

{KeyEvent} event The original keydown event

Source:

Handle Key Down event for Push-To-Talk When the right key is pressed, prevents the event from being propagated and pushes the PTT

{KeyEvent} event The original keyup event

Source:

Handle Key Up event for Push-To-Talk When the right key is released, prevents the event from being propagated and releases the PTT

{MouseEvent} event The original mousedown event

Source:

Handle Mouse Down event for Push-To-Talk Pushes the PTT when the right button is pressed

{MouseEvent} event The original mouseup event

Source:

Handle Mouse Up event for Push-To-Talk Releases the PTT when the right button is released