Skip to content

Commit

Permalink
Make the events enumerables instead of single mods
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Mar 10, 2024
1 parent 00e2990 commit 3eb790c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
40 changes: 22 additions & 18 deletions MonkeyLoader/MonkeyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@
namespace MonkeyLoader
{
/// <summary>
/// The delegate that gets called when a mod is added to or removed from a <see cref="MonkeyLoader"/>.
/// The delegate that gets called when a mod is added to a <see cref="MonkeyLoader"/>.
/// </summary>
/// <param name="loader">The loader responsible for the mod.</param>
/// <param name="mod">The mod that was added or removed.</param>
public delegate void ModsChangedEventHandler(MonkeyLoader loader, Mod mod);
/// <param name="mod">The mod that was added.</param>
public delegate void ModChangedEventHandler(MonkeyLoader loader, Mod mod);

/// <summary>
/// The delegate that gets called when mods are run or shut down by a <see cref="MonkeyLoader"/>.
/// </summary>
/// <param name="loader">The loader responsible for the mods.</param>
/// <param name="mods">The mods that were run or shut down.</param>
public delegate void ModsChangedEventHandler(MonkeyLoader loader, IEnumerable<Mod> mods);

/// <summary>
/// The root of all mod loading.
Expand Down Expand Up @@ -593,8 +600,7 @@ public void RunMods(params Mod[] mods)
LoadMonkeys(mods);
RunMonkeys(mods);

foreach (var mod in mods)
ModRan?.TryInvokeAll(this, mod);
ModsRan?.TryInvokeAll(this, mods);
}

/// <summary>
Expand Down Expand Up @@ -708,7 +714,7 @@ public bool Shutdown()
/// <returns>Whether it ran successfully.</returns>
public bool ShutdownMod(Mod mod)
{
ModShuttingDown?.TryInvokeAll(this, mod);
ModsShuttingDown?.TryInvokeAll(this, mod.Yield());

var earlyMonkeys = mod.GetEarlyMonkeysDescending();
var monkeys = mod.GetMonkeysDescending();
Expand All @@ -720,7 +726,7 @@ public bool ShutdownMod(Mod mod)
success &= mod.Shutdown();

_allMods.Remove(mod);
ModShutdown?.TryInvokeAll(this, mod);
ModsShutdown?.TryInvokeAll(this, mod.Yield());

return success;
}
Expand All @@ -739,8 +745,7 @@ public bool ShutdownMods(params Mod[] mods)
var success = true;
Array.Sort(mods, Mod.DescendingComparer);

foreach (var mod in mods)
ModShuttingDown?.TryInvokeAll(this, mod);
ModsShuttingDown?.TryInvokeAll(this, mods);

var earlyMonkeys = mods.GetEarlyMonkeysDescending();
var monkeys = mods.GetMonkeysDescending();
Expand All @@ -757,8 +762,7 @@ public bool ShutdownMods(params Mod[] mods)
foreach (var mod in mods)
_allMods.Remove(mod);

foreach (var mod in mods)
ModShutdown?.TryInvokeAll(this, mod);
ModsShutdown?.TryInvokeAll(this, mods);

return success;
}
Expand Down Expand Up @@ -926,22 +930,22 @@ private bool TryLoadMod(string path, [NotNullWhen(true)] out NuGetPackageMod? mo
/// <summary>
/// Called when a <see cref="Mod"/> is <see cref="AddMod">added</see> to this loader.
/// </summary>
public event ModsChangedEventHandler? ModAdded;
public event ModChangedEventHandler? ModAdded;

/// <summary>
/// Called after a <see cref="Mod"/> has been <see cref="RunMod">ran</see> by this loader.
/// Called after <see cref="Mod"/>s have been <see cref="RunMods(Mod[])">run</see> by this loader.
/// </summary>
public event ModsChangedEventHandler? ModRan;
public event ModsChangedEventHandler? ModsRan;

/// <summary>
/// Called after a <see cref="Mod"/> has been <see cref="Mod.Shutdown">shut down</see> by this loader.
/// Called after <see cref="Mod"/>s have been <see cref="Mod.Shutdown">shut down</see> by this loader.
/// </summary>
public event ModsChangedEventHandler? ModShutdown;
public event ModsChangedEventHandler? ModsShutdown;

/// <summary>
/// Called when a <see cref="Mod"/> is about to be <see cref="ShutdownMod">shut down</see> by this loader.
/// Called when <see cref="Mod"/>s are about to be <see cref="ShutdownMods(Mod[])">shut down</see> by this loader.
/// </summary>
public event ModsChangedEventHandler? ModShuttingDown;
public event ModsChangedEventHandler? ModsShuttingDown;

/// <summary>
/// Denotes the different stages of the loader's execution.<br/>
Expand Down
2 changes: 1 addition & 1 deletion MonkeyLoader/MonkeyLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>MonkeyLoader</Title>
<Authors>Banane9</Authors>
<Version>0.7.1-beta</Version>
<Version>0.7.2-beta</Version>
<Description>A convenience and extendability focused mod loader using NuGet packages.</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
Expand Down

0 comments on commit 3eb790c

Please sign in to comment.