summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/ModHelpers
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-07-07 12:17:22 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-07-07 12:17:22 -0400
commit5583e707b217eb36e71ccae2fe894efbd599a8db (patch)
tree7fe3117d19ec39034ce992dbca4992aace11d511 /src/StardewModdingAPI/Framework/ModHelpers
parent053c0577eccef3db3397a935863af79b30a0282f (diff)
downloadSMAPI-5583e707b217eb36e71ccae2fe894efbd599a8db.tar.gz
SMAPI-5583e707b217eb36e71ccae2fe894efbd599a8db.tar.bz2
SMAPI-5583e707b217eb36e71ccae2fe894efbd599a8db.zip
split helper out of mod registry, add mod ID, refactor ModHelper constructor (#318)
Diffstat (limited to 'src/StardewModdingAPI/Framework/ModHelpers')
-rw-r--r--src/StardewModdingAPI/Framework/ModHelpers/ModHelper.cs36
-rw-r--r--src/StardewModdingAPI/Framework/ModHelpers/ModRegistryHelper.cs48
2 files changed, 64 insertions, 20 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);
+ }
+ }
+}