diff options
-rw-r--r-- | src/StardewModdingAPI/Advanced/ConfigFile.cs | 37 | ||||
-rw-r--r-- | src/StardewModdingAPI/Advanced/IConfigFile.cs | 28 | ||||
-rw-r--r-- | src/StardewModdingAPI/Constants.cs | 2 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/ModHelper.cs | 15 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs | 14 | ||||
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 3 | ||||
-rw-r--r-- | src/StardewModdingAPI/StardewModdingAPI.csproj | 2 |
7 files changed, 6 insertions, 95 deletions
diff --git a/src/StardewModdingAPI/Advanced/ConfigFile.cs b/src/StardewModdingAPI/Advanced/ConfigFile.cs deleted file mode 100644 index 78cad26a..00000000 --- a/src/StardewModdingAPI/Advanced/ConfigFile.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.IO; -using Newtonsoft.Json; - -namespace StardewModdingAPI.Advanced -{ - /// <summary>Wraps a configuration file with IO methods for convenience.</summary> - [Obsolete] - public abstract class ConfigFile : IConfigFile - { - /********* - ** Accessors - *********/ - /// <summary>Provides simplified APIs for writing mods.</summary> - public IModHelper ModHelper { get; set; } - - /// <summary>The file path from which the model was loaded, relative to the mod directory.</summary> - public string FilePath { get; set; } - - - /********* - ** Public methods - *********/ - /// <summary>Reparse the underlying file and update this model.</summary> - public void Reload() - { - string json = File.ReadAllText(Path.Combine(this.ModHelper.DirectoryPath, this.FilePath)); - JsonConvert.PopulateObject(json, this); - } - - /// <summary>Save this model to the underlying file.</summary> - public void Save() - { - this.ModHelper.WriteJsonFile(this.FilePath, this); - } - } -}
\ No newline at end of file diff --git a/src/StardewModdingAPI/Advanced/IConfigFile.cs b/src/StardewModdingAPI/Advanced/IConfigFile.cs deleted file mode 100644 index 1b424ace..00000000 --- a/src/StardewModdingAPI/Advanced/IConfigFile.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace StardewModdingAPI.Advanced -{ - /// <summary>Wraps a configuration file with IO methods for convenience.</summary> - [Obsolete] - public interface IConfigFile - { - /********* - ** Accessors - *********/ - /// <summary>Provides simplified APIs for writing mods.</summary> - IModHelper ModHelper { get; set; } - - /// <summary>The file path from which the model was loaded, relative to the mod directory.</summary> - string FilePath { get; set; } - - - /********* - ** Methods - *********/ - /// <summary>Reparse the underlying file and update this model.</summary> - void Reload(); - - /// <summary>Save this model to the underlying file.</summary> - void Save(); - } -} diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs index 8949bc55..ae2fbe87 100644 --- a/src/StardewModdingAPI/Constants.cs +++ b/src/StardewModdingAPI/Constants.cs @@ -147,6 +147,8 @@ namespace StardewModdingAPI new GenericFieldFinder("StardewValley.Item", "set_Name", isStatic: false), // APIs removed in SMAPI 1.9 + new GenericTypeFinder("StardewModdingAPI.Advanced.ConfigFile"), + new GenericTypeFinder("StardewModdingAPI.Advanced.IConfigFile"), new GenericTypeFinder("StardewModdingAPI.Entities.SPlayer"), new GenericTypeFinder("StardewModdingAPI.Extensions"), new GenericTypeFinder("StardewModdingAPI.Inheritance.ItemStackChange"), diff --git a/src/StardewModdingAPI/Framework/ModHelper.cs b/src/StardewModdingAPI/Framework/ModHelper.cs index 0d50201b..c8c44dba 100644 --- a/src/StardewModdingAPI/Framework/ModHelper.cs +++ b/src/StardewModdingAPI/Framework/ModHelper.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using StardewModdingAPI.Advanced; using StardewModdingAPI.Framework.Reflection; using StardewModdingAPI.Framework.Serialisation; @@ -15,9 +14,6 @@ namespace StardewModdingAPI.Framework /// <summary>Encapsulates SMAPI's JSON file parsing.</summary> private readonly JsonHelper JsonHelper; - /// <summary>Manages deprecation warnings.</summary> - private static DeprecationManager DeprecationManager; - /********* ** Accessors @@ -65,13 +61,6 @@ namespace StardewModdingAPI.Framework this.ConsoleCommands = new CommandHelper(modName, commandManager); } - /// <summary>Injects types required for backwards compatibility.</summary> - /// <param name="deprecationManager">Manages deprecation warnings.</param> - internal static void Shim(DeprecationManager deprecationManager) - { - ModHelper.DeprecationManager = deprecationManager; - } - /**** ** Mod config file ****/ @@ -81,8 +70,6 @@ namespace StardewModdingAPI.Framework where TConfig : class, new() { TConfig config = this.ReadJsonFile<TConfig>("config.json") ?? new TConfig(); - if (config is IConfigFile) - ModHelper.DeprecationManager.Warn($"{nameof(IConfigFile)}", "1.9", DeprecationLevel.Info); this.WriteConfig(config); // create file or fill in missing fields return config; } @@ -107,7 +94,7 @@ namespace StardewModdingAPI.Framework where TModel : class { path = Path.Combine(this.DirectoryPath, path); - return this.JsonHelper.ReadJsonFile<TModel>(path, this); + return this.JsonHelper.ReadJsonFile<TModel>(path); } /// <summary>Save to a JSON file.</summary> diff --git a/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs b/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs index d5f5bfd0..bd15c7bb 100644 --- a/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs +++ b/src/StardewModdingAPI/Framework/Serialisation/JsonHelper.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using Microsoft.Xna.Framework.Input; using Newtonsoft.Json; -using StardewModdingAPI.Advanced; namespace StardewModdingAPI.Framework.Serialisation { @@ -31,9 +30,8 @@ namespace StardewModdingAPI.Framework.Serialisation /// <summary>Read a JSON file.</summary> /// <typeparam name="TModel">The model type.</typeparam> /// <param name="fullPath">The absolete file path.</param> - /// <param name="modHelper">The mod helper to inject for <see cref="IConfigFile"/> instances.</param> /// <returns>Returns the deserialised model, or <c>null</c> if the file doesn't exist or is empty.</returns> - public TModel ReadJsonFile<TModel>(string fullPath, IModHelper modHelper) + public TModel ReadJsonFile<TModel>(string fullPath) where TModel : class { // read file @@ -48,15 +46,7 @@ namespace StardewModdingAPI.Framework.Serialisation } // deserialise model - TModel model = JsonConvert.DeserializeObject<TModel>(json, this.JsonSettings); - if (model is IConfigFile) - { - var wrapper = (IConfigFile)model; - wrapper.ModHelper = modHelper; - wrapper.FilePath = fullPath; - } - - return model; + return JsonConvert.DeserializeObject<TModel>(json, this.JsonSettings); } /// <summary>Save to a JSON file.</summary> diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index f0cc00c7..db7a3df6 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -97,7 +97,6 @@ namespace StardewModdingAPI InternalExtensions.Shim(this.ModRegistry); Log.Shim(this.DeprecationManager, this.GetSecondaryMonitor("legacy mod"), this.ModRegistry); Mod.Shim(this.DeprecationManager); - ModHelper.Shim(this.DeprecationManager); ContentEvents.Shim(this.ModRegistry, this.Monitor); PlayerEvents.Shim(this.DeprecationManager); TimeEvents.Shim(this.DeprecationManager); @@ -344,7 +343,7 @@ namespace StardewModdingAPI } // deserialise manifest - manifest = jsonHelper.ReadJsonFile<Manifest>(Path.Combine(directory.FullName, "manifest.json"), null); + manifest = jsonHelper.ReadJsonFile<Manifest>(Path.Combine(directory.FullName, "manifest.json")); if (manifest == null) { this.Monitor.Log($"{skippedPrefix} because its manifest is invalid.", LogLevel.Error); diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 92726ca0..dceae74e 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -115,8 +115,6 @@ <Compile Include="..\GlobalAssemblyInfo.cs"> <Link>Properties\GlobalAssemblyInfo.cs</Link> </Compile> - <Compile Include="Advanced\ConfigFile.cs" /> - <Compile Include="Advanced\IConfigFile.cs" /> <Compile Include="Command.cs" /> <Compile Include="Events\ContentEvents.cs" /> <Compile Include="Events\EventArgsValueChanged.cs" /> |