summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ModRegistry.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-12-26 00:31:36 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-12-26 00:31:36 -0500
commit15d4b6310e3dd15c62f3faedbf1290b2db26fb59 (patch)
tree47d49a9c69628f0df1e688361f46bc5b46b3c0fd /src/SMAPI/Framework/ModRegistry.cs
parent5cc5f089b9645a60385ff293b5a7202f260bfc0f (diff)
parentf19cc3aac1a781bf2f2d20bc9577c2fe929b1e96 (diff)
downloadSMAPI-15d4b6310e3dd15c62f3faedbf1290b2db26fb59.tar.gz
SMAPI-15d4b6310e3dd15c62f3faedbf1290b2db26fb59.tar.bz2
SMAPI-15d4b6310e3dd15c62f3faedbf1290b2db26fb59.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/ModRegistry.cs')
-rw-r--r--src/SMAPI/Framework/ModRegistry.cs62
1 files changed, 23 insertions, 39 deletions
diff --git a/src/SMAPI/Framework/ModRegistry.cs b/src/SMAPI/Framework/ModRegistry.cs
index 9dde7a20..453d2868 100644
--- a/src/SMAPI/Framework/ModRegistry.cs
+++ b/src/SMAPI/Framework/ModRegistry.cs
@@ -15,26 +15,34 @@ 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>();
+
+ /// <summary>Whether all mods have been initialised and their <see cref="IMod.Entry"/> method called.</summary>
+ public bool AreAllModsInitialised { get; set; }
/*********
** 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 +50,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 +73,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 +85,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