Compendium

Compendium

The Compendium class provides an interface for interacting with compendium packs which are collections of similar Entities which are stored outside of the world database but able to be easily imported into an active session.

When the game session is initialized, each available compendium pack is constructed and added to the game.packs.

Each Compendium is distinctly referenced using its canonical "collection" name which is a unique string that contains the package name which provides the compendium as well as the name of the pack within that package. For example, in the DnD5e system, the compendium pack which provides the spells available within the SRD has the collection name "dnd5e.spells".

Constructor

new Compendium(metadata, options)

Source:
Examples
// Let's learn the collection names of all the compendium packs available within a game
game.packs.keys();

// Suppose we are working with a particular pack named "dnd5e.spells"
const pack = game.packs.get("dnd5e.spells");

// We can load the index of the pack which contains all entity IDs, names, and image icons
pack.getIndex().then(index => console.log(index));

// We can find a specific entry in the compendium by its name
let entry = pack.index.find(e => e.name === "Acid Splash");

// Given the entity ID of "Acid Splash" we can load the full Entity from the compendium
pack.getEntity(entry.id).then(spell => console.log(spell));
// We often may want to programmatically create new Compendium content
// Let's start by creating a custom spell as an Item instance
let itemData = {name: "Custom Death Ray", type: "Spell"};
let item = new Item(itemData);

// Once we have an entity for our new Compendium entry we can import it, if the pack is unlocked
pack.importEntity(item);

// When the entity is imported into the compendium it will be assigned a new ID, so let's find it
pack.getIndex().then(index => {
  let entry = index.find(e => e.name === itemData.name));
  console.log(entry);
});

// If we decide to remove an entry from the compendium we can do that by the entry ID
pack.removeEntry(entry.id);
Parameters:
Name Type Description
metadata Object

The compendium metadata, an object provided by game.data

options Object

Application rendering options

Members

(static) defaultOptions

Source:

cls

Source:

A reference to the Entity class object contained within this Compendium pack

collection

Source:

The canonical Compendium name - comprised of the originating package and the pack name

entity :string

Source:

The Entity type which is allowed to be stored in this collection

Type:
  • string

index :Array.<object>

Source:

The most recently retrieved index of the Compendium content This index is not guaranteed to be current - call getIndex() to reload the index

Type:

locked :boolean

Source:

Track whether the compendium pack is locked for editing

Type:
  • boolean

metadata :Object

Source:

The compendium metadata which defines the compendium content and location

Type:
  • Object

private :boolean

Source:

Track whether the compendium pack is private

Type:
  • boolean

title

Source:

Methods

(async, static) create(metadata, options) → {Promise.<Compendium>}

Source:

Create a new Compendium pack using provided

Parameters:
Name Type Description
metadata Object

The compendium metadata used to create the new pack

options Options

Additional options which modify the Compendium creation request

Returns:
Type
Promise.<Compendium>

_canDragDrop()

Source:

_canDragStart()

Source:

_onDragStart()

Source:

_onSearchFilter()

Source:

(async) close()

Source:

configure(settings) → {Promise}

Source:

Assign configuration metadata settings to the compendium pack

Parameters:
Name Type Description
settings Object

The object of compendium settings to define

Returns:

A Promise which resolves once the setting is updated

Type
Promise

(async) createEntity(data, options) → {Promise}

Source:

Create a new Entity within this Compendium Pack using provided data

Parameters:
Name Type Description
data Object

Data with which to create the entry

options Options

Additional options which modify the creation

Returns:

A Promise which resolves to the created Entity once the operation is complete

Type
Promise

(async) delete() → {Promise.<Compendium>}

Source:

Delete a world Compendium pack This is only allowed for world-level packs by a GM user

Returns:
Type
Promise.<Compendium>

(async) deleteEntity(id, options) → {Promise}

Source:

Delete a single Compendium entry by its provided _id

Parameters:
Name Type Description
id string

The entry ID to delete

options Object

Additional options which modify the deletion request

Returns:

A Promise which resolves to the deleted entry ID once the operation is complete

Type
Promise

(async) duplicate(label) → {Promise.<Compendium>}

Source:

Duplicate a compendium pack to the current World

Parameters:
Name Type Description
label
Returns:
Type
Promise.<Compendium>

(async) getContent() → {Promise.<Array>}

Source:

Get the complete set of content for this compendium, loading all entries in full Returns a Promise that resolves to an Array of entries

Returns:
Type
Promise.<Array>

(async) getData()

Source:

(async) getEntity(entryId) → {Promise.<(Entity|null)>}

Source:

Get a single Compendium entry as an Entity instance

Parameters:
Name Type Description
entryId string

The compendium entry ID to load and instantiate

Returns:

A Promise containing the returned Entity, if it exists, otherwise null

Type
Promise.<(Entity|null)>

(async) getEntry(entryId) → {Promise.<(Object|null)>}

Source:

Get a single Compendium entry as an Object

Parameters:
Name Type Description
entryId string

The compendium entry ID to retrieve

Returns:

A Promise containing the return entry data, or null

Type
Promise.<(Object|null)>

(async) getIndex() → {Promise}

Source:

Get the Compendium index Contains names and IDs of all data in the compendium

Returns:

A Promise containing an index of all compendium entries

Type
Promise

(async) importAll(folderIdopt, folderNameopt) → {Promise.<*>}

Source:

Fully import the contents of a Compendium pack into a World folder.

Parameters:
Name Type Attributes Description
folderId string | null <optional>

An existing Folder _id to use.

folderName string <optional>

A new Folder name to create.

Returns:
Type
Promise.<*>

(async) importEntity(entity) → {Promise}

Source:

Import a new Entity into a Compendium pack

Parameters:
Name Type Description
entity Entity

The Entity instance you wish to import

Returns:

A Promise which resolves to the created Entity once the operation is complete

Type
Promise

(async) migrate() → {Promise.<Compendium>}

Source:

Request that a Compendium pack be migrated to the latest System data template

Returns:
Type
Promise.<Compendium>

(async) updateEntity(data, options) → {Promise}

Source:

Update a single Compendium entry programmatically by providing new data with which to update

Parameters:
Name Type Description
data Object

The incremental update with which to update the Entity. Must contain the _id

options Object

Additional options which modify the update request

Returns:

A Promise which resolves with the updated Entity once the operation is complete

Type
Promise