The data model for a behavior that receives Region events.

Hierarchy (View Summary)

Constructors

Properties

_source: object

The source data object for this DataModel instance. Once constructed, the source object is sealed such that no keys may be added nor removed.

events: Set<string> = ...

The events that are handled by the behavior.

parent: null | DataModel<object, DataModelConstructionContext>

An immutable reverse-reference to a parent DataModel to which this model belongs.

_schema: SchemaField

The defined and cached Data Schema for all instances of this DataModel.

events: Record<
    string,
    (this: RegionBehaviorType, event: RegionEvent) => Promise<void>,
> = {}

The Region events that are handled by the behavior.

LOCALIZATION_PREFIXES: string[] = []

A set of localization prefix paths which are used by this data model.

Accessors

  • get invalid(): boolean

    Is the current state of this DataModel invalid? The model is invalid if there is any unresolved failure.

    Returns boolean

  • get region(): null | RegionDocument

    A convenience reference to the RegionDocument which contains this behavior sub-type.

    Returns null | RegionDocument

  • get scene(): null | documents.Scene

    A convenience reference to the Scene which contains this behavior sub-type.

    Returns null | documents.Scene

  • get schema(): SchemaField

    Define the data schema for this document instance.

    Returns SchemaField

Methods

  • Internal

    Called by ClientDocument#_preCreate.

    Parameters

    • data: object

      The initial data object provided to the document creation request

    • options: object

      Additional options which modify the creation request

    • user: BaseUser

      The User requesting the document creation

    Returns Promise<boolean | void>

    Return false to exclude this Document from the creation operation

  • Prepare data related to this DataModel itself, before any derived data is computed.

    Called before ClientDocumentMixin#prepareBaseData in ClientDocumentMixin#prepareData.

    Returns void

  • Apply transformations of derivations to the values of the source data object. Compute data fields whose values are not stored to the database.

    Called before ClientDocumentMixin#prepareDerivedData in ClientDocumentMixin#prepareData.

    Returns void

  • Reset the state of this data instance back to mirror the contained source data, erasing any changes.

    Returns void

  • Convert this Document to some HTML display for embedding purposes.

    Parameters

    • config: DocumentHTMLEmbedConfig

      Configuration for embedding behavior.

    • Optionaloptions: any = {}

      The original enrichment options for cases where the Document embed content also contains text that must be enriched.

    Returns Promise<any>

  • Extract the source data for the DataModel into a simple object format that can be serialized.

    Returns object

    The document source data expressed as a plain object

  • Copy and transform the DataModel into a plain object. Draw the values of the extracted object from the data source (by default) otherwise from its transformed values.

    Parameters

    • Optionalsource: boolean = true

      Draw values from the underlying data source rather than transformed values

    Returns object

    The extracted primitive object

  • Update the DataModel locally by applying an object of changes to its source data. The provided changes are expanded, cleaned, validated, and stored to the source data object for this model. The provided changes argument is mutated in this process. The source data is then re-initialized to apply those changes to the prepared data. The method returns an object of differential changes which modified the original data.

    Parameters

    • changes: object = {}

      New values which should be applied to the data model

    • options: DataModelUpdateOptions = {}

      Options which determine how the new data is merged

    Returns object

    An object containing differential keys and values that were changed

    An error if the requested data model changes were invalid

  • Validate the data contained in the document to check for type and content. If changes are provided, missing types are added to it before cleaning and validation. This mutates the provided changes. This function throws an error if data within the document is not valid.

    Parameters

    Returns boolean

    Whether the data source or proposed change is reported as valid. A boolean is always returned if validation is non-strict.

    An error thrown if validation is strict and a failure occurs.

  • Protected

    Configure the data model instance before validation and initialization workflows are performed.

    Parameters

    • Optionaloptions: object = {}

      Additional options modifying the configuration

    Returns void

  • Protected

    Get the terrain effects of this behavior for the movement of the given token. This function is called only for behaviors that are not disabled. The terrain data is created from the terrain effects (CONFIG.Token.movement.TerrainData.resolveTerrainEffects). Returns an empty array by default.

    Type Parameters

    • TerrainEffect

    Parameters

    • token: TokenDocument

      The token being or about to be moved within the region of this behavior

    • segment: Pick<TokenMovementWaypoint, "shape" | "height" | "width" | "action"> & {
          preview: boolean;
      }

      The segment data of the token's movement

    Returns TerrainEffect[]

    The terrain effects that apply to this token's movement

  • Protected

    Handle the Region event.

    Parameters

    Returns Promise<void>

  • Protected

    Initialize the instance by copying data from the source object to instance attributes. This mirrors the workflow of SchemaField#initialize but with some added functionality.

    Parameters

    • Optionaloptions: object = {}

      Options provided to the model constructor

    Returns void

  • Protected

    Initialize the source data for a new DataModel instance. One-time migrations and initial cleaning operations are applied to the source data.

    Parameters

    • data: object | DataModel<object, DataModelConstructionContext>

      The candidate source data from which the model will be constructed

    • Optionaloptions: object = {}

      Options provided to the model constructor

    Returns object

    Migrated and cleaned source data which will be stored to the model instance, which is the same object as the data argument

  • Protected

    Called by ClientDocument#_onCreate.

    Parameters

    • data: object

      The initial data object provided to the document creation request

    • options: object

      Additional options which modify the creation request

    • userId: string

      The id of the User requesting the document update

    Returns void

  • Protected

    Called by ClientDocumentMixin#_onDelete.

    Parameters

    • options: object

      Additional options which modify the deletion request

    • userId: string

      The id of the User requesting the document update

    Returns void

  • Protected

    Called by ClientDocumentMixin#_onUpdate.

    Parameters

    • changed: object

      The differential data that was changed relative to the documents prior values

    • options: object

      Additional options which modify the update request

    • userId: string

      The id of the User requesting the document update

    Returns void

  • Protected

    Called by ClientDocumentMixin#_preDelete.

    Parameters

    • options: object

      Additional options which modify the deletion request

    • user: BaseUser

      The User requesting the document deletion

    Returns Promise<boolean | void>

    A return value of false indicates the deletion operation should be cancelled.

  • Protected

    Called by ClientDocumentMixin#_preUpdate.

    Parameters

    • changes: object

      The candidate changes to the Document

    • options: object

      Additional options which modify the update request

    • user: BaseUser

      The User requesting the document update

    Returns Promise<boolean | void>

    A return value of false indicates the update operation should be cancelled.

  • Clean a data source object to conform to a specific provided schema.

    Parameters

    • Optionalsource: object = {}

      The source data object

    • Optionaloptions: object = {}

      Additional options which are passed to field cleaning methods

    Returns object

    The cleaned source data, which is the same object as the source argument

  • Migrate candidate source data for this DataModel which may require initial cleaning or transformations.

    Parameters

    • source: object

      The candidate source data from which the model will be constructed

    Returns object

    Migrated source data, which is the same object as the source argument

  • Wrap data migration in a try/catch which attempts it safely

    Parameters

    • source: object

      The candidate source data from which the model will be constructed

    Returns object

    Migrated source data, which is the same object as the source argument

  • Take data which conforms to the current data schema and add backwards-compatible accessors to it in order to support older code which uses this data.

    Parameters

    • data: object

      Data which matches the current schema

    • Optionaloptions: { embedded?: boolean } = {}

      Additional shimming options

      • Optionalembedded?: boolean

        Apply shims to embedded models?

    Returns object

    Data with added backwards-compatible properties, which is the same object as the data argument

  • Evaluate joint validation rules which apply validation conditions across multiple fields of the model. Field-specific validation rules should be defined as part of the DataSchema for the model. This method allows for testing aggregate rules which impose requirements on the overall model.

    Parameters

    • data: object

      Candidate data for the model

    Returns void

    An error if a validation failure is detected

  • Protected

    Create the events field.

    Parameters

    • options: { events?: string[]; initial?: string[] } = {}

      Options which configure how the events field is declared

      • Optionalevents?: string[]

        The event names to restrict to.

      • Optionalinitial?: string[]

        The initial set of events that should be default for the field

    Returns SetField

  • Protected

    A generator that orders the DataFields in the DataSchema into an expected initialization order.

    Returns Generator<[string, DataField], any, any>