mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Add singleton for accessing meeting buttons
This commit is contained in:
1 parent
605c792e8f
commit
0050c34225
6 files changed
+26
-7
No files matched your search
+1
-1
@@ -11,7 +11,7 @@ namespace MiraAPI.MeetingAbilities;
|
||||
/// <summary>
|
||||
/// Class for managing all registered meeting abilities.
|
||||
/// </summary>
|
||||
public static class TargetedMeetingAbilityManager
|
||||
public static class TargetedMeetingButtonManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a list if==of all registered <see cref="TargetedMeetingButton"/>.
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace MiraAPI.MeetingAbilities;
|
||||
|
||||
/// <summary>
|
||||
/// A utility class to get the instance of a <see cref="TargetedMeetingButton"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the button you are trying to access.</typeparam>
|
||||
public static class TargetedMeetingButtonSingleton<T> where T : TargetedMeetingButton
|
||||
{
|
||||
private static T? _instance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the <typeparamref name="T"/> button.
|
||||
/// </summary>
|
||||
[SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "This is a utility class to get the instance of a targeted meeting button.")]
|
||||
public static T Instance => _instance ??= TargetedMeetingButtonManager.Buttons.OfType<T>().Single();
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public static class FreeplayRoundStartPatch
|
||||
{
|
||||
if (!__result)
|
||||
{
|
||||
foreach (var ability in TargetedMeetingAbilityManager.Buttons.Where(x => x.ButtonUsesMode == MeetingButtonUsesMode.PerGame))
|
||||
foreach (var ability in TargetedMeetingButtonManager.Buttons.Where(x => x.ButtonUsesMode == MeetingButtonUsesMode.PerGame))
|
||||
{
|
||||
ability.UsesRemaining = ability.MaxUses;
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public static class IntroCutscenePatches
|
||||
var @event = new BeforeRoundStartEvent(true);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
foreach (var ability in TargetedMeetingAbilityManager.Buttons.Where(x => x.ButtonUsesMode == MeetingButtonUsesMode.PerGame))
|
||||
foreach (var ability in TargetedMeetingButtonManager.Buttons.Where(x => x.ButtonUsesMode == MeetingButtonUsesMode.PerGame))
|
||||
{
|
||||
ability.UsesRemaining = ability.MaxUses;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ internal static class MeetingHudPatches
|
||||
[HarmonyPatch(typeof(PlayerVoteArea), nameof(PlayerVoteArea.Start))]
|
||||
public static void VoteAreaStartPostfix(PlayerVoteArea __instance)
|
||||
{
|
||||
foreach (var targetedMeetingAbility in TargetedMeetingAbilityManager.Buttons)
|
||||
foreach (var targetedMeetingAbility in TargetedMeetingButtonManager.Buttons)
|
||||
{
|
||||
var btn = targetedMeetingAbility.CreateButton(__instance);
|
||||
btn.transform.SetParent(__instance.Buttons.transform);
|
||||
@@ -106,7 +106,7 @@ internal static class MeetingHudPatches
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var ability in TargetedMeetingAbilityManager.Buttons.Where(x => x.ButtonUsesMode == MeetingButtonUsesMode.PerMeeting))
|
||||
foreach (var ability in TargetedMeetingButtonManager.Buttons.Where(x => x.ButtonUsesMode == MeetingButtonUsesMode.PerMeeting))
|
||||
{
|
||||
ability.UsesRemaining = ability.MaxUses;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ internal static class MeetingHudPatches
|
||||
[HarmonyPatch(nameof(MeetingHud.Update))]
|
||||
public static void ForceSkipPatch(MeetingHud __instance)
|
||||
{
|
||||
foreach (var targetedMeetingAbility in TargetedMeetingAbilityManager.Buttons.Where(x => x.Enabled(PlayerControl.LocalPlayer.Data.Role)))
|
||||
foreach (var targetedMeetingAbility in TargetedMeetingButtonManager.Buttons.Where(x => x.Enabled(PlayerControl.LocalPlayer.Data.Role)))
|
||||
{
|
||||
targetedMeetingAbility.UpdateHandler();
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ public sealed class MiraPluginManager
|
||||
{
|
||||
try
|
||||
{
|
||||
return TargetedMeetingAbilityManager.RegisterMeetingAbility(type, info);
|
||||
return TargetedMeetingButtonManager.RegisterMeetingAbility(type, info);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user