Changes

Jump to navigation Jump to search
→‎Per-save JSON files: update per convention
Line 344: Line 344:     
====Per-save JSON files====
 
====Per-save JSON files====
You can also specify a directory path (relative to your mod directory) instead of just the file name. The directories will be created automatically if needed. For example, here's how you'd use per-save config files:
+
You can create per-save files by using the save ID in the name. If you specify a folder path (relative to your mod folder), SMAPI will create the folders automatically if needed.
 +
 
 +
For example, here's a typical per-save data file:
    
<source lang="c#">
 
<source lang="c#">
 
// read file
 
// read file
var model = this.Helper.ReadJsonFile<ModData>($"{Constants.SaveFolderName}/config.json") ?? new ModData();
+
var model = this.Helper.ReadJsonFile<ModData>($"data/{Constants.SaveFolderName}.json") ?? new ModData();
    
// write file (if needed)
 
// write file (if needed)
this.Helper.WriteJsonFile($"{Constants.SaveFolderName}/config.json", model);
+
this.Helper.WriteJsonFile($"data/{Constants.SaveFolderName}.json", model);
 
</source>
 
</source>
  
translators
8,445

edits

Navigation menu