EntityCollection

EntityCollection

An iterable container of Entity objects within the Foundry Virtual Tabletop framework. Each Entity type has it's own subclass of EntityCollection, which defines the abstract interface.

Constructor

(abstract) new EntityCollection(data)

Source:
Parameters:
Name Type Description
data Array

An Array of Entity data from which to create instances

Extends

Members

(static) instance :EntityCollection|null

Source:

Return a reference to the singleton instance of this EntityCollection, or null if it has not yet been created.

Type:

_source :Array

Source:

The source data is, itself, a mapping of IDs to data objects

Type:

apps :Array

Source:

An Array of application references which will be automatically updated when the collection content changes

Type:

directory :SidebarDirectory|null

Source:

Return a reference to the SidebarDirectory application for this EntityCollection, or null if it has not yet been created.

Type:

entity :string

Source:

Return a reference to the base Entity name which is contained within this EntityCollection.

Type:
  • string

entries

Source:
Overrides:

Return an Array of all the entry values in the Collection

name :string

Source:

The EntityCollection name

Type:
  • string

(abstract) object :Entity

Source:

Return a reference to the Entity subclass which should be used when creating elements of this EntityCollection. This should always be an explicit reference to the class which is used in this game to represent the entity, and not the base implementation of that entity type. For example :class:Actor5e not :class:Actor.

Type:

Methods

filter(condition) → {Array.<V>}

Source:
Overrides:
See:
  • {Array#filter}

Filter the Collection, returning an Array of entries which match a functional condition.

Example
let c = new Collection([["a", "AA"], ["b", "AB"], ["c", "CC"]]);
let hasA = c.filters(entry => entry.slice(0) === "A");
Parameters:
Name Type Description
condition function

The functional condition to test

Returns:

An Array of matched values

Type
Array.<V>

find(condition) → {V|null}

Source:
Overrides:
See:
  • {Array#find}

Find an entry in the Map using an functional condition.

Example
let c = new Collection([["a", "A"], ["b", "B"], ["c", "C"]]);
let a = c.find(entry => entry === "A");
Parameters:
Name Type Description
condition function

The functional condition to test

Returns:

The value, if found, otherwise null

Type
V | null

fromCompendium(data) → {Object}

Source:

Apply data transformations when importing an Entity from a Compendium pack

Parameters:
Name Type Description
data Object

The original Compendium entry data

Returns:

The processed data ready for Entity creation

Type
Object

get(key, strict) → {V|null}

Source:
Overrides:

Get an element from the Collection by its key.

Example
let c = new Collection([["a", "A"], ["b", "B"], ["c", "C"]]);
c.get("a"); // "A"
c.get("d"); // null
c.get("d", {strict: true}); // throws Error
Parameters:
Name Type Description
key string

The key of the entry to retrieve

strict boolean

Throw an Error if the requested id does not exist, otherwise return null. Default false

Returns:

The retrieved entry value, if the key exists, otherwise null

Type
V | null

getName(name, strict) → {Entity|null}

Source:

Get an Entity from the EntityCollection by name

Parameters:
Name Type Description
name string

The name of the Entity to retrieve

strict boolean

Throw an Error if the requested id does not exist, otherwise return null. Default false.

Returns:

The retrieved Entity, if one was found, otherwise null;

Type
Entity | null

(async) importFromCollection(collection, entryId, updateDataopt, optionsopt) → {Promise.<Entity>}

Source:

Import an Entity from a compendium collection, adding it to the current World.

Parameters:
Name Type Attributes Description
collection string

The name of the pack from which to import

entryId string

The ID of the compendium entry to import

updateData Object <optional>

Optional additional data used to modify the imported Entity before it is created

options Object <optional>

Optional arguments passed to the Entity.create method

Returns:

A Promise containing the imported Entity

Type
Promise.<Entity>

insert(entity)

Source:

Add a new Entity to the EntityCollection, asserting that they are of the correct type.

Parameters:
Name Type Description
entity Entity

The entity instance to add to the collection

map(transformer) → {Array.<V>}

Source:
Overrides:

Transform each element of the Collection into a new form, returning an Array of transformed values

Parameters:
Name Type Description
transformer function

The transformation function to apply to each entry value

Returns:

An Array of transformed values

Type
Array.<V>

reduce(evaluator, initial) → {any}

Source:
Overrides:
See:
  • {Array#reduce}

Reduce the Collection by applying an evaluator function and accumulating entries

Example
let c = new Collection([["a", "A"], ["b", "B"], ["c", "C"]]);
let letters = c.reduce((s, l) => {
  return s + l;
}, ""); // "ABC"
Parameters:
Name Type Description
evaluator function

A function which mutates the accumulator each iteration

initial any

An initial value which accumulates with each iteration

Returns:

The accumulated result

Type
any

remove(id)

Source:

Remove an Entity from the EntityCollection by its ID.

Parameters:
Name Type Description
id string

The entity ID which should be removed

render() → {this}

Source:

Render any Applications associated with this EntityCollection

Returns:

A reference to the rendered EntityCollection

Type
this