The Actor Entity

For application developers there are three important layers which are useful when working with Actors. The Actors() collection manages the set of actor entities which are present within the world. Each individual actor within that collection is an instance of the Actor() class (by default). Game systems which want more control over the behaviors and attributes of an actor may override this to a subclass included in their own definition.

When viewing or interacting with an actor inside the tabletop framework, the actor’s data is rendered and edited using the ActorSheet() class (by default). Game systems which want to fine-tune how the actor data is rendered may override this to a subclass included in their own definition.


The Actors Collection

class Actors(args)

The Collection() of Actor() entities The actors collection is accessible within the game as game.actors

Actors.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
Actors.Collection.remove(id)

Remove an Entity from the Collection by its ID.

Arguments:
  • id (String) – The entity ID which should be removed
Actors.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;

Actors.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;

Actors.Collection.render()

Re-render any currently visible applications associated with this Collection

Actors.object

type: Actor

Elements of the Actors collection are instances of the Actor class, or a subclass thereof

Actors.registerSheet(scope, cls, types, makeDefault)

Register an Actor sheet class as a candidate which can be used to display Actors of a given type

Arguments:
  • scope (String) – Provide a unique namespace scope for this sheet
  • cls (Application) – A defined Application class used to render the sheet
  • types (Array) – An Array of types for which this sheet can be used
  • makeDefault (Boolean) – Make this sheet the default choice for provided types? Default is false
Actors.socketListeners(socket)

Open additional socket listeners which transact Actor data

Actors.types

type: Array

Get the valid types of Actor for this game system

Actors.unregisterSheet(scope, cls, types)

Unregister an Actor sheet class, removing it from the list of avaliable sheet Applications to use

Arguments:
  • scope (String) – Provide a unique namespace scope for this sheet
  • cls (Application) – A defined Application class used to render the sheet
  • types (Array) – An Array of types for which this sheet should be removed

The Actor Class

class foundry.Actor()

The Actor class is a type of Entity() which represents the protagonists, characters, enemies, and more that inhabit the World.

foundry.Actor.Entity.create(data, options)

Create a new entity using provided input data The data for entity creation is typically provided from the server through the ‘create<Entity>’ socket Alternatively, the creation event may originate locally and the new entity can be pushed back to the server

Arguments:
  • data (Object) – The data with which to create the entity
  • options (Object) – Additional options which customize the creation workflow
  • options.temporary (Boolean) – Create a temporary entity which is not saved to the world database. Default is false.
  • options.displaySheet (Boolean) – Show the configuration sheet for the created entity once it is created. Default is true.
Returns:

Promise – A Promise which resolves to contain the created Entity

foundry.Actor.Entity.update(data, options)

Update the current entity using new data This new data is typically provided from the server through the ‘update<Entity>’ socket Alternatively, the update may originate locally, in which case it can be pushed back to the server

Arguments:
  • data (Object) – The data with which to update the entity
  • options (Object) – Additional options which customize the update workflow
Returns:

Promise – A Promise which resolves to the updated Entity

foundry.Actor.Entity.delete(options)

Delete the entity, removing it from its collection and deleting its data record

Arguments:
  • options (Object) – Additional options which customize the deletion workflow
Returns:

Promise – A Promise which resolves to the ID of the deleted Entity once handled by the server

foundry.Actor._onUpdate(data)

Additional updating steps for the Actor entity when new data is saved which trigger some related updates.

Re-render the parent collection if names, images, or permissions have changed Re-render active tokens if their linked attribute has changed

Arguments:
  • data (Object) – The new data object which was used to update the Actor
foundry.Actor._tokenImages

type: Array

Cache an Array of allowed Token images if using a wildcard path

foundry.Actor.createOwnedItem(itemData, options)

Create a new item owned by this Actor.

Arguments:
  • itemData (Object) – Data for the newly owned item
  • options (Object) – Item creation options
  • options.displaySheet (Boolean) – Render the Item sheet for the newly created item data
Returns:

Promise.<Item> – A Promise containing the newly created owned Item instance

foundry.Actor.deleteOwnedItem(itemId, options)

Delete an owned item by its ID

Arguments:
  • itemId (Number) – The ID of the item to delete
  • options (Object) – Item deletion options
Returns:

Promise.<Number> – A Promise resolving to the deleted item ID

foundry.Actor.getActiveTokens(linked=false)

Retrieve an Array of active tokens which represent this Actor in the current canvas Scene. If the canvas is not currently active, or there are no linked actors, the returned Array will be empty.

Arguments:
  • linked (Boolean) – Only return tokens which are linked to the Actor. Default (false) is to return all tokens even those which are not linked.
Returns:

Array – An array of tokens in the current Scene which reference this Actor.

foundry.Actor.getOwnedItem(itemId)

Get an owned item by it’s ID, initialized as an Item entity class

Arguments:
  • itemId (Number) – The ID of the owned item
Returns:

Item|null – An Item class instance for that owned item or null if the itemId does not exist

foundry.Actor.getTokenImages()

Get an Array of Token images which could represent this Actor

Returns:Promise
foundry.Actor.img

type: String

A convenient reference to the file path of the Actor’s profile image

foundry.Actor.importItemFromCollection(collection, entryId)

Import a new owned Item from a compendium collection The imported Item is then added to the Actor as an owned item.

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

A boolean flag for whether this Actor is a player-owned character.

foundry.Actor.items

type: Array

A convenient reference to the Array of Items which are owned by the Actor

foundry.Actor.token

type: Object

A convenient reference to the default Token data for the Actor

foundry.Actor.updateOwnedItem(itemData, options)

Update an owned item using provided new data

Arguments:
  • itemData (Object) – Data for the item to update
  • options (Object) – Item update options
Returns:

Promise.<Item> – A Promise resolving to the updated Item object


The Actor Sheet

class ActorSheet(actor, options)

The default Actor Sheet

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

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

Arguments:
  • actor (Actor) – The Actor instance being displayed within the sheet.
  • options (Object) – Additional options which modify the rendering of the Actor’s sheet.
  • options.editable (Boolean) – Is the Actor editable? Default is true.
ActorSheet.activateListeners(html)

Activate the default set of listeners for the Actor Sheet These listeners handle basic stuff like form submission or updating images

Arguments:
  • html (JQuery) – The rendered template ready to have listeners attached
ActorSheet.actor

type: Actor

A convenience reference to the Actor entity

ActorSheet.getData()

Prepare data for rendering the Actor sheet The prepared data object contains both the actor data as well as additional sheet options