Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    The Collection of Setting documents which exist within the active World. This collection is accessible as game.settings.storage.get("world")

    foundry.documents.Setting: The Setting document

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _source: object[]

    The source data array from which the Documents in the WorldCollection are created

    An Array of application references which will be automatically updated when the collection content changes

    invalidDocumentIds: Set<string> = ...

    Record the set of document ids where the Document was not initialized because of invalid source data

    documentName: string = "Setting"

    Accessors

    • get contents(): V[]

      Return an Array of all the entry values in the Collection

      Returns V[]

    • get directory(): null

      Returns null

    • get documentClass(): typeof Document

      A reference to the Document class definition which is contained within this DocumentCollection.

      Returns typeof Document

    • get instance(): WorldCollection<any>

      Return a reference to the singleton instance of this WorldCollection, or null if it has not yet been created.

      Returns WorldCollection<any>

    • get registeredSheets(): DocumentSheet[]

      Return an array of currently registered sheet classes for this Document type.

      Returns DocumentSheet[]

    Methods

    • Then iterating over a Collection, we should iterate over its values instead of over its entries

      Returns MapIterator<Setting>

    • Instantiate a Document for inclusion in the Collection.

      Parameters

      • data: object

        The Document data.

      • Optionalcontext: object = {}

        Document creation context.

      Returns Setting

    • Filter the Collection, returning an Array of entries which match a functional condition.

      Parameters

      • condition: (
            value: Setting,
            index: number,
            collection: Collection<string, Setting>,
        ) => unknown

        The functional condition to test.

      Returns Setting[]

      An Array of matched values

      let c = new Collection([["a", "AA"], ["b", "AB"], ["c", "CC"]]);
      let hasA = c.filters(entry => entry.slice(0) === "A");
    • Find an entry in the Map using a functional condition.

      Parameters

      • condition: (
            value: Setting,
            index: number,
            collection: Collection<string, Setting>,
        ) => unknown

        The functional condition to test.

      Returns Setting | undefined

      The value, if found, otherwise undefined

      let c = new Collection([["a", "A"], ["b", "B"], ["c", "C"]]);
      c.get("a") === c.find(entry => entry === "A"); // true
    • Apply a function to each element of the collection

      Parameters

      • fn: (value: Setting, index: number) => void

        A function to apply to each element

      Returns void

      Array#forEach

      let c = new Collection([["a", {active: false}], ["b", {active: false}], ["c", {active: false}]]);
      c.forEach(e => e.active = true);
    • Apply data transformations when importing a Document from a Compendium pack

      Parameters

      • document: object | Setting

        The source Document, or a plain data object

      • Optionaloptions: FromCompendiumOptions = {}

        Additional options which modify how the document is imported

      Returns object

      The processed data ready for world Document creation

    • Get an element from the DocumentCollection by its ID.

      Parameters

      • id: string

        The ID of the Document to retrieve.

      • Optionaloptions: { invalid?: boolean; strict?: boolean } = {}

        Additional options to configure retrieval.

        • Optionalinvalid?: boolean

          Allow retrieving an invalid Document.

        • Optionalstrict?: boolean

          Throw an Error if the requested Document does not exist.

      Returns Setting

      If strict is true and the Document cannot be found.

    • Obtain a temporary Document instance for a document id which currently has invalid source data.

      Parameters

      • id: string

        A document ID with invalid source data.

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

        Additional options to configure retrieval.

        • Optionalstrict?: boolean

          Throw an Error if the requested ID is not in the set of invalid IDs for this collection.

      Returns void | Setting

      An in-memory instance for the invalid Document

      If strict is true and the requested ID is not in the set of invalid IDs for this collection.

    • Return the serialized value of the world setting as a string

      Parameters

      • key: string

        The setting key

      • Optionaluser: string

        For user-scoped settings, the user ID.

      Returns string | null

      The serialized setting string

    • Get an entry from the Collection by name. Use of this method assumes that the objects stored in the collection have a "name" attribute.

      Parameters

      • name: string

        The name of the entry to retrieve

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

        Additional options that affect how entries are retrieved

        • Optionalstrict?: boolean

          Throw an Error if the requested name does not exist. Default false.

      Returns Setting | undefined

      The retrieved entry value, if one was found, otherwise undefined

      let c = new Collection([["a", "Alfred"], ["b", "Bob"], ["c", "Cynthia"]]);
      c.getName("Alfred"); // "Alfred"
      c.getName("D"); // undefined
      c.getName("D", {strict: true}); // throws Error
    • Return the Setting document with the given key.

      Parameters

      • key: string

        The setting key

      • Optionaluser: string = null

        For user-scoped settings, the user ID.

      Returns Setting

      The Setting

    • Import a Document from a Compendium collection, adding it to the current World. This method is a convenience wrapper around the underlying WorldCollection#importDocument workflow.

      Parameters

      • pack: CompendiumCollection<any>

        The CompendiumCollection instance from which to import

      • id: string

        The ID of the compendium entry to import

      • OptionalupdateData: object = {}

        Optional additional data used to modify the imported Document before it is created

      • Optionaloptions: any = {}

        Options passed to WorldCollection#importDocument

      Returns Promise<Setting>

      The imported Document instance

    • Transform each element of the Collection into a new form, returning an Array of transformed values

      Type Parameters

      • U

      Parameters

      • transformer: (element: Setting, index: number, collection: Collection<string, Setting>) => U

        A transformation function applied to each entry value.

      Returns U[]

      An Array of transformed values

    • Reduce the Collection by applying an evaluator function and accumulating entries

      Type Parameters

      • U

      Parameters

      • reducer: (
            accum: U,
            element: T,
            index: number,
            collection: Collection<string, Setting>,
        ) => U

        A reducer function applied to each entry value.

      • initial: U

        An initial value which accumulates with each iteration

      Returns U

      The accumulated result

      let c = new Collection([["a", "A"], ["b", "B"], ["c", "C"]]);
      let letters = c.reduce((s, l) => {
      return s + l;
      }, ""); // "ABC"
    • Render any Applications associated with this DocumentCollection.

      Parameters

      • Optionalforce: boolean = false

        Force rendering

      • Optionaloptions: object = {}

        Optional options

      Returns void

    • Find all Documents which match a given search term using a full-text search against their indexed HTML fields and their name. If filters are provided, results are filtered to only those that match the provided values.

      Parameters

      • search: { exclude?: string[]; filters?: FieldFilter[]; query?: string }

        An object configuring the search

        • Optionalexclude?: string[]

          An array of document IDs to exclude from search results

        • Optionalfilters?: FieldFilter[]

          An array of filters to apply

        • Optionalquery?: string

          A case-insensitive search string

      Returns object[] | Setting[]

    • Test whether a condition is met by some entry in the Collection.

      Parameters

      • condition: (element: T, index: number, set: Collection<string, Setting>) => boolean

        The functional condition to test.

      Returns boolean

      Was the test condition passed by at least one entry?

    • Convert the Collection to a primitive array of its contents.

      Returns object[]

      An array of contained values

    • Update all objects in this DocumentCollection with a provided transformation. Conditionally filter to only apply to Entities which match a certain condition.

      Parameters

      • transformation: object | Function

        An object of data or function to apply to all matched objects

      • condition: Function | null = null

        A function which tests whether to target each object

      • Optionaloptions: object = {}

        Additional options passed to Document.updateDocuments

      Returns Promise<Setting[]>

      An array of updated data once the operation is complete

    • Protected

      Initialize the DocumentCollection by constructing any initially provided Document instances

      Returns void

    • Get the searchable fields for a given document or index, based on its data model

      Parameters

      • documentName: string

        The document name

      • Optionaltype: string

        A document subtype

      Returns Record<string, SearchableField>

      A record of searchable DataField definitions

    • Register a Document sheet class as a candidate which can be used to display Documents of a given type. See foundry.applications.apps.DocumentSheetConfig.registerSheet for details.

      Parameters

      • ...args: any[]

        Arguments forwarded to the DocumentSheetConfig.registerSheet method

      Returns void

      foundry.documents.collections.Actors.registerSheet("dnd5e", ActorSheet5eCharacter, {
      types: ["character],
      makeDefault: true
      });
    • Unregister a Document sheet class, removing it from the list of available sheet Applications to use. See foundry.applications.apps.DocumentSheetConfig.unregisterSheet for detauls.

      Parameters

      • ...args: any[]

        Arguments forwarded to the DocumentSheetConfig.unregisterSheet method

      Returns void

      foundry.documents.collections.Actors.unregisterSheet("core", ActorSheet);