summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Framework/DeprecationManager.cs4
-rw-r--r--src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs9
-rw-r--r--src/SMAPI/Framework/ModRegistry.cs59
-rw-r--r--src/SMAPI/Program.cs10
4 files changed, 32 insertions, 50 deletions
diff --git a/src/SMAPI/Framework/DeprecationManager.cs b/src/SMAPI/Framework/DeprecationManager.cs
index 20bb0d2d..7a824a05 100644
--- a/src/SMAPI/Framework/DeprecationManager.cs
+++ b/src/SMAPI/Framework/DeprecationManager.cs
@@ -37,7 +37,7 @@ namespace StardewModdingAPI.Framework
/// <param name="severity">How deprecated the code is.</param>
public void Warn(string nounPhrase, string version, DeprecationLevel severity)
{
- this.Warn(this.ModRegistry.GetModFromStack(), nounPhrase, version, severity);
+ this.Warn(this.ModRegistry.GetFromStack()?.DisplayName, nounPhrase, version, severity);
}
/// <summary>Log a deprecation warning.</summary>
@@ -82,7 +82,7 @@ namespace StardewModdingAPI.Framework
/// <returns>Returns whether the deprecation was successfully marked as warned. Returns <c>false</c> if it was already marked.</returns>
public bool MarkWarned(string nounPhrase, string version)
{
- return this.MarkWarned(this.ModRegistry.GetModFromStack(), nounPhrase, version);
+ return this.MarkWarned(this.ModRegistry.GetFromStack()?.DisplayName, nounPhrase, version);
}
/// <summary>Mark a deprecation warning as already logged.</summary>
diff --git a/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs b/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs
index 9e824694..4e3f56de 100644
--- a/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs
+++ b/src/SMAPI/Framework/ModHelpers/ModRegistryHelper.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
+using System.Linq;
namespace StardewModdingAPI.Framework.ModHelpers
{
@@ -27,7 +28,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <summary>Get metadata for all loaded mods.</summary>
public IEnumerable<IManifest> GetAll()
{
- return this.Registry.GetAll();
+ return this.Registry.GetAll().Select(p => p.Manifest);
}
/// <summary>Get metadata for a loaded mod.</summary>
@@ -35,14 +36,14 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <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);
+ return this.Registry.Get(uniqueID)?.Manifest;
}
/// <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);
+ return this.Registry.Get(uniqueID) != null;
}
}
}
diff --git a/src/SMAPI/Framework/ModRegistry.cs b/src/SMAPI/Framework/ModRegistry.cs
index 9dde7a20..4dbc3541 100644
--- a/src/SMAPI/Framework/ModRegistry.cs
+++ b/src/SMAPI/Framework/ModRegistry.cs
@@ -15,26 +15,31 @@ namespace StardewModdingAPI.Framework
/// <summary>The registered mod data.</summary>
private readonly List<IModMetadata> Mods = new List<IModMetadata>();
- /// <summary>The friendly mod names treated as deprecation warning sources (assembly full name => mod name).</summary>
- private readonly IDictionary<string, string> ModNamesByAssembly = new Dictionary<string, string>();
+ /// <summary>An assembly full name => mod lookup.</summary>
+ private readonly IDictionary<string, IModMetadata> ModNamesByAssembly = new Dictionary<string, IModMetadata>();
/*********
** Public methods
*********/
- /****
- ** Basic metadata
- ****/
+ /// <summary>Register a mod as a possible source of deprecation warnings.</summary>
+ /// <param name="metadata">The mod metadata.</param>
+ public void Add(IModMetadata metadata)
+ {
+ this.Mods.Add(metadata);
+ this.ModNamesByAssembly[metadata.Mod.GetType().Assembly.FullName] = metadata;
+ }
+
/// <summary>Get metadata for all loaded mods.</summary>
- public IEnumerable<IManifest> GetAll()
+ public IEnumerable<IModMetadata> GetAll()
{
- return this.Mods.Select(p => p.Manifest);
+ return this.Mods.Select(p => p);
}
/// <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)
+ public IModMetadata Get(string uniqueID)
{
// normalise search ID
if (string.IsNullOrWhiteSpace(uniqueID))
@@ -42,37 +47,13 @@ namespace StardewModdingAPI.Framework
uniqueID = uniqueID.Trim();
// find match
- return this.GetAll().FirstOrDefault(p => p.UniqueID.Trim().Equals(uniqueID, StringComparison.InvariantCultureIgnoreCase));
- }
-
- /// <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.Get(uniqueID) != null;
- }
-
- /****
- ** Mod data
- ****/
- /// <summary>Register a mod as a possible source of deprecation warnings.</summary>
- /// <param name="metadata">The mod metadata.</param>
- public void Add(IModMetadata metadata)
- {
- this.Mods.Add(metadata);
- this.ModNamesByAssembly[metadata.Mod.GetType().Assembly.FullName] = metadata.DisplayName;
- }
-
- /// <summary>Get all enabled mods.</summary>
- public IEnumerable<IModMetadata> GetMods()
- {
- return (from mod in this.Mods select mod);
+ return this.GetAll().FirstOrDefault(p => p.Manifest.UniqueID.Trim().Equals(uniqueID, StringComparison.InvariantCultureIgnoreCase));
}
- /// <summary>Get the friendly mod name which defines a type.</summary>
+ /// <summary>Get the mod metadata from one of its assemblies.</summary>
/// <param name="type">The type to check.</param>
/// <returns>Returns the mod name, or <c>null</c> if the type isn't part of a known mod.</returns>
- public string GetModFrom(Type type)
+ public IModMetadata GetFrom(Type type)
{
// null
if (type == null)
@@ -89,7 +70,7 @@ namespace StardewModdingAPI.Framework
/// <summary>Get the friendly name for the closest assembly registered as a source of deprecation warnings.</summary>
/// <returns>Returns the source name, or <c>null</c> if no registered assemblies were found.</returns>
- public string GetModFromStack()
+ public IModMetadata GetFromStack()
{
// get stack frames
StackTrace stack = new StackTrace();
@@ -101,9 +82,9 @@ namespace StardewModdingAPI.Framework
foreach (StackFrame frame in frames)
{
MethodBase method = frame.GetMethod();
- string name = this.GetModFrom(method.ReflectedType);
- if (name != null)
- return name;
+ IModMetadata mod = this.GetFrom(method.ReflectedType);
+ if (mod != null)
+ return mod;
}
// no known assembly found
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index 8bc2c675..bd4692e6 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -247,7 +247,7 @@ namespace StardewModdingAPI
this.IsDisposed = true;
// dispose mod data
- foreach (IModMetadata mod in this.ModRegistry.GetMods())
+ foreach (IModMetadata mod in this.ModRegistry.GetAll())
{
try
{
@@ -374,7 +374,7 @@ namespace StardewModdingAPI
}
// update window titles
- int modsLoaded = this.ModRegistry.GetMods().Count();
+ int modsLoaded = this.ModRegistry.GetAll().Count();
this.GameInstance.Window.Title = $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion} with {modsLoaded} mods";
Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion} with {modsLoaded} mods";
@@ -390,7 +390,7 @@ namespace StardewModdingAPI
LocalizedContentManager.LanguageCode languageCode = this.ContentManager.GetCurrentLanguage();
// update mod translation helpers
- foreach (IModMetadata mod in this.ModRegistry.GetMods())
+ foreach (IModMetadata mod in this.ModRegistry.GetAll())
(mod.Mod.Helper.Translation as TranslationHelper)?.SetLocale(locale, languageCode);
}
@@ -753,7 +753,7 @@ namespace StardewModdingAPI
}
}
}
- IModMetadata[] loadedMods = this.ModRegistry.GetMods().ToArray();
+ IModMetadata[] loadedMods = this.ModRegistry.GetAll().ToArray();
// log skipped mods
this.Monitor.Newline();
@@ -858,7 +858,7 @@ namespace StardewModdingAPI
private void ReloadTranslations()
{
JsonHelper jsonHelper = new JsonHelper();
- foreach (IModMetadata metadata in this.ModRegistry.GetMods())
+ foreach (IModMetadata metadata in this.ModRegistry.GetAll())
{
// read translation files
IDictionary<string, IDictionary<string, string>> translations = new Dictionary<string, IDictionary<string, string>>();