Class JsonFileSaveStore

Namespace
TDMaker.Unity.Campaign
Assembly
TDMaker.Unity.dll

Default store: one JSON file per slot under UnityEngine.Application.persistentDataPath (folder TDMakerSaves, files slot1.json, slot2.json, ...). Writes go to a temporary file that then replaces the slot file, so a crash mid-write leaves the previous save intact. An unreadable file is renamed to slotN.json.bak (or .bak2, ...) and kept. Not for WebGL (use PlayerPrefsSaveStore, or CreateDefault(int, string)).

public sealed class JsonFileSaveStore : TextSaveStore, ISaveStore
Inheritance
JsonFileSaveStore
Implements
Inherited Members

Constructors

JsonFileSaveStore(string, int, string)

Creates a store. folder null uses persistentDataPath/TDMakerSaves.

public JsonFileSaveStore(string folder = null, int slots = 3, string filePrefix = "slot")

Parameters

folder string
slots int
filePrefix string

Fields

DefaultFolderName

Default folder name under UnityEngine.Application.persistentDataPath.

public const string DefaultFolderName = "TDMakerSaves"

Field Value

string

Properties

FilePrefix

File name stem (files are stem + slot number + .json).

public string FilePrefix { get; }

Property Value

string

Folder

Folder of the slot files.

public string Folder { get; }

Property Value

string

Methods

Backup(int, string)

Moves unreadable slot content out of the way, keeping it. Returns where it went (for the warning).

protected override string Backup(int slot, string text)

Parameters

slot int
text string

Returns

string

DeleteText(int)

Removes a slot.

protected override void DeleteText(int slot)

Parameters

slot int

GetBackups(int)

Backup files of slot kept after unreadable loads (oldest first).

public List<string> GetBackups(int slot)

Parameters

slot int

Returns

List<string>

HasText(int)

Whether a slot holds text.

protected override bool HasText(int slot)

Parameters

slot int

Returns

bool

PathOf(int)

Path of the file of slot.

public string PathOf(int slot)

Parameters

slot int

Returns

string

ReadText(int)

Reads the raw text of a slot, or null when it is empty.

protected override string ReadText(int slot)

Parameters

slot int

Returns

string

WriteText(int, string)

Writes the raw text of a slot.

protected override void WriteText(int slot, string text)

Parameters

slot int
text string