diff --git a/MonkeyLoader/Meta/IMod.cs b/MonkeyLoader/Meta/IMod.cs
index 34b0bde..8a92526 100644
--- a/MonkeyLoader/Meta/IMod.cs
+++ b/MonkeyLoader/Meta/IMod.cs
@@ -11,7 +11,7 @@ namespace MonkeyLoader.Meta
///
/// Contains all metadata and references for a mod.
///
- public interface IMod : IConfigOwner, ILoadedNuGetPackage, IShutdown, IComparable
+ public interface IMod : IConfigOwner, ILoadedNuGetPackage, IComparable
{
///
/// Gets the names of the authors of this mod.
@@ -65,10 +65,6 @@ public interface IMod : IConfigOwner, ILoadedNuGetPackage, IShutdown, IComparabl
///
public abstract Uri? IconUrl { get; }
- ///
- /// Gets the unique identifier of this mod.
- ///
- //public string Id { get; }
///
/// Gets whether this mod is a game pack.
///
@@ -150,7 +146,7 @@ public interface IMod : IConfigOwner, ILoadedNuGetPackage, IShutdown, IComparabl
public bool HasTag(string tag);
}
- internal interface IModInternal : IMod
+ internal interface IModInternal : IMod, IShutdown
{
public bool LoadEarlyMonkeys();
diff --git a/MonkeyLoader/Meta/IShutdown.cs b/MonkeyLoader/Meta/IShutdown.cs
index 9782716..3761d84 100644
--- a/MonkeyLoader/Meta/IShutdown.cs
+++ b/MonkeyLoader/Meta/IShutdown.cs
@@ -6,6 +6,28 @@
namespace MonkeyLoader.Meta
{
+ ///
+ /// Contains extension methods for collections of instances.
+ ///
+ public static class ShutdownEnumerableExtensions
+ {
+ ///
+ /// Calls the method on all elements of the collection,
+ /// aggregating their success state as an 'all'.
+ ///
+ /// The instances to process.
+ /// true if all instances successfully shut down, false otherwise.
+ public static bool ShutdownAll(this IEnumerable shutdowns)
+ {
+ var success = true;
+
+ foreach (var shutdown in shutdowns)
+ success &= shutdown.Shutdown();
+
+ return success;
+ }
+ }
+
///
/// Interface for everything that can be shut down.
///
diff --git a/MonkeyLoader/ModEnumerableExtensions.cs b/MonkeyLoader/ModEnumerableExtensions.cs
index cb3e97c..6ac86e0 100644
--- a/MonkeyLoader/ModEnumerableExtensions.cs
+++ b/MonkeyLoader/ModEnumerableExtensions.cs
@@ -29,6 +29,22 @@ public static IEarlyMonkey[] GetEarlyMonkeys(this IEnumerable mods)
public static IEarlyMonkey[] GetEarlyMonkeysAscending(this IEnumerable mods)
=> mods.GetSortedEarlyMonkeys(Monkey.AscendingComparer);
+ ///
+ /// Gets the s of the given in topological order.
+ ///
+ /// The mod to get the s of.
+ /// The s of the given in topological order.
+ public static IEarlyMonkey[] GetEarlyMonkeysAscending(this IMod mod)
+ => mod.GetSortedEarlyMonkeys(Monkey.AscendingComparer);
+
+ ///
+ /// Gets the s of the given in reverse-topological order.
+ ///
+ /// The mod to get the s of.
+ /// The s of the given in reverse-topological order.
+ public static IEarlyMonkey[] GetEarlyMonkeysDescending(this IMod mod)
+ => mod.GetSortedEarlyMonkeys(Monkey.DescendingComparer);
+
///
/// Gets the s of all given in reverse-topological order.
///
@@ -54,12 +70,42 @@ public static IMonkey[] GetMonkeysAscending(this IEnumerable mods)
=> mods.GetSortedMonkeys(Monkey.AscendingComparer);
///
- /// Gets the s of all given in reverse-topological order.
+ /// Gets the s of the given in topological order.
///
- /// The mods to get the s of.
- /// All s of the given in reverse-topological order.
- public static IMonkey[] GetMonkeysDescending(this IEnumerable mods)
- => mods.GetSortedMonkeys(Monkey.DescendingComparer);
+ /// The mod to get the s of.
+ /// The s of the given in topological order.
+ public static IMonkey[] GetMonkeysAscending(this IMod mod)
+ => mod.GetSortedMonkeys(Monkey.AscendingComparer);
+
+ ///
+ /// Gets the s of all given in reverse-topological order.
+ ///
+ /// The mods to get the s of.
+ /// All s of the given in reverse-topological order.
+ public static IMonkey[] GetMonkeysDescending(this IEnumerable mod)
+ => mod.GetSortedMonkeys(Monkey.DescendingComparer);
+
+ ///
+ /// Gets the s of the given in reverse-topological order.
+ ///
+ /// The mod to get the s of.
+ /// The s of the given in reverse-topological order.
+ public static IMonkey[] GetMonkeysDescending(this IMod mod)
+ => mod.GetSortedMonkeys(Monkey.DescendingComparer);
+
+ ///
+ /// Gets the s of the given in the order defined by the given .
+ ///
+ /// The mod to get the s of.
+ /// The defining the order.
+ /// The s of the given in the defined order.
+ public static IEarlyMonkey[] GetSortedEarlyMonkeys(this IMod mod, Comparison comparison)
+ {
+ var earlyMonkeys = mod.EarlyMonkeys.ToArray();
+ Array.Sort(earlyMonkeys, comparison);
+
+ return earlyMonkeys;
+ }
///
/// Gets the s of all given in the order defined by the given .
@@ -84,6 +130,29 @@ public static IEarlyMonkey[] GetSortedEarlyMonkeys(this IEnumerable mods,
public static IEarlyMonkey[] GetSortedEarlyMonkeys(this IEnumerable mods, IComparer comparer)
=> mods.GetSortedEarlyMonkeys(comparer.Compare);
+ ///
+ /// Gets the s of the given in the order defined by the given .
+ ///
+ /// The mod to get the s of.
+ /// The defining the order.
+ /// The s of the given in the defined order.
+ public static IEarlyMonkey[] GetSortedEarlyMonkeys(this IMod mod, IComparer comparer)
+ => mod.GetSortedEarlyMonkeys(comparer.Compare);
+
+ ///
+ /// Gets the s of the given in the order defined by the given .
+ ///
+ /// The mod to get the s of.
+ /// The defining the order.
+ /// The s of the given in the defined order.
+ public static IMonkey[] GetSortedMonkeys(this IMod mod, Comparison comparison)
+ {
+ var monkeys = mod.Monkeys.ToArray();
+ Array.Sort(monkeys, comparison);
+
+ return monkeys;
+ }
+
///
/// Gets the s of all given in the order defined by the given .
///
@@ -93,6 +162,15 @@ public static IEarlyMonkey[] GetSortedEarlyMonkeys(this IEnumerable mods,
public static IMonkey[] GetSortedMonkeys(this IEnumerable mods, IComparer comparer)
=> mods.GetSortedMonkeys(comparer.Compare);
+ ///
+ /// Gets the s of the given in the order defined by the given .
+ ///
+ /// The mod to get the s of.
+ /// The defining the order.
+ /// All s of the given in the defined order.
+ public static IMonkey[] GetSortedMonkeys(this IMod mod, IComparer comparer)
+ => mod.GetSortedMonkeys(comparer.Compare);
+
///
/// Gets the s of all given in the order defined by the given .
///
diff --git a/MonkeyLoader/MonkeyLoader.cs b/MonkeyLoader/MonkeyLoader.cs
index f84af22..e8d458f 100644
--- a/MonkeyLoader/MonkeyLoader.cs
+++ b/MonkeyLoader/MonkeyLoader.cs
@@ -24,7 +24,7 @@ namespace MonkeyLoader
///
public sealed class MonkeyLoader : IConfigOwner, IShutdown
{
- private readonly SortedSet _allMods = new(Mod.AscendingComparer);
+ private readonly SortedDictionary _allMods = new(Mod.AscendingComparer);
private LoggingHandler _loggingHandler = MissingLoggingHandler.Instance;
///
@@ -45,7 +45,7 @@ public sealed class MonkeyLoader : IConfigOwner, IShutdown
///
/// Gets all loaded game pack s in topological order.
///
- public IEnumerable GamePacks => _allMods.Where(mod => mod.IsGamePack);
+ public IEnumerable GamePacks => _allMods.Keys.Where(mod => mod.IsGamePack);
///
/// Gets this loader's id.
@@ -99,7 +99,7 @@ public LoggingHandler LoggingHandler
///
/// Gets all loaded s in topological order.
///
- public IEnumerable Mods => _allMods.AsSafeEnumerable();
+ public IEnumerable Mods => _allMods.Keys.AsSafeEnumerable();
///
/// Gets the NuGet manager used by this loader.
@@ -109,7 +109,7 @@ public LoggingHandler LoggingHandler
///
/// Gets all loaded regular s in topological order.
///
- public IEnumerable RegularMods => _allMods.Where(mod => !mod.IsGamePack);
+ public IEnumerable RegularMods => _allMods.Keys.Where(mod => !mod.IsGamePack);
///
/// Gets whether this loaders's Shutdown() failed when it was called.
@@ -146,7 +146,11 @@ public MonkeyLoader(string configPath = "MonkeyLoader/MonkeyLoader.json", Loggin
foreach (var modLocation in Locations.Mods)
{
modLocation.LoadMod += (mL, path) => TryLoadAndRunMod(path, out _);
- modLocation.UnloadMod += (mL, path) => ShutdownMod(path);
+ modLocation.UnloadMod += (mL, path) =>
+ {
+ if (TryFindModByLocation(path, out var mod))
+ ShutdownMod(mod);
+ };
}
// TODO: do this properly - scan all loaded assemblies?
@@ -215,7 +219,7 @@ public void AddMod(IMod mod)
{
Logger.Debug(() => $"Adding {(mod.IsGamePack ? "game pack" : "regular")} mod: {mod.Title}");
- _allMods.Add((IModInternal)mod);
+ _allMods.Add(mod, (IModInternal)mod);
NuGet.Add(mod);
}
@@ -329,7 +333,7 @@ public IEnumerable LoadAllMods()
public void LoadEarlyMonkeys(IEnumerable mods)
{
Logger.Trace(() => "Loading early monkeys in this order:");
- Logger.Trace(mods.Cast().Select(mod => new Func