SMAPI - Stardew Modding API

SMAPI - Stardew Modding API

971k Downloads

Add data storage API

Pathoschild opened this issue ยท 5 comments

commented

Add an API to read/write per-save data in the save file.

Requires Stardew Valley 1.3 (#453).

commented

I suppose this supercedes #293 ?

commented

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.

commented

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.

commented

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": "..."
}
commented

Done in develop for the upcoming SMAPI 2.8.