A Vision Mode which can be selected for use by a Token. The selected Vision Mode alters the appearance of various aspects of the canvas while that Token is the POV.

Hierarchy (View Summary)

Constructors

  • Construct a Vision Mode using provided configuration parameters and callback functions.

    Parameters

    • data: object = {}

      Data which fulfills the model defined by the VisionMode schema.

    • Optionaloptions: object = {}

      Additional options passed to the DataModel constructor.

    Returns VisionMode

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.

animated: boolean

A flag for whether this vision source is animated

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.

LIGHTING_LEVELS: Readonly<
    {
        BRIGHT: 2;
        BRIGHTEST: 3;
        DARKNESS: -2;
        DIM: 1;
        HALFDARK: -1;
        UNLIT: 0;
    },
> = LIGHTING_LEVELS

The lighting illumination levels which are supported.

LIGHTING_VISIBILITY: { DISABLED: number; ENABLED: number; REQUIRED: number } = ...

Flags for how each lighting channel should be rendered for the currently active vision modes:

  • Disabled: this lighting layer is not rendered, the shaders does not decide.
  • Enabled: this lighting layer is rendered normally, and the shaders can choose if they should be rendered or not.
  • Required: the lighting layer is rendered, the shaders does not decide.
LOCALIZATION_PREFIXES: string[] = []

A set of localization prefix paths which are used by this DataModel. This provides an alternative to defining the label and hint property of each field by having foundry map the labels to a structure inside the path provided by the prefix.

JavaScript class definition and localization call.

class MyDataModel extends foundry.abstract.DataModel {
static defineSchema() {
return {
foo: new foundry.data.fields.StringField(),
bar: new foundry.data.fields.NumberField()
};
}
static LOCALIZATION_PREFIXES = ["MYMODULE.MYDATAMODEL"];
}

Hooks.on("i18nInit", () => {
// Foundry will attempt to automatically localize models registered for a document subtype, so this step is only
// needed for other data model usage, e.g. for a Setting.
Localization.localizeDataModel(MyDataModel);
});

JSON localization file

{
"MYMODULE": {
"MYDATAMODEL": {
"FIELDS" : {
"foo": {
"label": "Foo",
"hint": "Instructions for foo"
},
"bar": {
"label": "Bar",
"hint": "Instructions for bar"
}
}
}
}
}

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 perceivesLight(): boolean

    Does this vision mode enable light sources? True unless it disables lighting entirely.

    Returns boolean

  • get schema(): SchemaField

    Define the data schema for this document instance.

    Returns SchemaField

  • get schema(): SchemaField

    The Data Schema for all instances of this DataModel.

    Returns SchemaField

Methods

  • Special activation handling that could be implemented by VisionMode subclasses

    Parameters

    Returns void

  • Special deactivation handling that could be implemented by VisionMode subclasses

    Parameters

    Returns void

  • Special handling which is needed when this Vision Mode is activated for a PointVisionSource.

    Parameters

    Returns void

  • An animation function which runs every frame while this Vision Mode is active.

    Parameters

    • dt: number

      The deltaTime passed by the PIXI Ticker

    Returns any

  • Special handling which is needed when this Vision Mode is deactivated for a PointVisionSource.

    Parameters

    Returns void

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

    Returns void

  • 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

    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

  • 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

  • Define the data schema for models of this type. The schema is populated the first time it is accessed and cached for future reuse.

    The schema, through its fields, provide the essential cleaning, validation, and initialization methods to turn the _source values into direct properties of the data model. The schema is a static property of the model and is reused by all instances to perform validation.

    The schemas defined by the core software in classes like foundry.documents.BaseActor are validated by the server, where user code does not run. However, almost all documents have a flags field to store data, and many have a system field that can be configured to be a foundry.abstract.TypeDataModel instance. Those models are not constructed on the server and rely purely on client-side code, which means certain extra-sensitive fields must be also be registered through your package manifest. foundry.packages.types.ServerSanitizationFields

    Returns {
        canvas: SchemaField;
        id: StringField;
        label: StringField;
        lighting: SchemaField;
        tokenConfig: BooleanField;
        vision: SchemaField;
    }

    class SomeModel extends foundry.abstract.DataModel {
    static defineSchema() {
    return {
    foo: new foundry.data.fields.StringField()
    }
    }
    }

    class AnotherModel extends SomeModel {
    static defineSchema() {
    // Inheritance and object oriented principles apply to schema definition
    const schema = super.defineSchema()

    schema.bar = new foundry.data.fields.NumberField()

    return schema;
    }
    }
  • 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

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

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