Skip to content

Commit

Permalink
Merge pull request #18 from MonkeyModdingTroop/feature/add-configured…
Browse files Browse the repository at this point in the history
…-monkey-interface

Add an IConfiguredMonkey interface and make the ConfigSection public.
  • Loading branch information
Banane9 authored May 15, 2024
2 parents e97bf3d + 182e87c commit d7ad15b
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 12 deletions.
36 changes: 36 additions & 0 deletions MonkeyLoader/Meta/IConfiguredMonkey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using MonkeyLoader.Configuration;
using MonkeyLoader.Patching;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MonkeyLoader.Meta
{
/// <summary>
/// Defines the non-generic interface for all sorts of
/// <see cref="ConfiguredMonkey{TMonkey, TConfigSection}">configured monkeys</see>.
/// </summary>
public interface IConfiguredMonkey : IMonkey
{
/// <summary>
/// Gets the loaded config section for this monkey after it has been run.
/// </summary>
public ConfigSection ConfigSection { get; }
}

/// <summary>
/// Defines the interface for all sorts of
/// <see cref="ConfiguredMonkey{TMonkey, TConfigSection}">configured monkeys</see>.
/// </summary>
/// <typeparam name="TConfigSection">The type of the config section loaded by this monkey.</typeparam>
public interface IConfiguredMonkey<TConfigSection> : IConfiguredMonkey
where TConfigSection : ConfigSection
{
/// <summary>
/// Gets the loaded config section for this monkey after it has been run.
/// </summary>
public new TConfigSection ConfigSection { get; }
}
}
5 changes: 3 additions & 2 deletions MonkeyLoader/Meta/IMonkey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace MonkeyLoader.Meta
{
/// <summary>
/// Interface for <see cref="EarlyMonkey{TMonkey}"/>s.
/// Defines the interface for all <see cref="EarlyMonkey{TMonkey}">early monkeys</see>.
/// </summary>
public interface IEarlyMonkey : IMonkey
{
Expand All @@ -31,7 +31,8 @@ public interface IEarlyMonkey : IMonkey
}

/// <summary>
/// The interface for any monkey.
/// Defines the interface for all (<see cref="EarlyMonkey{TMonkey}">early</see>)
/// <see cref="Monkey{TMonkey}">monkeys</see>.
/// </summary>
public interface IMonkey : IRun, IShutdown, IComparable<IMonkey>
{
Expand Down
2 changes: 1 addition & 1 deletion MonkeyLoader/Meta/IRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace MonkeyLoader.Meta
{
/// <summary>
/// Interface for everything that can be run.
/// Defines the interface for everything that can be run.
/// </summary>
public interface IRun
{
Expand Down
2 changes: 1 addition & 1 deletion MonkeyLoader/Meta/IShutdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static bool ShutdownAll(this IEnumerable<IShutdown> shutdowns, bool appli
}

/// <summary>
/// Interface for everything that can be shut down.
/// Defines the interface for everything that can be shut down.
/// </summary>
public interface IShutdown
{
Expand Down
3 changes: 1 addition & 2 deletions MonkeyLoader/Meta/Mod.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using HarmonyLib;
using MonkeyLoader.Configuration;
using MonkeyLoader.Configuration;
using MonkeyLoader.Events;
using MonkeyLoader.Logging;
using MonkeyLoader.NuGet;
Expand Down
9 changes: 7 additions & 2 deletions MonkeyLoader/Patching/ConfiguredEarlyMonkey.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MonkeyLoader.Configuration;
using MonkeyLoader.Meta;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -15,14 +16,18 @@ namespace MonkeyLoader.Patching
/// <inheritdoc/>
/// <typeparam name="TMonkey">The type of the actual patcher.</typeparam>
/// <typeparam name="TConfigSection">The type of the config section to load.</typeparam>
public abstract class ConfiguredEarlyMonkey<TMonkey, TConfigSection> : EarlyMonkey<TMonkey>
public abstract class ConfiguredEarlyMonkey<TMonkey, TConfigSection> : EarlyMonkey<TMonkey>, IConfiguredMonkey<TConfigSection>
where TMonkey : ConfiguredEarlyMonkey<TMonkey, TConfigSection>, new()
where TConfigSection : ConfigSection, new()
{
/// <summary>
/// Gets the loaded config section for this pre-patcher after it has been <see cref="EarlyMonkey{TMonkey}.Prepare()">prepared</see>.
/// </summary>
protected static TConfigSection ConfigSection { get; private set; } = null!;
public static TConfigSection ConfigSection { get; private set; } = null!;

TConfigSection IConfiguredMonkey<TConfigSection>.ConfigSection => ConfigSection;

ConfigSection IConfiguredMonkey.ConfigSection => ConfigSection;

/// <summary>
/// Allows creating only a single <typeparamref name="TMonkey"/> instance.
Expand Down
9 changes: 7 additions & 2 deletions MonkeyLoader/Patching/ConfiguredMonkey.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HarmonyLib;
using MonkeyLoader.Configuration;
using MonkeyLoader.Meta;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -17,14 +18,18 @@ namespace MonkeyLoader.Patching
/// <inheritdoc/>
/// <typeparam name="TMonkey">The type of the actual patcher.</typeparam>
/// <typeparam name="TConfigSection">The type of the config section to load.</typeparam>
public abstract class ConfiguredMonkey<TMonkey, TConfigSection> : Monkey<TMonkey>
public abstract class ConfiguredMonkey<TMonkey, TConfigSection> : Monkey<TMonkey>, IConfiguredMonkey<TConfigSection>
where TMonkey : ConfiguredMonkey<TMonkey, TConfigSection>, new()
where TConfigSection : ConfigSection, new()
{
/// <summary>
/// Gets the loaded config section for this patcher after it has been <see cref="MonkeyBase.Run">run</see>.
/// </summary>
protected static TConfigSection ConfigSection { get; private set; } = null!;
public static TConfigSection ConfigSection { get; private set; } = null!;

TConfigSection IConfiguredMonkey<TConfigSection>.ConfigSection => ConfigSection;

ConfigSection IConfiguredMonkey.ConfigSection => ConfigSection;

/// <summary>
/// Allows creating only a single <typeparamref name="TMonkey"/> instance.
Expand Down
3 changes: 3 additions & 0 deletions MonkeyLoader/Patching/EarlyMonkey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public abstract class EarlyMonkey<TMonkey> : MonkeyBase<TMonkey>, IEarlyMonkey
/// </summary>
protected EarlyMonkey()
{
if (GetType() != typeof(TMonkey))
throw new InvalidOperationException("TMonkey must be the concrete Type being instantiated!");

_prePatchTargets = new Lazy<PrePatchTarget[]>(() => GetPrePatchTargets().ToArray());
}

Expand Down
8 changes: 6 additions & 2 deletions MonkeyLoader/Patching/Monkey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,17 @@ private int TypeNameComparison(IMonkey x, IMonkey y)
/// Game assemblies and their types can be directly referenced from these.
/// </remarks>
/// <inheritdoc/>
public abstract class Monkey<TMonkey> : MonkeyBase<TMonkey> where TMonkey : Monkey<TMonkey>, new()
public abstract class Monkey<TMonkey> : MonkeyBase<TMonkey>
where TMonkey : Monkey<TMonkey>, new()
{
/// <summary>
/// Allows creating only a single <typeparamref name="TMonkey"/> instance.
/// </summary>
protected Monkey()
{ }
{
if (GetType() != typeof(TMonkey))
throw new InvalidOperationException("TMonkey must be the concrete Type being instantiated!");
}

/// <inheritdoc/>
public override sealed bool Run()
Expand Down

0 comments on commit d7ad15b

Please sign in to comment.