Items

Item entities represent objects or features that are owned by an Actor. While the term item tends to imply physical possessions, as a developer in Foundry Virtual Tabletop you should consider Items as the building block for anything that can be owned by an Actor. For example, in the D&D5e system, Item types are used for Classes, Spells, and Feats in addition to standard inventory and equipment.

The FVTT framework provides core APIs for manipulating and modifying Items including support to allow Items to belong to an Actor to modify the Actor’s owned version of that Item.

There are several important API layers which are useful when working with Items. The Items() collection has all of the Item() instances which are defined at the World level (as oppoosed to owned items which belong to a specific actor). This Items collection is available under game.items.

The Item() class represents a single item which may be unowned (and defined at the World level) or owned (and defined at the Actor level). Owned items which belong to an Actor() are defined in that actor’s data model under actor.data.items. The Item() class may be overridden by a system or module by defining the Config.Item.entityClass global configuration value.

When viewing or interacting with an item’s data, the item is rendered and edited using the ItemSheet() class which can be extended or overridden by systems or modules. To override the default implementation, a mod should define the CONFIG.Item.sheetClass global configuration value.



The Items Collection

class Items()

The Collection() of Item() entities The items collection is accessible within the game as game.items

Items.Collection.insert(entity)

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

Arguments:
  • entity (Entity) – The entity instance to add to the collection
Items.Collection.remove(id)

Remove an Entity from the Collection by its ID.

Arguments:
  • id (String) – The entity ID which should be removed
Items.Collection.get(id)

Get an element from the collection by ID

Arguments:
  • id (String) – The entity ID to retrieve from the collection
Returns:

Entity – The retrieved Entity, if the ID was found, otherwise null;

Items.Collection.index(id)

Retrieve the index of an entity within the collection by its ID

Arguments:
  • id (String) – The entity ID to retrieve from the collection
Returns:

Number – The index of the Entity within the collection, if found, otherwise -1;

Items.Collection.render(force)

Render all applications associated with this Collection

Items.importFromCollection(collection, entryId)

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

Arguments:
  • collection (String) – The name of the pack from which to import
  • entryId (String) – The ID of the compendium entry to import
Returns:

Promise – A Promise containing the imported Item

Items.object

Elements of the Items collection are instances of the Item class, or a subclass thereof


The Item Class

class CONFIG.Item()

Configuration for the default Item entity class


The Item Sheet

class ItemSheet(item, options)

The default Item Sheet

This is a Application that is responsible for rendering an item’s attributes and allowing the item to be edited.

System modifications may elect to override this class to better suit their own game system by re-defining the value CONFIG.Item.sheetClass.

For basic or aesthetic modifications, overriding this class entirely may not be necessary and you may simply wish to replace the default HTML template. This can be accomplished by re-defning CONFIG.ItemSheet.template.

Arguments:
  • item (Item) – The Item instance being displayed within the sheet.
  • options (Object) – Additional options which modify the rendering of the item.
  • options.editable (Boolean) – Is the item editable? Default is true.
ItemSheet.activateListeners(html)

Activate listeners which provide interactivity for item sheet events

Arguments:
  • html (jQuery) – The HTML object returned by template rendering
ItemSheet.actor

type: Actor

The Actor instance which owns this item. This may be null if the item is unowned.

ItemSheet.defaultOptions

Assign the default options which are supported by the CharacterSelect menu

ItemSheet.getData()

Customize the data provided to the item sheet for rendering. By default we just duplicate the item data.

ItemSheet.title

type: String

The displayed window title for the item sheet - just the item’s name by default