summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Framework/ModHelpers/DataHelper.cs155
-rw-r--r--src/SMAPI/Framework/ModHelpers/ModHelper.cs28
-rw-r--r--src/SMAPI/IDataHelper.cs61
-rw-r--r--src/SMAPI/IModHelper.cs11
-rw-r--r--src/SMAPI/Program.cs3
-rw-r--r--src/SMAPI/StardewModdingAPI.csproj2
-rw-r--r--src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs5
8 files changed, 244 insertions, 22 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 09d444a3..c7097f97 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -4,6 +4,7 @@
* Updated compatibility list.
* For modders:
+ * Added [data API](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Data).
* Added `IContentPack.WriteJsonFile` method.
* Fixed `IContentPack.ReadJsonFile` allowing non-relative paths.
diff --git a/src/SMAPI/Framework/ModHelpers/DataHelper.cs b/src/SMAPI/Framework/ModHelpers/DataHelper.cs
new file mode 100644
index 00000000..6ba099b4
--- /dev/null
+++ b/src/SMAPI/Framework/ModHelpers/DataHelper.cs
@@ -0,0 +1,155 @@
+using System;
+using System.IO;
+using Newtonsoft.Json;
+using StardewModdingAPI.Toolkit.Serialisation;
+using StardewModdingAPI.Toolkit.Utilities;
+using StardewValley;
+
+namespace StardewModdingAPI.Framework.ModHelpers
+{
+ /// <summary>Provides an API for reading and storing local mod data.</summary>
+ internal class DataHelper : BaseHelper, IDataHelper
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>Encapsulates SMAPI's JSON file parsing.</summary>
+ private readonly JsonHelper JsonHelper;
+
+ /// <summary>The absolute path to the mod folder.</summary>
+ private readonly string ModFolderPath;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="modID">The unique ID of the relevant mod.</param>
+ /// <param name="modFolderPath">The absolute path to the mod folder.</param>
+ /// <param name="jsonHelper">The absolute path to the mod folder.</param>
+ public DataHelper(string modID, string modFolderPath, JsonHelper jsonHelper)
+ : base(modID)
+ {
+ this.ModFolderPath = modFolderPath;
+ this.JsonHelper = jsonHelper;
+ }
+
+ /****
+ ** JSON file
+ ****/
+ /// <summary>Read data from a JSON file in the mod'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>
+ /// <returns>Returns the deserialised model, or <c>null</c> if the file doesn't exist or is empty.</returns>
+ /// <exception cref="InvalidOperationException">The <paramref name="path"/> is not relative or contains directory climbing (../).</exception>
+ public TModel ReadJsonFile<TModel>(string path) where TModel : class
+ {
+ if (!PathUtilities.IsSafeRelativePath(path))
+ throw new InvalidOperationException($"You must call {nameof(IModHelper.Data)}.{nameof(this.ReadJsonFile)} with a relative path.");
+
+ path = Path.Combine(this.ModFolderPath, PathUtilities.NormalisePathSeparators(path));
+ return this.JsonHelper.ReadJsonFileIfExists(path, out TModel data)
+ ? data
+ : null;
+ }
+
+ /// <summary>Save data to a JSON file in the mod'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>
+ /// <exception cref="InvalidOperationException">The <paramref name="path"/> is not relative or contains directory climbing (../).</exception>
+ public void WriteJsonFile<TModel>(string path, TModel data) where TModel : class
+ {
+ if (!PathUtilities.IsSafeRelativePath(path))
+ throw new InvalidOperationException($"You must call {nameof(IModHelper.Data)}.{nameof(this.WriteJsonFile)} with a relative path.");
+
+ path = Path.Combine(this.ModFolderPath, PathUtilities.NormalisePathSeparators(path));
+ this.JsonHelper.WriteJsonFile(path, data);
+ }
+
+ /****
+ ** Save file
+ ****/
+ /// <summary>Read arbitrary data stored in the current save slot. This is only possible if a save has been loaded.</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="key">The unique key identifying the data.</param>
+ /// <returns>Returns the parsed data, or <c>null</c> if the entry doesn't exist or is empty.</returns>
+ /// <exception cref="InvalidOperationException">The player hasn't loaded a save file yet.</exception>
+ public TModel ReadSaveData<TModel>(string key) where TModel : class
+ {
+ if (!Context.IsSaveLoaded)
+ throw new InvalidOperationException($"Can't invoke {nameof(this.ReadSaveData)} when a save file isn't loaded.");
+
+ return Game1.CustomData.TryGetValue(this.GetSaveFileKey(key), out string value)
+ ? this.JsonHelper.Deserialise<TModel>(value)
+ : null;
+ }
+
+ /// <summary>Save arbitrary data to the current save slot. This is only possible if a save has been loaded, and the data will be lost if the player exits without saving the current day.</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="key">The unique key identifying the data.</param>
+ /// <param name="data">The arbitrary data to save.</param>
+ /// <exception cref="InvalidOperationException">The player hasn't loaded a save file yet.</exception>
+ public void WriteSaveData<TModel>(string key, TModel data) where TModel : class
+ {
+ if (!Context.IsSaveLoaded)
+ throw new InvalidOperationException($"Can't invoke {nameof(this.WriteSaveData)} when a save file isn't loaded.");
+
+ Game1.CustomData[this.GetSaveFileKey(key)] = this.JsonHelper.Serialise(data, Formatting.None);
+ }
+
+ /****
+ ** Global app data
+ ****/
+ /// <summary>Read arbitrary data stored on the local computer, synchronised by GOG/Steam if applicable.</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="key">The unique key identifying the data.</param>
+ /// <returns>Returns the parsed data, or <c>null</c> if the entry doesn't exist or is empty.</returns>
+ public TModel ReadGlobalData<TModel>(string key) where TModel : class
+ {
+ string path = this.GetGlobalDataPath(key);
+ return this.JsonHelper.ReadJsonFileIfExists(path, out TModel data)
+ ? data
+ : null;
+ }
+
+ /// <summary>Save arbitrary data to the local computer, synchronised by GOG/Steam if applicable.</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="key">The unique key identifying the data.</param>
+ /// <param name="data">The arbitrary data to save.</param>
+ public void WriteGlobalData<TModel>(string key, TModel data) where TModel : class
+ {
+ string path = this.GetGlobalDataPath(key);
+ this.JsonHelper.WriteJsonFile(path, data);
+ }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Get the unique key for a save file data entry.</summary>
+ /// <param name="key">The unique key identifying the data.</param>
+ private string GetSaveFileKey(string key)
+ {
+ this.AssertSlug(key, nameof(key));
+ return $"smapi-mod-data/{this.ModID}/{key}".ToLower();
+ }
+
+ /// <summary>Get the absolute path for a global data file.</summary>
+ /// <param name="key">The unique key identifying the data.</param>
+ private string GetGlobalDataPath(string key)
+ {
+ this.AssertSlug(key, nameof(key));
+ return Path.Combine(Constants.SavesPath, ".smapi-mod-data", this.ModID.ToLower(), $"{key}.json".ToLower());
+ }
+
+ /// <summary>Assert that a key contains only characters that are safe in all contexts.</summary>
+ /// <param name="key">The key to check.</param>
+ /// <param name="paramName">The argument name for any assertion error.</param>
+ private void AssertSlug(string key, string paramName)
+ {
+ if (!PathUtilities.IsSlug(key))
+ throw new ArgumentException("The data key is invalid (keys must only contain letters, numbers, underscores, periods, or hyphens).", paramName);
+ }
+ }
+}
diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs
index 0ba258b4..0ed3df12 100644
--- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs
+++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs
@@ -4,9 +4,7 @@ using System.IO;
using System.Linq;
using StardewModdingAPI.Events;
using StardewModdingAPI.Framework.Input;
-using StardewModdingAPI.Toolkit.Serialisation;
using StardewModdingAPI.Toolkit.Serialisation.Models;
-using StardewModdingAPI.Toolkit.Utilities;
namespace StardewModdingAPI.Framework.ModHelpers
{
@@ -16,9 +14,6 @@ namespace StardewModdingAPI.Framework.ModHelpers
/*********
** Properties
*********/
- /// <summary>Encapsulates SMAPI's JSON file parsing.</summary>
- private readonly JsonHelper JsonHelper;
-
/// <summary>The content packs loaded for this mod.</summary>
private readonly IContentPack[] ContentPacks;
@@ -41,6 +36,9 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <summary>An API for loading content assets.</summary>
public IContentHelper Content { get; }
+ /// <summary>An API for reading and writing persistent mod data.</summary>
+ public IDataHelper Data { get; }
+
/// <summary>An API for checking and changing input state.</summary>
public IInputHelper Input { get; }
@@ -66,11 +64,11 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <summary>Construct an instance.</summary>
/// <param name="modID">The mod's unique ID.</param>
/// <param name="modDirectory">The full path to the mod's folder.</param>
- /// <param name="jsonHelper">Encapsulate SMAPI's JSON parsing.</param>
/// <param name="inputState">Manages the game's input state.</param>
/// <param name="events">Manages access to events raised by SMAPI.</param>
/// <param name="contentHelper">An API for loading content assets.</param>
/// <param name="commandHelper">An API for managing console commands.</param>
+ /// <param name="dataHelper">An API for reading and writing persistent mod data.</param>
/// <param name="modRegistry">an API for fetching metadata about loaded mods.</param>
/// <param name="reflectionHelper">An API for accessing private game code.</param>
/// <param name="multiplayer">Provides multiplayer utilities.</param>
@@ -80,7 +78,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <param name="deprecationManager">Manages deprecation warnings.</param>
/// <exception cref="ArgumentNullException">An argument is null or empty.</exception>
/// <exception cref="InvalidOperationException">The <paramref name="modDirectory"/> path does not exist on disk.</exception>
- public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, ICommandHelper commandHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper, IEnumerable<IContentPack> contentPacks, Func<string, IManifest, IContentPack> createContentPack, DeprecationManager deprecationManager)
+ public ModHelper(string modID, string modDirectory, SInputState inputState, IModEvents events, IContentHelper contentHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper, IEnumerable<IContentPack> contentPacks, Func<string, IManifest, IContentPack> createContentPack, DeprecationManager deprecationManager)
: base(modID)
{
// validate directory
@@ -91,8 +89,8 @@ namespace StardewModdingAPI.Framework.ModHelpers
// initialise
this.DirectoryPath = modDirectory;
- this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper));
this.Content = contentHelper ?? throw new ArgumentNullException(nameof(contentHelper));
+ this.Data = dataHelper ?? throw new ArgumentNullException(nameof(dataHelper));
this.Input = new InputHelper(modID, inputState);
this.ModRegistry = modRegistry ?? throw new ArgumentNullException(nameof(modRegistry));
this.ConsoleCommands = commandHelper ?? throw new ArgumentNullException(nameof(commandHelper));
@@ -113,7 +111,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
public TConfig ReadConfig<TConfig>()
where TConfig : class, new()
{
- TConfig config = this.ReadJsonFile<TConfig>("config.json") ?? new TConfig();
+ TConfig config = this.Data.ReadJsonFile<TConfig>("config.json") ?? new TConfig();
this.WriteConfig(config); // create file or fill in missing fields
return config;
}
@@ -124,7 +122,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
public void WriteConfig<TConfig>(TConfig config)
where TConfig : class, new()
{
- this.WriteJsonFile("config.json", config);
+ this.Data.WriteJsonFile("config.json", config);
}
/****
@@ -134,24 +132,22 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <typeparam name="TModel">The model type.</typeparam>
/// <param name="path">The file path relative to the mod directory.</param>
/// <returns>Returns the deserialised model, or <c>null</c> if the file doesn't exist or is empty.</returns>
+ [Obsolete("Use " + nameof(ModHelper.Data) + "." + nameof(IDataHelper.ReadJsonFile) + " instead")]
public TModel ReadJsonFile<TModel>(string path)
where TModel : class
{
- path = Path.Combine(this.DirectoryPath, PathUtilities.NormalisePathSeparators(path));
- return this.JsonHelper.ReadJsonFileIfExists(path, out TModel data)
- ? data
- : null;
+ return this.Data.ReadJsonFile<TModel>(path);
}
/// <summary>Save to a JSON file.</summary>
/// <typeparam name="TModel">The model type.</typeparam>
/// <param name="path">The file path relative to the mod directory.</param>
/// <param name="model">The model to save.</param>
+ [Obsolete("Use " + nameof(ModHelper.Data) + "." + nameof(IDataHelper.WriteJsonFile) + " instead")]
public void WriteJsonFile<TModel>(string path, TModel model)
where TModel : class
{
- path = Path.Combine(this.DirectoryPath, PathUtilities.NormalisePathSeparators(path));
- this.JsonHelper.WriteJsonFile(path, model);
+ this.Data.WriteJsonFile(path, model);
}
/****
diff --git a/src/SMAPI/IDataHelper.cs b/src/SMAPI/IDataHelper.cs
new file mode 100644
index 00000000..722d5062
--- /dev/null
+++ b/src/SMAPI/IDataHelper.cs
@@ -0,0 +1,61 @@
+using System;
+
+namespace StardewModdingAPI
+{
+ /// <summary>Provides an API for reading and storing local mod data.</summary>
+ public interface IDataHelper
+ {
+ /*********
+ ** Public methods
+ *********/
+ /****
+ ** JSON file
+ ****/
+ /// <summary>Read data from a JSON file in the mod'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>
+ /// <returns>Returns the deserialised model, or <c>null</c> if the file doesn't exist or is empty.</returns>
+ /// <exception cref="InvalidOperationException">The <paramref name="path"/> is not relative or contains directory climbing (../).</exception>
+ TModel ReadJsonFile<TModel>(string path) where TModel : class;
+
+ /// <summary>Save data to a JSON file in the mod'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>
+ /// <exception cref="InvalidOperationException">The <paramref name="path"/> is not relative or contains directory climbing (../).</exception>
+ void WriteJsonFile<TModel>(string path, TModel data) where TModel : class;
+
+ /****
+ ** Save file
+ ****/
+ /// <summary>Read arbitrary data stored in the current save slot. This is only possible if a save has been loaded.</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="key">The unique key identifying the data.</param>
+ /// <returns>Returns the parsed data, or <c>null</c> if the entry doesn't exist or is empty.</returns>
+ /// <exception cref="InvalidOperationException">The player hasn't loaded a save file yet.</exception>
+ TModel ReadSaveData<TModel>(string key) where TModel : class;
+
+ /// <summary>Save arbitrary data to the current save slot. This is only possible if a save has been loaded, and the data will be lost if the player exits without saving the current day.</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="key">The unique key identifying the data.</param>
+ /// <param name="data">The arbitrary data to save.</param>
+ /// <exception cref="InvalidOperationException">The player hasn't loaded a save file yet.</exception>
+ void WriteSaveData<TModel>(string key, TModel data) where TModel : class;
+
+
+ /****
+ ** Global app data
+ ****/
+ /// <summary>Read arbitrary data stored on the local computer, synchronised by GOG/Steam if applicable.</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="key">The unique key identifying the data.</param>
+ /// <returns>Returns the parsed data, or <c>null</c> if the entry doesn't exist or is empty.</returns>
+ TModel ReadGlobalData<TModel>(string key) where TModel : class;
+
+ /// <summary>Save arbitrary data to the local computer, synchronised by GOG/Steam if applicable.</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="key">The unique key identifying the data.</param>
+ /// <param name="data">The arbitrary data to save.</param>
+ void WriteGlobalData<TModel>(string key, TModel data) where TModel : class;
+ }
+}
diff --git a/src/SMAPI/IModHelper.cs b/src/SMAPI/IModHelper.cs
index d7b8c986..e4b5d390 100644
--- a/src/SMAPI/IModHelper.cs
+++ b/src/SMAPI/IModHelper.cs
@@ -17,9 +17,15 @@ namespace StardewModdingAPI
[Obsolete("This is an experimental interface which may change at any time. Don't depend on this for released mods.")]
IModEvents Events { get; }
+ /// <summary>An API for managing console commands.</summary>
+ ICommandHelper ConsoleCommands { get; }
+
/// <summary>An API for loading content assets.</summary>
IContentHelper Content { get; }
+ /// <summary>An API for reading and writing persistent mod data.</summary>
+ IDataHelper Data { get; }
+
/// <summary>An API for checking and changing input state.</summary>
IInputHelper Input { get; }
@@ -32,9 +38,6 @@ namespace StardewModdingAPI
/// <summary>Provides multiplayer utilities.</summary>
IMultiplayerHelper Multiplayer { get; }
- /// <summary>An API for managing console commands.</summary>
- ICommandHelper ConsoleCommands { get; }
-
/// <summary>Provides translations stored in the mod's <c>i18n</c> folder, with one file per locale (like <c>en.json</c>) containing a flat key => value structure. Translations are fetched with locale fallback, so missing translations are filled in from broader locales (like <c>pt-BR.json</c> &lt; <c>pt.json</c> &lt; <c>default.json</c>).</summary>
ITranslationHelper Translation { get; }
@@ -61,12 +64,14 @@ namespace StardewModdingAPI
/// <typeparam name="TModel">The model type.</typeparam>
/// <param name="path">The file path relative to the mod directory.</param>
/// <returns>Returns the deserialised model, or <c>null</c> if the file doesn't exist or is empty.</returns>
+ [Obsolete("Use " + nameof(IModHelper.Data) + "." + nameof(IDataHelper.ReadJsonFile) + " instead")]
TModel ReadJsonFile<TModel>(string path) where TModel : class;
/// <summary>Save to a JSON file.</summary>
/// <typeparam name="TModel">The model type.</typeparam>
/// <param name="path">The file path relative to the mod directory.</param>
/// <param name="model">The model to save.</param>
+ [Obsolete("Use " + nameof(IModHelper.Data) + "." + nameof(IDataHelper.WriteJsonFile) + " instead")]
void WriteJsonFile<TModel>(string path, TModel model) where TModel : class;
/****
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index 634c5066..c40d2ff6 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -865,6 +865,7 @@ namespace StardewModdingAPI
IModEvents events = new ModEvents(metadata, this.EventManager);
ICommandHelper commandHelper = new CommandHelper(manifest.UniqueID, metadata.DisplayName, this.GameInstance.CommandManager);
IContentHelper contentHelper = new ContentHelper(contentCore, metadata.DirectoryPath, manifest.UniqueID, metadata.DisplayName, monitor);
+ IDataHelper dataHelper = new DataHelper(manifest.UniqueID, metadata.DirectoryPath, jsonHelper);
IReflectionHelper reflectionHelper = new ReflectionHelper(manifest.UniqueID, metadata.DisplayName, this.Reflection, this.DeprecationManager);
IModRegistry modRegistryHelper = new ModRegistryHelper(manifest.UniqueID, this.ModRegistry, proxyFactory, monitor);
IMultiplayerHelper multiplayerHelper = new MultiplayerHelper(manifest.UniqueID, this.GameInstance.Multiplayer);
@@ -877,7 +878,7 @@ namespace StardewModdingAPI
return new ContentPack(packDirPath, packManifest, packContentHelper, this.Toolkit.JsonHelper);
}
- modHelper = new ModHelper(manifest.UniqueID, metadata.DirectoryPath, jsonHelper, this.GameInstance.Input, events, contentHelper, commandHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper, contentPacks, CreateTransitionalContentPack, this.DeprecationManager);
+ modHelper = new ModHelper(manifest.UniqueID, metadata.DirectoryPath, this.GameInstance.Input, events, contentHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper, contentPacks, CreateTransitionalContentPack, this.DeprecationManager);
}
// init mod
diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj
index fc2d45ba..713b1b31 100644
--- a/src/SMAPI/StardewModdingAPI.csproj
+++ b/src/SMAPI/StardewModdingAPI.csproj
@@ -109,6 +109,7 @@
<Compile Include="Events\WorldBuildingListChangedEventArgs.cs" />
<Compile Include="Events\WorldLocationListChangedEventArgs.cs" />
<Compile Include="Events\WorldObjectListChangedEventArgs.cs" />
+ <Compile Include="Framework\ModHelpers\DataHelper.cs" />
<Compile Include="Framework\SGameConstructorHack.cs" />
<Compile Include="Framework\ContentManagers\BaseContentManager.cs" />
<Compile Include="Framework\ContentManagers\GameContentManager.cs" />
@@ -136,6 +137,7 @@
<Compile Include="Framework\ModHelpers\InputHelper.cs" />
<Compile Include="Framework\StateTracking\Comparers\GenericEqualsComparer.cs" />
<Compile Include="Framework\WatcherCore.cs" />
+ <Compile Include="IDataHelper.cs" />
<Compile Include="IInputHelper.cs" />
<Compile Include="Framework\Input\SInputState.cs" />
<Compile Include="Framework\Input\InputStatus.cs" />
diff --git a/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs b/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs
index dcc0dac4..cf2ce0d1 100644
--- a/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs
+++ b/src/StardewModdingAPI.Toolkit/Serialisation/JsonHelper.cs
@@ -127,9 +127,10 @@ namespace StardewModdingAPI.Toolkit.Serialisation
/// <summary>Serialize a model to JSON text.</summary>
/// <typeparam name="TModel">The model type.</typeparam>
/// <param name="model">The model to serialise.</param>
- public string Serialise<TModel>(TModel model)
+ /// <param name="formatting">The formatting to apply.</param>
+ public string Serialise<TModel>(TModel model, Formatting formatting = Formatting.Indented)
{
- return JsonConvert.SerializeObject(model, this.JsonSettings);
+ return JsonConvert.SerializeObject(model, formatting, this.JsonSettings);
}
}
}