summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-08-18 23:00:01 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-08-18 23:00:01 -0400
commitd918ceb224bd6ed8b428219ab28a436896a30b45 (patch)
treeb1856080c290be01e9eaa809f8f4b39fca69757b
parentf9eb16489fcf3f4c486df5f96a94edf16cf19a09 (diff)
downloadSMAPI-d918ceb224bd6ed8b428219ab28a436896a30b45.tar.gz
SMAPI-d918ceb224bd6ed8b428219ab28a436896a30b45.tar.bz2
SMAPI-d918ceb224bd6ed8b428219ab28a436896a30b45.zip
add IContentPack.WriteJsonFile method (#468)
-rw-r--r--docs/release-notes.md8
-rw-r--r--src/SMAPI/Framework/ContentPack.cs10
-rw-r--r--src/SMAPI/IContentPack.cs8
3 files changed, 23 insertions, 3 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 0b3259f5..fc6ea97f 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -1,6 +1,10 @@
# Release notes
## 2.8 (upcoming)
-* Updated compatibility list.
+* For players:
+ * Updated compatibility list.
+
+* For modders:
+ * Added `IContentPack.WriteJsonFile` method.
## 2.7
* For players:
@@ -14,6 +18,7 @@
* Fixed `player_add` command not recognising return scepter.
* Fixed `player_add` command showing fish twice.
* Fixed some SMAPI logs not deleted when starting a new session.
+ * Updated compatibility list.
* For modders:
* Added support for `.json` data files in the content API (including Content Patcher).
@@ -25,7 +30,6 @@
* All enums are now JSON-serialised by name instead of numeric value. (Previously only a few enums were serialised that way. JSON files which already have numeric enum values will still be parsed fine.)
* Fixed false compatibility error when constructing multidimensional arrays.
* Fixed `.ToSButton()` methods not being public.
- * Updated compatibility list.
* For SMAPI developers:
* Dropped support for pre-SMAPI-2.6 update checks in the web API.
diff --git a/src/SMAPI/Framework/ContentPack.cs b/src/SMAPI/Framework/ContentPack.cs
index 62d8b80d..ccb2b9a0 100644
--- a/src/SMAPI/Framework/ContentPack.cs
+++ b/src/SMAPI/Framework/ContentPack.cs
@@ -59,6 +59,16 @@ namespace StardewModdingAPI.Framework
: null;
}
+ /// <summary>Save data to a JSON file in the content pack's folder.</summary>
+ /// <typeparam name="TModel">The model type. This should be a plain class that has public properties for the data you want. The properties can be complex types.</typeparam>
+ /// <param name="path">The file path relative to the mod folder.</param>
+ /// <param name="data">The arbitrary data to save.</param>
+ public void WriteJsonFile<TModel>(string path, TModel data) where TModel : class
+ {
+ path = Path.Combine(this.DirectoryPath, PathUtilities.NormalisePathSeparators(path));
+ this.JsonHelper.WriteJsonFile(path, data);
+ }
+
/// <summary>Load content from the content pack folder (if not already cached), and return it. When loading a <c>.png</c> file, this must be called outside the game's draw loop.</summary>
/// <typeparam name="T">The expected data type. The main supported types are <see cref="Map"/>, <see cref="Texture2D"/>, and dictionaries; other types may be supported by the game's content pipeline.</typeparam>
/// <param name="key">The local path to a content file relative to the content pack folder.</param>
diff --git a/src/SMAPI/IContentPack.cs b/src/SMAPI/IContentPack.cs
index 15a2b7dd..fa793b13 100644
--- a/src/SMAPI/IContentPack.cs
+++ b/src/SMAPI/IContentPack.cs
@@ -22,11 +22,17 @@ namespace StardewModdingAPI
** Public methods
*********/
/// <summary>Read a JSON file from the content pack folder.</summary>
- /// <typeparam name="TModel">The model type.</typeparam>
+ /// <typeparam name="TModel">The model type. This should be a plain class that has public properties for the data you want. The properties can be complex types.</typeparam>
/// <param name="path">The file path relative to the content pack directory.</param>
/// <returns>Returns the deserialised model, or <c>null</c> if the file doesn't exist or is empty.</returns>
TModel ReadJsonFile<TModel>(string path) where TModel : class;
+ /// <summary>Save data to a JSON file in the content pack's folder.</summary>
+ /// <typeparam name="TModel">The model type. This should be a plain class that has public properties for the data you want. The properties can be complex types.</typeparam>
+ /// <param name="path">The file path relative to the mod folder.</param>
+ /// <param name="data">The arbitrary data to save.</param>
+ void WriteJsonFile<TModel>(string path, TModel data) where TModel : class;
+
/// <summary>Load content from the content pack folder (if not already cached), and return it. When loading a <c>.png</c> file, this must be called outside the game's draw loop.</summary>
/// <typeparam name="T">The expected data type. The main supported types are <see cref="Map"/>, <see cref="Texture2D"/>, and dictionaries; other types may be supported by the game's content pipeline.</typeparam>
/// <param name="key">The local path to a content file relative to the content pack folder.</param>