summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModHelpers
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-08-26 19:08:38 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-08-26 19:08:38 -0400
commit73c389df74a8df796b3c1cacf2c035ac7e34a063 (patch)
treeb13a3da7f4c07d3cd01569e6c82ffb9e936140db /src/SMAPI/Framework/ModHelpers
parentda29f3f08f2192cdce2d3a9ed3c55680421e0caf (diff)
downloadSMAPI-73c389df74a8df796b3c1cacf2c035ac7e34a063.tar.gz
SMAPI-73c389df74a8df796b3c1cacf2c035ac7e34a063.tar.bz2
SMAPI-73c389df74a8df796b3c1cacf2c035ac7e34a063.zip
delete data API entries when they're set to null (#468)
Diffstat (limited to 'src/SMAPI/Framework/ModHelpers')
-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);
}