Перейти к основному содержанию

Saver

Module used to save data between world sessions, different worlds have their own saves.

Index

Interfaces

DefaultSavesFunction

  • DefaultSavesFunction(): object
  • Returns object

IHashSaver

IHashSaver:

getId

  • getId(): number
  • Returns number

setId

  • setId(id: number): void
  • Parameters

    • id: number

    Returns void

IObjectSaver

IObjectSaver:

Interface that should be implemented to pass object as Saver.registerObjectSaver parameter.

read

Function that converts serialized data from saves scope to your object instance.

save

Function used to save serialized data of your object instance.

IScopeSaver

IScopeSaver:

Interface that should be implemented to pass object as Saver.registerScopeSaver parameter.

optionalgetDefaultSaves

getDefaultSaves?: DefaultSavesFunction

Function that returns default data to be passed to read if there is no previous data.

@since

2.3.1b116-3

read

Function that loads data from saves scope.

save

Function used to save data.

ObjectLoadFunction


  • Parameters

    • obj: object

      object data from saves

    Returns SaveableObjectType

    Instance of newly instantiated object.

ObjectSaveFunction


  • Parameters

    Returns object

    Object data to be serialized in saves scope.

ScopeLoadFunction

  • ScopeLoadFunction(scope: object): void
  • Parameters

    • scope: object

      object data from saves

    Returns void

ScopeSaveFunction

  • ScopeSaveFunction(): object

  • Returns object

    Object data to be serialized in saves scope.

Type Aliases

SaveableObjectType

SaveableObjectType: object | org.json.JSONObject | IHashSaver

Functions

addSavesScope

  • Creates saves scope, a universal data storage container. This storage container should be used whenever you need to save some data between world sessions. If you want to store primitives, use an object to wrap them.

    @example
    let thirst = 20;
    Saver.addSavesScope("thirst_library.thirst",
    function read(scope) {
    thirst = scope ? scope.thirst : 20;
    },
    function save() {
    return { thirst: thirst };
    }
    );

    Parameters

    Returns void

deserialize

  • deserialize(obj: object): any

deserializeFromString

  • deserializeFromString(str: string): any

registerObject

registerObjectSaver

  • registerObjectSaver(name: string, saver: IObjectSaver): number
  • Registers object as object instance saver.

    @example
    function PedestalTile(type) {
    this.type = type;
    Saver.registerObject(this, PedestalTile.saverId);
    }
    PedestalTile.saverId = Saver.registerObjectSaver("mystical_agriculture.pedestal", {
    read(obj) {
    return new PedestalTile(obj.type);
    },
    save(instance) {
    return { type: instance.type };
    }
    });

    Parameters

    • name: string

      saves scope name

    • saver: IObjectSaver

      object that implements Saver.IObjectSaver interface and can be loaded and saved via it's functions calls

    Returns number

    Saver identifier of your object instance.

registerScopeSaver

  • registerScopeSaver(name: string, saver: IScopeSaver): void
  • Registers object as scope saver.


    Parameters

    • name: string

      saves scope name

    • saver: IScopeSaver

      object that implements Saver.IScopeSaver interface and can be loaded and saved via it's functions calls

    Returns void

serialize

  • serialize(obj: any): object

serializeToString

  • serializeToString(obj: any): string

setObjectIgnored

  • setObjectIgnored(obj: object, ignore: boolean): void
  • Changes registered via Saver.registerObject instance behavior to object be skippable or not.


    Parameters

    • obj: object

      target object instance

    • ignore: boolean

      should be skipped on saving

    Returns void