Collection

Collection

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

Constructor

(abstract) new Collection(data, apps)

Source:
Parameters:
Name Type Description
data Array

An Array of Entity data from which to create instances

apps Array

An Array of Application instances which the Collection modifies

Members

(static) instance :Collection|null

Source:

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

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 Collection, or null if it has not yet been created.

Type:

entities :Array

Source:

An Array of all the Entity instances of this type which are contained within the collection

Type:

entity :string

Source:

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

Type:
  • string

name :string

Source:

The Collection name

Type:
  • string

(abstract) object :Entity

Source:

Return a reference to the Entity subclass which should be used when creating elements of this Collection. 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

(static) socketListeners(socket)

Source:

Activate socket listeners related to this particular Entity type.

Parameters:
Name Type Description
socket Socket

The open game socket

get(id, strict) → {Entity|null}

Source:

Get an element from the collection by ID.

Parameters:
Name Type Description
id string

The entity ID to retrieve from the collection

strict boolean

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

Returns:

The retrieved Entity, if the ID 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>

initialize() → {this}

Source:

Initialize the Collection instance by preparing all of it's contained Entities

Returns:

A reference to the initialized Collection

Type
this

insert(entity)

Source:

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

Parameters:
Name Type Description
entity Entity

The entity instance to add to the collection

remove(id)

Source:

Remove an Entity from the Collection 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 Collection

Returns:

A reference to the rendered Collection

Type
this