mwg API
    Preparing search index...

    Class SaveSystem<T>

    Type Parameters

    • T
    Index
    • Reads a slot back out as a portable string a player can carry to another browser or device, or hand to their own server - the counterpart to importSlot, for mwg's own save shape rather than a foreign one (importExternal covers that side). scrambleKey, when given, runs the payload through scramble first: not encryption, only enough to stop a save being hand-edited in a text editor. Returns null for a slot with no save.

      Parameters

      • slot: string
      • OptionalscrambleKey: string

      Returns string | null

    • Adopts a save this SaveSystem never wrote: normalize runs once on externalBytes, producing state at version 0, which is then carried up through the same migrations chain an ordinary load already uses to reach the current version - a game supplies one normalize per external format it wants to accept (an rpg.decodeMarshal-based one for a Game.rxdata, say), rather than hand-rolling "decode, then call save" outside the versioned pipeline every migration otherwise goes through.

      externalBytes is size-checked before normalize ever sees it - a cheap, structural guard against a truncated or hostile file, ahead of and distinct from validating whatever shape normalize itself produces.

      Parameters

      • slot: string
      • externalBytes: Uint8Array
      • normalize: (bytes: Uint8Array) => unknown
      • Optionalpreview: unknown

      Returns void

    • Writes a payload from this SaveSystem's own exportSlot back as an ordinary save, migrated up to the current version the same way load migrates an older save found locally. scrambleKey must match whatever exportSlot scrambled it with, if any.

      payload is size- and control-character-checked before it is unscrambled or parsed - this crossed a device or a server, unlike load's own localStorage, which this same SaveSystem wrote itself and has no reason to distrust.

      Parameters

      • slot: string
      • payload: string
      • OptionalscrambleKey: string

      Returns void

    • every slot with a save, and its metadata - for a save-select screen

      Returns { meta: SaveMeta; slot: string }[]

    • Reads a slot, migrating it up to the current version if it was saved at an older one. Returns null for a corrupted or malformed slot the same way it already does for a missing one - a slot this SaveSystem wrote itself is trusted, but a truncated write (an interrupted browser storage flush, a quota eviction, a hand-edited value) is still possible, and a save-select screen should see "no usable save here", not an uncaught SyntaxError.

      Parameters

      • slot: string

      Returns SaveData<T> | null

    • Parameters

      • slot: string
      • state: T
      • Optionalpreview: unknown

      Returns void