Add data storage API
Pathoschild opened this issue ยท 5 comments
Add an API to read/write per-save data in the save file.
Requires Stardew Valley 1.3 (#453).
I suppose this supercedes #293 ?
Yep, most likely #293 won't be implemented since this provides a cleaner way to store per-save data. I'll keep that open for now though, since this is still unplanned.
Actually, if visually it works like #293 but internally the "json file" is stored in a string, it wont actually need any external differences, for mod authors it would be easier if there is 1 standard in how to read/write the stuff after all.
I haven't planned out the API yet, but my idea is to use the same overall API (but you specify a key instead of a filename):
// write
helper.Data.Write("data", data, perSave: true);
// read
var data = helper.Data.Read<DataModel>("data", perSave: true);
// iterate
foreach(string key in helper.Data.GetKeys(perSave: true))
...;
SMAPI would store the data in-memory and serialise on save. Per-save data would be stuffed into the save file, and global data would be stored in a global file in the saves folder. The serialised data would probably look something like this:
// StardewValley/Saves/SMAPI.mod-data.json
{
"mods[<mod id>].data": "..."
}
// in save file
{
"SMAPI.mods[<mod id>].data": "..."
}