From ba590b20a6581323ac13fc63d380524789d49c97 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 19 Jan 2017 11:07:48 -0500 Subject: add public mod registry (#220) --- src/StardewModdingAPI/Framework/ModRegistry.cs | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/StardewModdingAPI/Framework') diff --git a/src/StardewModdingAPI/Framework/ModRegistry.cs b/src/StardewModdingAPI/Framework/ModRegistry.cs index 51ec7123..209f1928 100644 --- a/src/StardewModdingAPI/Framework/ModRegistry.cs +++ b/src/StardewModdingAPI/Framework/ModRegistry.cs @@ -7,7 +7,7 @@ using System.Reflection; namespace StardewModdingAPI.Framework { /// Tracks the installed mods. - internal class ModRegistry + internal class ModRegistry : IModRegistry { /********* ** Properties @@ -22,6 +22,33 @@ namespace StardewModdingAPI.Framework /********* ** Public methods *********/ + /**** + ** IModRegistry + ****/ + /// Get metadata for all loaded mods. + public IEnumerable GetAll() + { + return this.Mods.Select(p => p.ModManifest); + } + + /// Get metadata for a loaded mod. + /// The mod's unique ID. + /// Returns the matching mod's metadata, or null if not found. + public IManifest Get(string uniqueID) + { + return this.GetAll().FirstOrDefault(p => p.UniqueID == uniqueID); + } + + /// Get whether a mod has been loaded. + /// The mod's unique ID. + public bool IsLoaded(string uniqueID) + { + return this.GetAll().Any(p => p.UniqueID == uniqueID); + } + + /**** + ** Internal methods + ****/ /// Register a mod as a possible source of deprecation warnings. /// The mod instance. public void Add(IMod mod) -- cgit