summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/SMAPI/Framework/ModHelpers/DataHelper.cs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/SMAPI/Framework/ModHelpers/DataHelper.cs b/src/SMAPI/Framework/ModHelpers/DataHelper.cs
index 506c9c54..e5100aed 100644
--- a/src/SMAPI/Framework/ModHelpers/DataHelper.cs
+++ b/src/SMAPI/Framework/ModHelpers/DataHelper.cs
@@ -99,7 +99,11 @@ namespace StardewModdingAPI.Framework.ModHelpers
if (!Context.IsMainPlayer)
throw new InvalidOperationException($"Can't use {nameof(IMod.Helper)}.{nameof(IModHelper.Data)}.{nameof(this.ReadSaveData)} because this isn't the main player. (Save files are stored on the main player's computer.)");
- Game1.CustomData[this.GetSaveFileKey(key)] = this.JsonHelper.Serialise(data, Formatting.None);
+ string internalKey = this.GetSaveFileKey(key);
+ if (data != null)
+ Game1.CustomData[internalKey] = this.JsonHelper.Serialise(data, Formatting.None);
+ else
+ Game1.CustomData.Remove(internalKey);
}
/****
@@ -124,7 +128,10 @@ namespace StardewModdingAPI.Framework.ModHelpers
public void WriteGlobalData<TModel>(string key, TModel data) where TModel : class
{
string path = this.GetGlobalDataPath(key);
- this.JsonHelper.WriteJsonFile(path, data);
+ if (data != null)
+ this.JsonHelper.WriteJsonFile(path, data);
+ else
+ File.Delete(path);
}