summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/ModHelpers
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI/Framework/ModHelpers')
-rw-r--r--src/StardewModdingAPI/Framework/ModHelpers/BaseHelper.cs23
-rw-r--r--src/StardewModdingAPI/Framework/ModHelpers/CommandHelper.cs6
-rw-r--r--src/StardewModdingAPI/Framework/ModHelpers/ContentHelper.cs6
-rw-r--r--src/StardewModdingAPI/Framework/ModHelpers/ModHelper.cs12
-rw-r--r--src/StardewModdingAPI/Framework/ModHelpers/ReflectionHelper.cs6
-rw-r--r--src/StardewModdingAPI/Framework/ModHelpers/TranslationHelper.cs6
6 files changed, 46 insertions, 13 deletions
diff --git a/src/StardewModdingAPI/Framework/ModHelpers/BaseHelper.cs b/src/StardewModdingAPI/Framework/ModHelpers/BaseHelper.cs
new file mode 100644
index 00000000..16032da1
--- /dev/null
+++ b/src/StardewModdingAPI/Framework/ModHelpers/BaseHelper.cs
@@ -0,0 +1,23 @@
+namespace StardewModdingAPI.Framework.ModHelpers
+{
+ /// <summary>The common base class for mod helpers.</summary>
+ internal abstract class BaseHelper : IModLinked
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The unique ID of the mod for which the helper was created.</summary>
+ public string ModID { get; }
+
+
+ /*********
+ ** Protected methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="modID">The unique ID of the relevant mod.</param>
+ protected BaseHelper(string modID)
+ {
+ this.ModID = modID;
+ }
+ }
+}
diff --git a/src/StardewModdingAPI/Framework/ModHelpers/CommandHelper.cs b/src/StardewModdingAPI/Framework/ModHelpers/CommandHelper.cs
index 5fd56fdf..bdedb07c 100644
--- a/src/StardewModdingAPI/Framework/ModHelpers/CommandHelper.cs
+++ b/src/StardewModdingAPI/Framework/ModHelpers/CommandHelper.cs
@@ -3,7 +3,7 @@ using System;
namespace StardewModdingAPI.Framework.ModHelpers
{
/// <summary>Provides an API for managing console commands.</summary>
- internal class CommandHelper : ICommandHelper
+ internal class CommandHelper : BaseHelper, ICommandHelper
{
/*********
** Accessors
@@ -19,9 +19,11 @@ namespace StardewModdingAPI.Framework.ModHelpers
** Public methods
*********/
/// <summary>Construct an instance.</summary>
+ /// <param name="modID">The unique ID of the relevant mod.</param>
/// <param name="modName">The friendly mod name for this instance.</param>
/// <param name="commandManager">Manages console commands.</param>
- public CommandHelper(string modName, CommandManager commandManager)
+ public CommandHelper(string modID, string modName, CommandManager commandManager)
+ : base(modID)
{
this.ModName = modName;
this.CommandManager = commandManager;
diff --git a/src/StardewModdingAPI/Framework/ModHelpers/ContentHelper.cs b/src/StardewModdingAPI/Framework/ModHelpers/ContentHelper.cs
index 4fc46dd0..5f72176e 100644
--- a/src/StardewModdingAPI/Framework/ModHelpers/ContentHelper.cs
+++ b/src/StardewModdingAPI/Framework/ModHelpers/ContentHelper.cs
@@ -16,7 +16,7 @@ using xTile.Tiles;
namespace StardewModdingAPI.Framework.ModHelpers
{
/// <summary>Provides an API for loading content assets.</summary>
- internal class ContentHelper : IContentHelper
+ internal class ContentHelper : BaseHelper, IContentHelper
{
/*********
** Properties
@@ -56,8 +56,10 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <summary>Construct an instance.</summary>
/// <param name="contentManager">SMAPI's underlying content manager.</param>
/// <param name="modFolderPath">The absolute path to the mod folder.</param>
+ /// <param name="modID">The unique ID of the relevant mod.</param>
/// <param name="modName">The friendly mod name for use in errors.</param>
- public ContentHelper(SContentManager contentManager, string modFolderPath, string modName)
+ public ContentHelper(SContentManager contentManager, string modFolderPath, string modID, string modName)
+ : base(modID)
{
this.ContentManager = contentManager;
this.ModFolderPath = modFolderPath;
diff --git a/src/StardewModdingAPI/Framework/ModHelpers/ModHelper.cs b/src/StardewModdingAPI/Framework/ModHelpers/ModHelper.cs
index 965a940a..20d891a1 100644
--- a/src/StardewModdingAPI/Framework/ModHelpers/ModHelper.cs
+++ b/src/StardewModdingAPI/Framework/ModHelpers/ModHelper.cs
@@ -5,7 +5,7 @@ using StardewModdingAPI.Framework.Serialisation;
namespace StardewModdingAPI.Framework.ModHelpers
{
/// <summary>Provides simplified APIs for writing mods.</summary>
- internal class ModHelper : IModHelper, IDisposable
+ internal class ModHelper : BaseHelper, IModHelper, IDisposable
{
/*********
** Properties
@@ -40,6 +40,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
** Public methods
*********/
/// <summary>Construct an instance.</summary>
+ /// <param name="modID">The mod's unique ID.</param>
/// <param name="displayName">The mod's display name.</param>
/// <param name="modDirectory">The full path to the mod's folder.</param>
/// <param name="jsonHelper">Encapsulate SMAPI's JSON parsing.</param>
@@ -49,7 +50,8 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <param name="reflection">Simplifies access to private game code.</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 displayName, string modDirectory, JsonHelper jsonHelper, IModRegistry modRegistry, CommandManager commandManager, SContentManager contentManager, IReflectionHelper reflection)
+ public ModHelper(string modID, string displayName, string modDirectory, JsonHelper jsonHelper, IModRegistry modRegistry, CommandManager commandManager, SContentManager contentManager, IReflectionHelper reflection)
+ : base(modID)
{
// validate
if (string.IsNullOrWhiteSpace(modDirectory))
@@ -64,11 +66,11 @@ namespace StardewModdingAPI.Framework.ModHelpers
// initialise
this.DirectoryPath = modDirectory;
this.JsonHelper = jsonHelper;
- this.Content = new ContentHelper(contentManager, modDirectory, displayName);
+ this.Content = new ContentHelper(contentManager, modDirectory, modID, displayName);
this.ModRegistry = modRegistry;
- this.ConsoleCommands = new CommandHelper(displayName, commandManager);
+ this.ConsoleCommands = new CommandHelper(modID, displayName, commandManager);
this.Reflection = reflection;
- this.Translation = new TranslationHelper(displayName, contentManager.GetLocale(), contentManager.GetCurrentLanguage());
+ this.Translation = new TranslationHelper(modID, displayName, contentManager.GetLocale(), contentManager.GetCurrentLanguage());
}
/****
diff --git a/src/StardewModdingAPI/Framework/ModHelpers/ReflectionHelper.cs b/src/StardewModdingAPI/Framework/ModHelpers/ReflectionHelper.cs
index 5a21d999..9411a97a 100644
--- a/src/StardewModdingAPI/Framework/ModHelpers/ReflectionHelper.cs
+++ b/src/StardewModdingAPI/Framework/ModHelpers/ReflectionHelper.cs
@@ -5,7 +5,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
{
/// <summary>Provides helper methods for accessing private game code.</summary>
/// <remarks>This implementation searches up the type hierarchy, and caches the reflected fields and methods with a sliding expiry (to optimise performance without unnecessary memory usage).</remarks>
- internal class ReflectionHelper : IReflectionHelper
+ internal class ReflectionHelper : BaseHelper, IReflectionHelper
{
/*********
** Properties
@@ -18,8 +18,10 @@ namespace StardewModdingAPI.Framework.ModHelpers
** Public methods
*********/
/// <summary>Construct an instance.</summary>
+ /// <param name="modID">The unique ID of the relevant mod.</param>
/// <param name="reflector">The underlying reflection helper.</param>
- public ReflectionHelper(Reflector reflector)
+ public ReflectionHelper(string modID, Reflector reflector)
+ : base(modID)
{
this.Reflector = reflector;
}
diff --git a/src/StardewModdingAPI/Framework/ModHelpers/TranslationHelper.cs b/src/StardewModdingAPI/Framework/ModHelpers/TranslationHelper.cs
index 86737f85..bbe3a81a 100644
--- a/src/StardewModdingAPI/Framework/ModHelpers/TranslationHelper.cs
+++ b/src/StardewModdingAPI/Framework/ModHelpers/TranslationHelper.cs
@@ -6,7 +6,7 @@ using StardewValley;
namespace StardewModdingAPI.Framework.ModHelpers
{
/// <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>
- internal class TranslationHelper : ITranslationHelper
+ internal class TranslationHelper : BaseHelper, ITranslationHelper
{
/*********
** Properties
@@ -35,10 +35,12 @@ namespace StardewModdingAPI.Framework.ModHelpers
** Public methods
*********/
/// <summary>Construct an instance.</summary>
+ /// <param name="modID">The unique ID of the relevant mod.</param>
/// <param name="modName">The name of the relevant mod for error messages.</param>
/// <param name="locale">The initial locale.</param>
/// <param name="languageCode">The game's current language code.</param>
- public TranslationHelper(string modName, string locale, LocalizedContentManager.LanguageCode languageCode)
+ public TranslationHelper(string modID, string modName, string locale, LocalizedContentManager.LanguageCode languageCode)
+ : base(modID)
{
// save data
this.ModName = modName;