Class SyncedDataManager

Hierarchy

  • DataManager
    • SyncedDataManager

Constructors

Properties

count: number

Return the total number of entries in this Data Manager.

events: EventEmitter

The DataManager's event emitter.

freeze: boolean

Gets or sets the frozen state of this Data Manager. A frozen Data Manager will block all attempts to create new values or update existing ones.

list: {
    [key: string]: any;
}

The data list.

Type declaration

  • [key: string]: any
parent: any

The object that this DataManager belongs to.

ready: boolean = false
values: {
    [key: string]: any;
}

The public values list. You can use this to access anything you have stored in this Data Manager. For example, if you set a value called gold you can access it via:

this.data.values.gold;

You can also modify it directly:

this.data.values.gold += 1000;

Doing so will emit a setdata event from the parent of this Data Manager.

Do not modify this object directly. Adding properties directly to this object will not emit any events. Always use DataManager.set to create new items the first time around.

Type declaration

  • [key: string]: any

Methods

  • Passes all data entries to the given callback.

    Parameters

    • callback: DataEachCallback

      The function to call.

    • Optional context: any

      Value to use as this when executing callback.

    • Rest ...args: any[]

      Additional arguments that will be passed to the callback, after the game object, key, and data.

    Returns this

  • Retrieves the value for the given key, or undefined if it doesn't exist.

    You can also access values via the values object. For example, if you had a key called gold you can do either:

    this.data.get('gold');
    

    Or access the value directly:

    this.data.values.gold;
    

    You can also pass in an array of keys, in which case an array of values will be returned:

    this.data.get([ 'gold', 'armor', 'health' ]);
    

    This approach is useful for destructuring arrays in ES6.

    Parameters

    • key: string | string[]

      The key of the value to retrieve, or an array of keys.

    Returns any

  • Retrieves all data values in a new object.

    Returns {
        [key: string]: any;
    }

    • [key: string]: any
  • Determines whether the given key is set in this Data Manager.

    Please note that the keys are case-sensitive and must be valid JavaScript Object property strings. This means the keys gold and Gold are treated as two unique values within the Data Manager.

    Parameters

    • key: string

      The key to check.

    Returns boolean

  • Merge the given object of key value pairs into this DataManager.

    Any newly created values will emit a setdata event. Any updated values (see the overwrite argument) will emit a changedata event.

    Parameters

    • data: {
          [key: string]: any;
      }

      The data to merge.

      • [key: string]: any
    • Optional overwrite: boolean

      Whether to overwrite existing data. Defaults to true. Default true.

    Returns this

  • Retrieves the data associated with the given 'key', deletes it from this Data Manager, then returns it.

    Parameters

    • key: string

      The key of the value to retrieve and delete.

    Returns any

  • Queries the DataManager for the values of keys matching the given regular expression.

    Parameters

    • search: RegExp

      A regular expression object. If a non-RegExp object obj is passed, it is implicitly converted to a RegExp by using new RegExp(obj).

    Returns {
        [key: string]: any;
    }

    • [key: string]: any
  • Delete all data in this Data Manager and unfreeze it.

    Returns this

  • Freeze or unfreeze this Data Manager. A frozen Data Manager will block all attempts to create new values or update existing ones.

    Parameters

    • value: boolean

      Whether to freeze or unfreeze the Data Manager.

    Returns this

  • Toggle a boolean value for the given key. If the key doesn't already exist in the Data Manager then it is toggled from false.

    When the value is first set, a setdata event is emitted.

    Parameters

    • key: string

      The key to toggle the value for.

    Returns this