summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Advanced/ConfigFile.cs2
-rw-r--r--src/StardewModdingAPI/Advanced/IConfigFile.cs2
-rw-r--r--src/StardewModdingAPI/Framework/DeprecationManager.cs5
-rw-r--r--src/StardewModdingAPI/IModHelper.cs43
-rw-r--r--src/StardewModdingAPI/Mod.cs15
-rw-r--r--src/StardewModdingAPI/ModHelper.cs3
-rw-r--r--src/StardewModdingAPI/Program.cs9
-rw-r--r--src/StardewModdingAPI/StardewModdingAPI.csproj1
8 files changed, 67 insertions, 13 deletions
diff --git a/src/StardewModdingAPI/Advanced/ConfigFile.cs b/src/StardewModdingAPI/Advanced/ConfigFile.cs
index 000eaf4c..1aba2f2c 100644
--- a/src/StardewModdingAPI/Advanced/ConfigFile.cs
+++ b/src/StardewModdingAPI/Advanced/ConfigFile.cs
@@ -10,7 +10,7 @@ namespace StardewModdingAPI.Advanced
** Accessors
*********/
/// <summary>Provides methods for interacting with the mod directory, including read/writing the config file.</summary>
- public ModHelper ModHelper { get; set; }
+ 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; }
diff --git a/src/StardewModdingAPI/Advanced/IConfigFile.cs b/src/StardewModdingAPI/Advanced/IConfigFile.cs
index 78fd44a6..841f4c58 100644
--- a/src/StardewModdingAPI/Advanced/IConfigFile.cs
+++ b/src/StardewModdingAPI/Advanced/IConfigFile.cs
@@ -7,7 +7,7 @@
** Accessors
*********/
/// <summary>Provides methods for interacting with the mod directory, including read/writing the config file.</summary>
- ModHelper ModHelper { get; set; }
+ IModHelper ModHelper { get; set; }
/// <summary>The file path from which the model was loaded, relative to the mod directory.</summary>
string FilePath { get; set; }
diff --git a/src/StardewModdingAPI/Framework/DeprecationManager.cs b/src/StardewModdingAPI/Framework/DeprecationManager.cs
index 4de92bca..044c2a40 100644
--- a/src/StardewModdingAPI/Framework/DeprecationManager.cs
+++ b/src/StardewModdingAPI/Framework/DeprecationManager.cs
@@ -112,9 +112,10 @@ namespace StardewModdingAPI.Framework
/// <param name="subtype">The type to check.</param>
/// <param name="baseType">The base type which declares the virtual method.</param>
/// <param name="name">The method name.</param>
- public bool IsVirtualMethodImplemented(Type subtype, Type baseType, string name)
+ /// <param name="argumentTypes">The expected argument types.</param>
+ internal bool IsVirtualMethodImplemented(Type subtype, Type baseType, string name, Type[] argumentTypes)
{
- MethodInfo method = subtype.GetMethod(nameof(Mod.Entry), new[] { typeof(object[]) });
+ MethodInfo method = subtype.GetMethod(nameof(Mod.Entry), argumentTypes);
return method.DeclaringType != baseType;
}
}
diff --git a/src/StardewModdingAPI/IModHelper.cs b/src/StardewModdingAPI/IModHelper.cs
new file mode 100644
index 00000000..1af7df6b
--- /dev/null
+++ b/src/StardewModdingAPI/IModHelper.cs
@@ -0,0 +1,43 @@
+namespace StardewModdingAPI
+{
+ /// <summary>Provides methods for interacting with a mod directory.</summary>
+ public interface IModHelper
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The mod directory path.</summary>
+ string DirectoryPath { get; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /****
+ ** Mod config file
+ ****/
+ /// <summary>Read the mod's configuration file (and create it if needed).</summary>
+ /// <typeparam name="TConfig">The config class type. This should be a plain class that has public properties for the settings you want. These can be complex types.</typeparam>
+ TConfig ReadConfig<TConfig>() where TConfig : class, new();
+
+ /// <summary>Save to the mod's configuration file.</summary>
+ /// <typeparam name="TConfig">The config class type.</typeparam>
+ /// <param name="config">The config settings to save.</param>
+ void WriteConfig<TConfig>(TConfig config) where TConfig : class, new();
+
+ /****
+ ** Generic JSON files
+ ****/
+ /// <summary>Read a JSON file.</summary>
+ /// <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>
+ 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>
+ void WriteJsonFile<TModel>(string path, TModel model) where TModel : class;
+ }
+} \ No newline at end of file
diff --git a/src/StardewModdingAPI/Mod.cs b/src/StardewModdingAPI/Mod.cs
index e3011a19..c2a755b0 100644
--- a/src/StardewModdingAPI/Mod.cs
+++ b/src/StardewModdingAPI/Mod.cs
@@ -17,7 +17,7 @@ namespace StardewModdingAPI
** Accessors
*********/
/// <summary>Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</summary>
- public ModHelper Helper { get; internal set; }
+ public IModHelper Helper { get; internal set; }
/// <summary>Writes messages to the console and log file.</summary>
public IMonitor Monitor { get; internal set; }
@@ -26,7 +26,7 @@ namespace StardewModdingAPI
public Manifest Manifest { get; internal set; }
/// <summary>The full path to the mod's directory on the disk.</summary>
- [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(ModHelper.DirectoryPath) + " instead")]
+ [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.DirectoryPath) + " instead")]
public string PathOnDisk
{
get
@@ -38,7 +38,7 @@ namespace StardewModdingAPI
}
/// <summary>The full path to the mod's <c>config.json</c> file on the disk.</summary>
- [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(ModHelper.ReadConfig) + " instead")]
+ [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.ReadConfig) + " instead")]
public string BaseConfigPath
{
get
@@ -50,11 +50,11 @@ namespace StardewModdingAPI
}
/// <summary>The full path to the per-save configs folder (if <see cref="StardewModdingAPI.Manifest.PerSaveConfigs"/> is <c>true</c>).</summary>
- [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(ModHelper.ReadJsonFile) + " instead")]
+ [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.ReadJsonFile) + " instead")]
public string PerSaveConfigFolder => this.GetPerSaveConfigFolder();
/// <summary>The full path to the per-save configuration file for the current save (if <see cref="StardewModdingAPI.Manifest.PerSaveConfigs"/> is <c>true</c>).</summary>
- [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(ModHelper.ReadJsonFile) + " instead")]
+ [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.ReadJsonFile) + " instead")]
public string PerSaveConfigPath
{
get
@@ -75,8 +75,13 @@ namespace StardewModdingAPI
/// <summary>The entry point for your mod. It will always be called once when the mod loads.</summary>
/// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
+ [Obsolete("This overload is obsolete since SMAPI 1.1.")]
public virtual void Entry(ModHelper helper) { }
+ /// <summary>The entry point for your mod. It will always be called once when the mod loads.</summary>
+ /// <param name="helper">Provides methods for interacting with the mod directory, such as read/writing a config file or custom JSON files.</param>
+ public virtual void Entry(IModHelper helper) { }
+
/*********
** Private methods
diff --git a/src/StardewModdingAPI/ModHelper.cs b/src/StardewModdingAPI/ModHelper.cs
index 52cabff0..29ae1280 100644
--- a/src/StardewModdingAPI/ModHelper.cs
+++ b/src/StardewModdingAPI/ModHelper.cs
@@ -6,7 +6,8 @@ using StardewModdingAPI.Advanced;
namespace StardewModdingAPI
{
/// <summary>Provides methods for interacting with a mod directory.</summary>
- public class ModHelper
+ [Obsolete("Use " + nameof(IModHelper) + "instead.")]
+ public class ModHelper : IModHelper
{
/*********
** Accessors
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs
index 962a30f8..e60fb6b2 100644
--- a/src/StardewModdingAPI/Program.cs
+++ b/src/StardewModdingAPI/Program.cs
@@ -404,12 +404,15 @@ namespace StardewModdingAPI
modEntry.PathOnDisk = directory;
Program.Monitor.Log($"Loaded mod: {modEntry.Manifest.Name} by {modEntry.Manifest.Author}, v{modEntry.Manifest.Version} | {modEntry.Manifest.Description}", LogLevel.Info);
Program.ModsLoaded += 1;
- modEntry.Entry(); // deprecated
- modEntry.Entry(modEntry.Helper);
+ modEntry.Entry(); // deprecated since 1.0
+ modEntry.Entry((ModHelper)modEntry.Helper); // deprecated since 1.1
+ modEntry.Entry(modEntry.Helper); // deprecated since 1.1
// raise deprecation warning for old Entry() method
- if (Program.DeprecationManager.IsVirtualMethodImplemented(modEntryType, typeof(Mod), nameof(Mod.Entry)))
+ if (Program.DeprecationManager.IsVirtualMethodImplemented(modEntryType, typeof(Mod), nameof(Mod.Entry), new[] { typeof(object[]) }))
Program.DeprecationManager.Warn(manifest.Name, $"an old version of {nameof(Mod)}.{nameof(Mod.Entry)}", "1.0", DeprecationLevel.Notice);
+ if (Program.DeprecationManager.IsVirtualMethodImplemented(modEntryType, typeof(Mod), nameof(Mod.Entry), new[] { typeof(ModHelper) }))
+ Program.DeprecationManager.Warn(manifest.Name, $"an old version of {nameof(Mod)}.{nameof(Mod.Entry)}", "1.1", DeprecationLevel.Notice);
}
}
else
diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj
index 2d6a7c7f..475d8893 100644
--- a/src/StardewModdingAPI/StardewModdingAPI.csproj
+++ b/src/StardewModdingAPI/StardewModdingAPI.csproj
@@ -195,6 +195,7 @@
<Compile Include="Extensions.cs" />
<Compile Include="Framework\DeprecationLevel.cs" />
<Compile Include="Framework\DeprecationManager.cs" />
+ <Compile Include="IModHelper.cs" />
<Compile Include="Framework\LogFileManager.cs" />
<Compile Include="LogLevel.cs" />
<Compile Include="Framework\ModRegistry.cs" />