summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI/Framework')
-rw-r--r--src/StardewModdingAPI/Framework/ModHelpers/ModHelper.cs36
-rw-r--r--src/StardewModdingAPI/Framework/ModHelpers/ModRegistryHelper.cs48
-rw-r--r--src/StardewModdingAPI/Framework/ModRegistry.cs6
3 files changed, 67 insertions, 23 deletions
diff --git a/src/StardewModdingAPI/Framework/ModHelpers/ModHelper.cs b/src/StardewModdingAPI/Framework/ModHelpers/ModHelper.cs
index 20d891a1..665b9cf4 100644
--- a/src/StardewModdingAPI/Framework/ModHelpers/ModHelper.cs
+++ b/src/StardewModdingAPI/Framework/ModHelpers/ModHelper.cs
@@ -23,16 +23,16 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <summary>An API for loading content assets.</summary>
public IContentHelper Content { get; }
- /// <summary>Simplifies access to private game code.</summary>
+ /// <summary>An API for accessing private game code.</summary>
public IReflectionHelper Reflection { get; }
- /// <summary>Metadata about loaded mods.</summary>
+ /// <summary>an API for fetching metadata about loaded mods.</summary>
public IModRegistry ModRegistry { get; }
/// <summary>An API for managing console commands.</summary>
public 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>
+ /// <summary>An API for reading 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>
public ITranslationHelper Translation { get; }
@@ -41,36 +41,32 @@ namespace StardewModdingAPI.Framework.ModHelpers
*********/
/// <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>
- /// <param name="modRegistry">Metadata about loaded mods.</param>
- /// <param name="commandManager">Manages console commands.</param>
- /// <param name="contentManager">The content manager which loads content assets.</param>
- /// <param name="reflection">Simplifies access to private game code.</param>
+ /// <param name="contentHelper">An API for loading content assets.</param>
+ /// <param name="commandHelper">An API for managing console commands.</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="translationHelper">An API for reading translations stored in the mod's <c>i18n</c> folder.</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 displayName, string modDirectory, JsonHelper jsonHelper, IModRegistry modRegistry, CommandManager commandManager, SContentManager contentManager, IReflectionHelper reflection)
+ public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, IContentHelper contentHelper, ICommandHelper commandHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, ITranslationHelper translationHelper)
: base(modID)
{
- // validate
+ // validate directory
if (string.IsNullOrWhiteSpace(modDirectory))
throw new ArgumentNullException(nameof(modDirectory));
- if (jsonHelper == null)
- throw new ArgumentNullException(nameof(jsonHelper));
- if (modRegistry == null)
- throw new ArgumentNullException(nameof(modRegistry));
if (!Directory.Exists(modDirectory))
throw new InvalidOperationException("The specified mod directory does not exist.");
// initialise
this.DirectoryPath = modDirectory;
- this.JsonHelper = jsonHelper;
- this.Content = new ContentHelper(contentManager, modDirectory, modID, displayName);
- this.ModRegistry = modRegistry;
- this.ConsoleCommands = new CommandHelper(modID, displayName, commandManager);
- this.Reflection = reflection;
- this.Translation = new TranslationHelper(modID, displayName, contentManager.GetLocale(), contentManager.GetCurrentLanguage());
+ this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper));
+ this.Content = contentHelper ?? throw new ArgumentNullException(nameof(contentHelper));
+ this.ModRegistry = modRegistry ?? throw new ArgumentNullException(nameof(modRegistry));
+ this.ConsoleCommands = commandHelper ?? throw new ArgumentNullException(nameof(commandHelper));
+ this.Reflection = reflectionHelper ?? throw new ArgumentNullException(nameof(reflectionHelper));
+ this.Translation = translationHelper ?? throw new ArgumentNullException(nameof(translationHelper));
}
/****
diff --git a/src/StardewModdingAPI/Framework/ModHelpers/ModRegistryHelper.cs b/src/StardewModdingAPI/Framework/ModHelpers/ModRegistryHelper.cs
new file mode 100644
index 00000000..9e824694
--- /dev/null
+++ b/src/StardewModdingAPI/Framework/ModHelpers/ModRegistryHelper.cs
@@ -0,0 +1,48 @@
+using System.Collections.Generic;
+
+namespace StardewModdingAPI.Framework.ModHelpers
+{
+ /// <summary>Provides metadata about installed mods.</summary>
+ internal class ModRegistryHelper : BaseHelper, IModRegistry
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>The underlying mod registry.</summary>
+ private readonly ModRegistry Registry;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="modID">The unique ID of the relevant mod.</param>
+ /// <param name="registry">The underlying mod registry.</param>
+ public ModRegistryHelper(string modID, ModRegistry registry)
+ : base(modID)
+ {
+ this.Registry = registry;
+ }
+
+ /// <summary>Get metadata for all loaded mods.</summary>
+ public IEnumerable<IManifest> GetAll()
+ {
+ return this.Registry.GetAll();
+ }
+
+ /// <summary>Get metadata for a loaded mod.</summary>
+ /// <param name="uniqueID">The mod's unique ID.</param>
+ /// <returns>Returns the matching mod's metadata, or <c>null</c> if not found.</returns>
+ public IManifest Get(string uniqueID)
+ {
+ return this.Registry.Get(uniqueID);
+ }
+
+ /// <summary>Get whether a mod has been loaded.</summary>
+ /// <param name="uniqueID">The mod's unique ID.</param>
+ public bool IsLoaded(string uniqueID)
+ {
+ return this.Registry.IsLoaded(uniqueID);
+ }
+ }
+}
diff --git a/src/StardewModdingAPI/Framework/ModRegistry.cs b/src/StardewModdingAPI/Framework/ModRegistry.cs
index f9d3cfbf..a427bdb7 100644
--- a/src/StardewModdingAPI/Framework/ModRegistry.cs
+++ b/src/StardewModdingAPI/Framework/ModRegistry.cs
@@ -7,7 +7,7 @@ using System.Reflection;
namespace StardewModdingAPI.Framework
{
/// <summary>Tracks the installed mods.</summary>
- internal class ModRegistry : IModRegistry
+ internal class ModRegistry
{
/*********
** Properties
@@ -23,7 +23,7 @@ namespace StardewModdingAPI.Framework
** Public methods
*********/
/****
- ** IModRegistry
+ ** Basic metadata
****/
/// <summary>Get metadata for all loaded mods.</summary>
public IEnumerable<IManifest> GetAll()
@@ -47,7 +47,7 @@ namespace StardewModdingAPI.Framework
}
/****
- ** Internal methods
+ ** Mod data
****/
/// <summary>Register a mod as a possible source of deprecation warnings.</summary>
/// <param name="metadata">The mod metadata.</param>