mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
clean up warnings and typos
This commit is contained in:
167 files changed
+1335
-1433
No files matched your search
+19
-1
@@ -1 +1,19 @@
|
||||
[*.{cs,vb}]
|
||||
[*.{cs,vb}]
|
||||
|
||||
# IDE0008: Use explicit type
|
||||
dotnet_diagnostic.IDE0008.severity = none
|
||||
|
||||
# IDE0160: Convert to block scoped namespace
|
||||
dotnet_diagnostic.IDE0160.severity = none
|
||||
|
||||
# IDE0011: Add braces
|
||||
dotnet_diagnostic.IDE0011.severity = none
|
||||
|
||||
# CS8618: Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
||||
dotnet_diagnostic.CS8618.severity = none
|
||||
|
||||
# CA1805: Do not initialize unnecessarily
|
||||
dotnet_diagnostic.CA1805.severity = none
|
||||
|
||||
# S3358: Ternary operators should not be nested
|
||||
dotnet_diagnostic.S3358.severity = none
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
.git/
|
||||
.idea/
|
||||
.vs/
|
||||
.vs*/
|
||||
obj/
|
||||
bin/
|
||||
.qodo/
|
||||
|
||||
@@ -10,9 +10,7 @@ namespace MiraAPI.Example.Buttons;
|
||||
public class MeetingButton : CustomActionButton
|
||||
{
|
||||
public override string Name => "Call Meeting";
|
||||
|
||||
public override float Cooldown => 15;
|
||||
|
||||
public override int MaxUses => 3;
|
||||
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
@@ -30,10 +28,10 @@ public class MeetingButton : CustomActionButton
|
||||
PlayerControl.LocalPlayer.NetTransform.Halt();
|
||||
var minigame = Object.Instantiate(bt.MinigamePrefab, Camera.main!.transform, false);
|
||||
|
||||
var taskAdderGame = minigame as TaskAdderGame;
|
||||
if (taskAdderGame != null)
|
||||
var taskAdderGame = minigame.TryCast<TaskAdderGame>();
|
||||
if (taskAdderGame)
|
||||
{
|
||||
taskAdderGame.SafePositionWorld = bt.SafePositionLocal + (Vector2)bt.transform.position;
|
||||
taskAdderGame!.SafePositionWorld = bt.SafePositionLocal + (Vector2)bt.transform.position;
|
||||
}
|
||||
|
||||
minigame.transform.localPosition = new Vector3(0f, 0f, -50f);
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ExampleLocalSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
public ConfigEntry<float> ExampleNumber { get; private set; } = config.Bind("General", "Example Number", 4f);
|
||||
|
||||
[LocalNumberSetting(min: 0.1f, max: 2.5f, increment: 0.1f, formatString: "0.0", suffixType: MiraNumberSuffixes.Multiplier)]
|
||||
public ConfigEntry<float> ExampleFloatNumber { get; private set; } = config.Bind("General", "Example Multplier", 1f);
|
||||
public ConfigEntry<float> ExampleFloatNumber { get; private set; } = config.Bind("General", "Example Multiplier", 1f);
|
||||
|
||||
[LocalEnumSetting]
|
||||
public ConfigEntry<ExampleEnumSetting> ExampleEnum { get; private set; } = config.Bind("General", "Example Enum", ExampleEnumSetting.Fries);
|
||||
|
||||
@@ -17,8 +17,13 @@ namespace MiraAPI.Example;
|
||||
public partial class ExamplePlugin : BasePlugin, IMiraPlugin
|
||||
{
|
||||
public Harmony Harmony { get; } = new(Id);
|
||||
public string OptionsTitleText => "Mira API\nExample Mod";
|
||||
public ConfigFile GetConfigFile() => Config;
|
||||
public string OptionsTitleText { get; } = "Mira API\nExample Mod";
|
||||
|
||||
public ConfigFile GetConfigFile()
|
||||
{
|
||||
return Config;
|
||||
}
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
ExampleEventHandlers.Initialize();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<Version>1.0.0</Version>
|
||||
<Description>Example mod for Mira API</Description>
|
||||
<Authors>Angxl, XtraCube</Authors>
|
||||
<NoWarn>$(NoWarn);EnableGenerateDocumentationFile</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -6,9 +6,7 @@ namespace MiraAPI.Example.Options.Modifiers;
|
||||
public class GeneralModifierOptions : AbstractOptionGroup
|
||||
{
|
||||
public override string GroupName => "General";
|
||||
|
||||
public override uint GroupPriority => 0;
|
||||
|
||||
public override MenuCategory ParentMenu => MenuCategory.Modifiers;
|
||||
|
||||
[ModdedToggleOption("Some Boolean Option")]
|
||||
|
||||
@@ -8,9 +8,9 @@ using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Roles;
|
||||
|
||||
public class ChameloenRole : CrewmateRole, ICustomRole
|
||||
public class ChameleonRole : CrewmateRole, ICustomRole
|
||||
{
|
||||
public string RoleName => "Chamelon";
|
||||
public string RoleName => "Chameleon";
|
||||
public string RoleLongDescription => "Stay invisible while not moving.";
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.AcceptedGreen;
|
||||
@@ -28,7 +28,7 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
||||
|
||||
public override void Initialize(PlayerControl player)
|
||||
{
|
||||
Logger<ExamplePlugin>.Info("Initializing ChamelonRole for player: " + player.PlayerId);
|
||||
Logger<ExamplePlugin>.Info("Initializing ChameleonRole for player: " + player.PlayerId);
|
||||
RoleBehaviourStubs.Initialize(this, player);
|
||||
_shouldHide = true;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class ChameloenRole : CrewmateRole, ICustomRole
|
||||
|
||||
public override void Deinitialize(PlayerControl targetPlayer)
|
||||
{
|
||||
Logger<ExamplePlugin>.Info("Deinitializing ChamelonRole for player: " + targetPlayer.PlayerId);
|
||||
Logger<ExamplePlugin>.Info("Deinitializing ChameleonRole for player: " + targetPlayer.PlayerId);
|
||||
RoleBehaviourStubs.Deinitialize(this, targetPlayer);
|
||||
_shouldHide = false;
|
||||
foreach (var cosmetic in Player.cosmetics.transform.GetComponentsInChildren<SpriteRenderer>(true))
|
||||
|
||||
@@ -12,7 +12,7 @@ public class FreezerRole : ImpostorRole, ICustomRole
|
||||
public Color RoleColor => Palette.Blue;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Impostor;
|
||||
|
||||
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
|
||||
public CustomRoleConfiguration Configuration => new(this)
|
||||
{
|
||||
Icon = MiraAssets.ImpostorFile,
|
||||
IconTmp = TmpSpriteUtils.CreateSpriteAsset(MiraAssets.ImpostorFile.LoadAsset(), "ApiExample.Role.Impostor.FreezerRole"),
|
||||
|
||||
@@ -11,7 +11,7 @@ public class TeleporterRole : CrewmateRole, ICustomRole
|
||||
public Color RoleColor => new Color32(221, 176, 152, 255);
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Crewmate;
|
||||
|
||||
public CustomRoleConfiguration Configuration => new CustomRoleConfiguration(this)
|
||||
public CustomRoleConfiguration Configuration => new(this)
|
||||
{
|
||||
OptionsScreenshot = ExampleAssets.Banner,
|
||||
CanModifyChance = false,
|
||||
|
||||
@@ -3,42 +3,32 @@
|
||||
namespace MiraAPI.Events.Mira;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="CustomActionButton"/> click is cancelled. Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// Invoked when a <see cref="CustomActionButton"/> click is cancelled.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// </remarks>
|
||||
/// <typeparam name="T">The <see cref="CustomActionButton"/> type.</typeparam>
|
||||
public sealed class MiraButtonCancelledEvent<T> : MiraEvent where T : CustomActionButton
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> whose click was cancelled.</param>
|
||||
public sealed class MiraButtonCancelledEvent<T>(T button) : MiraEvent where T : CustomActionButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CustomActionButton"/> whose click was cancelled.
|
||||
/// </summary>
|
||||
public T Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonCancelledEvent{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> whose click was cancelled.</param>
|
||||
public MiraButtonCancelledEvent(T button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
public T Button { get; } = button;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="CustomActionButton"/> click is cancelled. Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// Invoked when a <see cref="CustomActionButton"/> click is cancelled.
|
||||
/// </summary>
|
||||
public sealed class MiraButtonCancelledEvent : MiraEvent
|
||||
/// <remarks>
|
||||
/// Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// </remarks>
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> whose click was cancelled.</param>
|
||||
public sealed class MiraButtonCancelledEvent(CustomActionButton button) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CustomActionButton"/> whose click was cancelled.
|
||||
/// </summary>
|
||||
public CustomActionButton Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonCancelledEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> whose click was cancelled.</param>
|
||||
public MiraButtonCancelledEvent(CustomActionButton button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
public CustomActionButton Button { get; } = button;
|
||||
}
|
||||
@@ -3,49 +3,38 @@
|
||||
namespace MiraAPI.Events.Mira;
|
||||
|
||||
/// <summary>
|
||||
/// Button click event for <see cref="CustomActionButton"/>s only. Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// Button click event for <see cref="CustomActionButton"/>s only.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// </remarks>
|
||||
/// <typeparam name="T">The <see cref="CustomActionButton"/> type.</typeparam>
|
||||
public sealed class MiraButtonClickEvent<T> : MiraCancelableEvent where T : CustomActionButton
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> that was clicked.</param>
|
||||
/// <param name="genericClickEvent">The generic <see cref="MiraButtonClickEvent"/> invoked before button-specific events.</param>
|
||||
public sealed class MiraButtonClickEvent<T>(T button, MiraButtonClickEvent genericClickEvent) : MiraCancelableEvent where T : CustomActionButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CustomActionButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public T Button { get; }
|
||||
public T Button { get; } = button;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the generic <see cref="MiraButtonClickEvent"/> that is invoked before this button-specific event.
|
||||
/// </summary>
|
||||
public MiraButtonClickEvent GenericClickEvent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonClickEvent{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> that was clicked.</param>
|
||||
/// <param name="genericClickEvent">The generic <see cref="MiraButtonClickEvent"/> invoked before button-specific events.</param>
|
||||
public MiraButtonClickEvent(T button, MiraButtonClickEvent genericClickEvent)
|
||||
{
|
||||
GenericClickEvent = genericClickEvent;
|
||||
Button = button;
|
||||
}
|
||||
public MiraButtonClickEvent GenericClickEvent { get; } = genericClickEvent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Button click event for <see cref="CustomActionButton"/>s only. Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// Button click event for <see cref="CustomActionButton"/>s only.
|
||||
/// </summary>
|
||||
public sealed class MiraButtonClickEvent : MiraCancelableEvent
|
||||
/// <remarks>
|
||||
/// Do not use for vanilla <see cref="AbilityButton"/>s.
|
||||
/// </remarks>
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> that was clicked.</param>
|
||||
public sealed class MiraButtonClickEvent(CustomActionButton button) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CustomActionButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public CustomActionButton Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraButtonClickEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The <see cref="CustomActionButton"/> that was clicked.</param>
|
||||
public MiraButtonClickEvent(CustomActionButton button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
public CustomActionButton Button { get; } = button;
|
||||
}
|
||||
@@ -5,26 +5,17 @@ namespace MiraAPI.Events;
|
||||
/// <summary>
|
||||
/// Wrapper for <see cref="MiraEvent"/> handlers.
|
||||
/// </summary>
|
||||
public class MiraEventWrapper
|
||||
/// <param name="eventHandler">The action for the event handler.</param>
|
||||
/// <param name="priority">The priority of the handler.</param>
|
||||
public class MiraEventWrapper(Delegate eventHandler, int priority)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the event handler delegate.
|
||||
/// </summary>
|
||||
public Delegate EventHandler { get; }
|
||||
public Delegate EventHandler { get; } = eventHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority of the handler. Lower values are called first.
|
||||
/// </summary>
|
||||
public int Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraEventWrapper"/> class.
|
||||
/// </summary>
|
||||
/// <param name="eventHandler">The action for the event handler.</param>
|
||||
/// <param name="priority">The priority of the handler.</param>
|
||||
public MiraEventWrapper(Delegate eventHandler, int priority)
|
||||
{
|
||||
EventHandler = eventHandler;
|
||||
Priority = priority;
|
||||
}
|
||||
public int Priority { get; } = priority;
|
||||
}
|
||||
@@ -5,20 +5,12 @@ namespace MiraAPI.Events;
|
||||
/// <summary>
|
||||
/// Register a <see cref="MiraEvent"/> handler.
|
||||
/// </summary>
|
||||
/// <param name="priority">The priority of the event. Lower values are called first.</param>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class RegisterEventAttribute : Attribute
|
||||
public class RegisterEventAttribute(int priority = 0) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the priority of the event. Lower values are called first.
|
||||
/// </summary>
|
||||
public int Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RegisterEventAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="priority">The priority of the event. Lower values are called first.</param>
|
||||
public RegisterEventAttribute(int priority = 0)
|
||||
{
|
||||
Priority = priority;
|
||||
}
|
||||
public int Priority { get; } = priority;
|
||||
}
|
||||
@@ -3,33 +3,23 @@
|
||||
/// <summary>
|
||||
/// Event that is invoked after a player is murdered. Only called after a successful murder. This event is not cancelable.
|
||||
/// </summary>
|
||||
public class AfterMurderEvent : MiraEvent
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The killed <see cref="PlayerControl"/>.</param>
|
||||
/// <param name="deadBody">The <paramref name="target"/>'s <see cref="global::DeadBody"/>, if it exists.</param>
|
||||
public class AfterMurderEvent(PlayerControl source, PlayerControl target, DeadBody? deadBody) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PlayerControl"/> that killed the <see cref="Target"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Source { get; }
|
||||
public PlayerControl Source { get; } = source;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PlayerControl"/> that was killed.
|
||||
/// </summary>
|
||||
public PlayerControl Target { get; }
|
||||
public PlayerControl Target { get; } = target;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Target"/>'s <see cref="global::DeadBody"/>, if it exists.
|
||||
/// </summary>
|
||||
public DeadBody? DeadBody { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AfterMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The killer.</param>
|
||||
/// <param name="target">The killed <see cref="PlayerControl"/>.</param>
|
||||
/// <param name="deadBody">The <paramref name="target"/>'s <see cref="global::DeadBody"/>, if it exists.</param>
|
||||
public AfterMurderEvent(PlayerControl source, PlayerControl target, DeadBody? deadBody)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
DeadBody = deadBody;
|
||||
}
|
||||
public DeadBody? DeadBody { get; } = deadBody;
|
||||
}
|
||||
@@ -3,19 +3,11 @@
|
||||
/// <summary>
|
||||
/// Invoked before <see cref="GameManager.RpcEndGame"/> is called, allowing cancellation of the game end entirely.
|
||||
/// </summary>
|
||||
public class BeforeGameEndEvent : MiraCancelableEvent
|
||||
/// <param name="reason">The reason for the game end.</param>
|
||||
public class BeforeGameEndEvent(GameOverReason reason) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the reason for the game end.
|
||||
/// </summary>
|
||||
public GameOverReason Reason { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeGameEndEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="reason">The reason for the game end.</param>
|
||||
public BeforeGameEndEvent(GameOverReason reason)
|
||||
{
|
||||
Reason = reason;
|
||||
}
|
||||
public GameOverReason Reason { get; } = reason;
|
||||
}
|
||||
@@ -5,45 +5,32 @@ namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
/// <summary>
|
||||
/// Event that is invoked before a player is murdered. This event is cancelable.
|
||||
/// </summary>
|
||||
public sealed class BeforeMurderEvent : MiraCancelableEvent
|
||||
/// <param name="source">The <see cref="PlayerControl"/> that is killing the <paramref name="target"/>.</param>
|
||||
/// <param name="target">The <see cref="PlayerControl"/> that is being killed.</param>
|
||||
/// <param name="inMeeting">Whether the murder is intended to be triggered in a meeting.</param>
|
||||
public sealed class BeforeMurderEvent(PlayerControl source, PlayerControl target, MeetingCheck inMeeting) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PlayerControl"/> that is killing the <see cref="Target"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Source { get; }
|
||||
public PlayerControl Source { get; } = source;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PlayerControl"/> that is being killed.
|
||||
/// </summary>
|
||||
public PlayerControl Target { get; }
|
||||
public PlayerControl Target { get; } = target;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the murder was meant to be done in a meeting, via an enum.
|
||||
/// </summary>
|
||||
public MeetingCheck InMeeting { get; }
|
||||
public MeetingCheck InMeeting { get; } = inMeeting;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The <see cref="PlayerControl"/> that is killing the <paramref name="target"/>.</param>
|
||||
/// <param name="target">The <see cref="PlayerControl"/> that is being killed.</param>
|
||||
/// <param name="inMeeting">Whether the murder is intended to be triggered in a meeting.</param>
|
||||
public BeforeMurderEvent(PlayerControl source, PlayerControl target, MeetingCheck inMeeting)
|
||||
public BeforeMurderEvent(PlayerControl source, PlayerControl target) : this(source, target, MeetingCheck.Ignore)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
InMeeting = inMeeting;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeMurderEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="source">The <see cref="PlayerControl"/> that is killing the <paramref name="target"/>.</param>
|
||||
/// <param name="target">The <see cref="PlayerControl"/> that is being killed.</param>
|
||||
public BeforeMurderEvent(PlayerControl source, PlayerControl target)
|
||||
{
|
||||
Source = source;
|
||||
Target = target;
|
||||
InMeeting = MeetingCheck.Ignore;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,13 @@
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// Event invoked on <see cref="IntroCutscene.OnDestroy"/> and <see cref="ExileController.WrapUp"/>
|
||||
/// to determine if it should run the <see cref="RoundStartEvent"/> event or not.
|
||||
/// Event invoked on <see cref="IntroCutscene.OnDestroy"/> and <see cref="ExileController.WrapUp"/> to determine if it should run the <see cref="RoundStartEvent"/> event or not.
|
||||
/// </summary>
|
||||
public class BeforeRoundStartEvent : MiraCancelableEvent
|
||||
/// <param name="triggeredByIntro">Whether the event was triggered by the intro or not.</param>
|
||||
public class BeforeRoundStartEvent(bool triggeredByIntro) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the event was triggered by the <see cref="IntroCutscene"/> or <see cref="ExileController"/>.
|
||||
/// </summary>
|
||||
public bool TriggeredByIntro { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeRoundStartEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="triggeredByIntro">Whether the event was triggered by the intro or not.</param>
|
||||
public BeforeRoundStartEvent(bool triggeredByIntro)
|
||||
{
|
||||
TriggeredByIntro = triggeredByIntro;
|
||||
}
|
||||
public bool TriggeredByIntro { get; } = triggeredByIntro;
|
||||
}
|
||||
@@ -3,19 +3,11 @@
|
||||
/// <summary>
|
||||
/// The event that is invoked when the end game screen is shown. Non cancelable.
|
||||
/// </summary>
|
||||
public class GameEndEvent : MiraEvent
|
||||
/// <param name="manager">The <see cref="global::EndGameManager"/> instance.</param>
|
||||
public class GameEndEvent(EndGameManager manager) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="global::EndGameManager"/> instance.
|
||||
/// </summary>
|
||||
public EndGameManager EndGameManager { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GameEndEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="manager">The <see cref="global::EndGameManager"/> instance.</param>
|
||||
public GameEndEvent(EndGameManager manager)
|
||||
{
|
||||
EndGameManager = manager;
|
||||
}
|
||||
public EndGameManager EndGameManager { get; } = manager;
|
||||
}
|
||||
@@ -3,19 +3,11 @@
|
||||
/// <summary>
|
||||
/// The event that is invoked when the intro cutscene is shown. Non cancelable.
|
||||
/// </summary>
|
||||
public class IntroBeginEvent : MiraEvent
|
||||
/// <param name="introCutscene">The intro cutscene.</param>
|
||||
public class IntroBeginEvent(IntroCutscene introCutscene) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="global::IntroCutscene"/> instance.
|
||||
/// </summary>
|
||||
public IntroCutscene IntroCutscene { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IntroBeginEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="introCutscene">The intro cutscene.</param>
|
||||
public IntroBeginEvent(IntroCutscene introCutscene)
|
||||
{
|
||||
IntroCutscene = introCutscene;
|
||||
}
|
||||
public IntroCutscene IntroCutscene { get; } = introCutscene;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
/// <summary>
|
||||
/// The event that is invoked when the intro cutscene has finished playing.
|
||||
/// </summary>
|
||||
/// <param name="introCutscene">The intro cutscene.</param>
|
||||
public class IntroEndEvent(IntroCutscene introCutscene) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -3,19 +3,11 @@
|
||||
/// <summary>
|
||||
/// The event that is invoked when the player's role is shown on the intro cutscene. Non cancelable.
|
||||
/// </summary>
|
||||
public class IntroRoleRevealEvent : MiraEvent
|
||||
/// <param name="introCutscene">The intro cutscene.</param>
|
||||
public class IntroRoleRevealEvent(IntroCutscene introCutscene) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="global::IntroCutscene"/> instance.
|
||||
/// </summary>
|
||||
public IntroCutscene IntroCutscene { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IntroRoleRevealEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="introCutscene">The intro cutscene.</param>
|
||||
public IntroRoleRevealEvent(IntroCutscene introCutscene)
|
||||
{
|
||||
IntroCutscene = introCutscene;
|
||||
}
|
||||
public IntroCutscene IntroCutscene { get; } = introCutscene;
|
||||
}
|
||||
@@ -4,19 +4,11 @@
|
||||
/// Start Round event, invoked on <see cref="IntroCutscene.OnDestroy"/> and <see cref="ExileController.WrapUp"/>
|
||||
/// if the <see cref="BeforeRoundStartEvent"/> isn't cancelled.
|
||||
/// </summary>
|
||||
public class RoundStartEvent : MiraEvent
|
||||
/// <param name="triggeredByIntro">Whether the event was triggered by the intro or not.</param>
|
||||
public class RoundStartEvent(bool triggeredByIntro) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the event was triggered by the <see cref="IntroCutscene"/> or <see cref="ExileController"/>.
|
||||
/// </summary>
|
||||
public bool TriggeredByIntro { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RoundStartEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="triggeredByIntro">Whether the event was triggered by the intro or not.</param>
|
||||
public RoundStartEvent(bool triggeredByIntro)
|
||||
{
|
||||
TriggeredByIntro = triggeredByIntro;
|
||||
}
|
||||
public bool TriggeredByIntro { get; } = triggeredByIntro;
|
||||
}
|
||||
@@ -5,26 +5,17 @@ namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
/// <summary>
|
||||
/// Event that is invoked after a player's role is set. This event is not cancelable.
|
||||
/// </summary>
|
||||
public class SetRoleEvent : MiraEvent
|
||||
/// <param name="player">The player.</param>
|
||||
/// <param name="role">The new role.</param>
|
||||
public class SetRoleEvent(PlayerControl player, RoleTypes role) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PlayerControl"/> whose role was changed.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
public PlayerControl Player { get; } = player;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the role that the player was set to.
|
||||
/// </summary>
|
||||
public RoleTypes Role { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetRoleEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player.</param>
|
||||
/// <param name="role">The new role.</param>
|
||||
public SetRoleEvent(PlayerControl player, RoleTypes role)
|
||||
{
|
||||
Player = player;
|
||||
Role = role;
|
||||
}
|
||||
public RoleTypes Role { get; } = role;
|
||||
}
|
||||
@@ -6,39 +6,23 @@ namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
/// Invoked when a Vanilla <see cref="AbilityButton"/> click is cancelled. Do not use for <see cref="CustomActionButton"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The vanilla <see cref="AbilityButton"/> type.</typeparam>
|
||||
public sealed class VanillaButtonCancelledEvent<T> : MiraEvent where T : AbilityButton
|
||||
/// <param name="button">The vanilla <see cref="AbilityButton"/> whose click was cancelled.</param>
|
||||
public sealed class VanillaButtonCancelledEvent<T>(T button) : MiraEvent where T : AbilityButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Vanilla <see cref="AbilityButton"/> whose click was cancelled.
|
||||
/// </summary>
|
||||
public T Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VanillaButtonCancelledEvent{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The vanilla <see cref="AbilityButton"/> whose click was cancelled.</param>
|
||||
public VanillaButtonCancelledEvent(T button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
public T Button { get; } = button;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a Vanilla <see cref="AbilityButton"/> click is cancelled. Do not use for <see cref="CustomActionButton"/>s.
|
||||
/// </summary>
|
||||
public sealed class VanillaButtonCancelledEvent : MiraEvent
|
||||
/// <param name="button">The vanilla <see cref="AbilityButton"/> whose click was cancelled.</param>
|
||||
public sealed class VanillaButtonCancelledEvent(AbilityButton button) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Vanilla <see cref="AbilityButton"/> whose click was cancelled.
|
||||
/// </summary>
|
||||
public AbilityButton Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VanillaButtonCancelledEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The vanilla <see cref="AbilityButton"/> whose click was cancelled.</param>
|
||||
public VanillaButtonCancelledEvent(AbilityButton button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
public AbilityButton Button { get; } = button;
|
||||
}
|
||||
@@ -6,60 +6,41 @@ namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
/// Button click event for Vanilla <see cref="AbilityButton"/>s only. Do not use for <see cref="CustomActionButton"/>s.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The vanilla <see cref="AbilityButton"/> type.</typeparam>
|
||||
public sealed class VanillaButtonClickEvent<T> : MiraCancelableEvent where T : AbilityButton
|
||||
/// <param name="button">The vanilla <see cref="AbilityButton"/> that was clicked.</param>
|
||||
/// <param name="genericClickEvent">The generic <see cref="VanillaButtonClickEvent"/> invoked before button-specific events.</param>
|
||||
public sealed class VanillaButtonClickEvent<T>(T button, VanillaButtonClickEvent genericClickEvent) : MiraCancelableEvent where T : AbilityButton
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the vanilla <see cref="AbilityButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public T Button { get; }
|
||||
public T Button { get; } = button;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the generic <see cref="VanillaButtonClickEvent"/> that is invoked before this button-specific event.
|
||||
/// </summary>
|
||||
public VanillaButtonClickEvent GenericClickEvent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VanillaButtonClickEvent{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The vanilla <see cref="AbilityButton"/> that was clicked.</param>
|
||||
/// <param name="genericClickEvent">The generic <see cref="VanillaButtonClickEvent"/> invoked before button-specific events.</param>
|
||||
public VanillaButtonClickEvent(T button, VanillaButtonClickEvent genericClickEvent)
|
||||
{
|
||||
GenericClickEvent = genericClickEvent;
|
||||
Button = button;
|
||||
}
|
||||
public VanillaButtonClickEvent GenericClickEvent { get; } = genericClickEvent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Button click event for Vanilla <see cref="AbilityButton"/> only. Do not use for <see cref="CustomActionButton"/>s.
|
||||
/// </summary>
|
||||
public sealed class VanillaButtonClickEvent : MiraCancelableEvent
|
||||
/// <param name="button">The Vanilla <see cref="AbilityButton"/> that was clicked.</param>
|
||||
/// <param name="playerTarget">The <see cref="PlayerControl"/> target, if any.</param>
|
||||
/// <param name="ventTarget">The <see cref="Vent"/> target, if any.</param>
|
||||
public sealed class VanillaButtonClickEvent(AbilityButton button, PlayerControl? playerTarget = null, Vent? ventTarget = null) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Vanilla <see cref="AbilityButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public AbilityButton Button { get; }
|
||||
public AbilityButton Button { get; } = button;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the target <see cref="PlayerControl"/>, if any, of the Vanilla <see cref="AbilityButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public PlayerControl? PlayerTarget { get; }
|
||||
public PlayerControl? PlayerTarget { get; } = playerTarget;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the target <see cref="Vent"/>, if any, of the Vanilla <see cref="AbilityButton"/> that was clicked.
|
||||
/// </summary>
|
||||
public Vent? VentTarget { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="VanillaButtonClickEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="button">The Vanilla <see cref="AbilityButton"/> that was clicked.</param>
|
||||
/// <param name="playerTarget">The <see cref="PlayerControl"/> target, if any.</param>
|
||||
/// <param name="ventTarget">The <see cref="Vent"/> target, if any.</param>
|
||||
public VanillaButtonClickEvent(AbilityButton button, PlayerControl? playerTarget = null, Vent? ventTarget = null)
|
||||
{
|
||||
Button = button;
|
||||
PlayerTarget = playerTarget;
|
||||
VentTarget = ventTarget;
|
||||
}
|
||||
public Vent? VentTarget { get; } = ventTarget;
|
||||
}
|
||||
@@ -3,19 +3,11 @@
|
||||
/// <summary>
|
||||
/// Event fired when a player closes the doors in a room.
|
||||
/// </summary>
|
||||
public class CloseDoorsEvent : MiraCancelableEvent
|
||||
/// <param name="room">The room that was closed.</param>
|
||||
public class CloseDoorsEvent(SystemTypes room) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the room that the doors were closed in.
|
||||
/// </summary>
|
||||
public SystemTypes Room { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CloseDoorsEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="room">The room that was closed.</param>
|
||||
public CloseDoorsEvent(SystemTypes room)
|
||||
{
|
||||
Room = room;
|
||||
}
|
||||
public SystemTypes Room { get; } = room;
|
||||
}
|
||||
@@ -3,19 +3,11 @@
|
||||
/// <summary>
|
||||
/// Sabotage from Vanilla Among Us.
|
||||
/// </summary>
|
||||
public class PlayerOpenSabotageEvent : MiraCancelableEvent
|
||||
/// <param name="mapBehaviour">The <see cref="global::MapBehaviour"/>.</param>
|
||||
public class PlayerOpenSabotageEvent(MapBehaviour mapBehaviour) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="global::MapBehaviour"/>.
|
||||
/// </summary>
|
||||
public MapBehaviour MapBehaviour { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerOpenSabotageEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mapBehaviour">The <see cref="global::MapBehaviour"/>.</param>
|
||||
public PlayerOpenSabotageEvent(MapBehaviour mapBehaviour)
|
||||
{
|
||||
MapBehaviour = mapBehaviour;
|
||||
}
|
||||
public MapBehaviour MapBehaviour { get; } = mapBehaviour;
|
||||
}
|
||||
@@ -3,33 +3,23 @@
|
||||
/// <summary>
|
||||
/// <see cref="MiraCancelableEvent"/> that is invoked before a system is updated. Usually used for sabotage events.
|
||||
/// </summary>
|
||||
public class UpdateSystemEvent : MiraCancelableEvent
|
||||
/// <param name="systemType">The <see cref="SystemTypes"/> being updated.</param>
|
||||
/// <param name="player">The <see cref="PlayerControl"/> that is updating the system.</param>
|
||||
/// <param name="amount">Amount to update System to.</param>
|
||||
public class UpdateSystemEvent(SystemTypes systemType, PlayerControl player, byte amount) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of system that will be updated.
|
||||
/// </summary>
|
||||
public SystemTypes SystemType { get; }
|
||||
public SystemTypes SystemType { get; } = systemType;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PlayerControl"/> that is updating the system.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
public PlayerControl Player { get; } = player;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the byte amount the system is being updated by.
|
||||
/// </summary>
|
||||
public byte Amount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateSystemEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="systemType">The <see cref="SystemTypes"/> being updated.</param>
|
||||
/// <param name="player">The <see cref="PlayerControl"/> that is updating the system.</param>
|
||||
/// <param name="amount">Amount to update System to.</param>
|
||||
public UpdateSystemEvent(SystemTypes systemType, PlayerControl player, byte amount)
|
||||
{
|
||||
SystemType = systemType;
|
||||
Player = player;
|
||||
Amount = amount;
|
||||
}
|
||||
public byte Amount { get; } = amount;
|
||||
}
|
||||
@@ -3,19 +3,11 @@
|
||||
/// <summary>
|
||||
/// The event that is invoked when a player is ejected. Non-cancelable.
|
||||
/// </summary>
|
||||
public class EjectionEvent : MiraEvent
|
||||
/// <param name="controller">The <see cref="global::ExileController"/> instance.</param>
|
||||
public class EjectionEvent(ExileController controller) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="global::ExileController"/> instance.
|
||||
/// </summary>
|
||||
public ExileController ExileController { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EjectionEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="controller">The <see cref="global::ExileController"/> instance.</param>
|
||||
public EjectionEvent(ExileController controller)
|
||||
{
|
||||
ExileController = controller;
|
||||
}
|
||||
public ExileController ExileController { get; } = controller;
|
||||
}
|
||||
@@ -4,33 +4,23 @@
|
||||
/// The event that is invoked when a body is reported.
|
||||
/// This is invoked in <see cref="PlayerControl.CmdReportDeadBody(NetworkedPlayerInfo)"/>.
|
||||
/// </summary>
|
||||
public class ReportBodyEvent : MiraCancelableEvent
|
||||
/// <param name="reporter">The player who reported the body.</param>
|
||||
/// <param name="target">The player being reported.</param>
|
||||
/// <param name="body">The <see cref="DeadBody"/> being reported.</param>
|
||||
public class ReportBodyEvent(PlayerControl reporter, NetworkedPlayerInfo? target, DeadBody? body) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player that is reporting the body.
|
||||
/// </summary>
|
||||
public PlayerControl Reporter { get; }
|
||||
public PlayerControl Reporter { get; } = reporter;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player that is being reported. Will be <see langword="null"/> for emergency meeting.
|
||||
/// </summary>
|
||||
public NetworkedPlayerInfo? Target { get; }
|
||||
public NetworkedPlayerInfo? Target { get; } = target;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="DeadBody"/> that is being reported. Will be <see langword="null"/> for emergency meeting.
|
||||
/// </summary>
|
||||
public DeadBody? Body { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReportBodyEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="reporter">The player who reported the body.</param>
|
||||
/// <param name="target">The player being reported.</param>
|
||||
/// <param name="body">The <see cref="DeadBody"/> being reported.</param>
|
||||
public ReportBodyEvent(PlayerControl reporter, NetworkedPlayerInfo? target, DeadBody? body)
|
||||
{
|
||||
Reporter = reporter;
|
||||
Target = target;
|
||||
Body = body;
|
||||
}
|
||||
public DeadBody? Body { get; } = body;
|
||||
}
|
||||
@@ -4,19 +4,11 @@
|
||||
/// The event that is invoked when a meeting is called. This event is not cancelable.
|
||||
/// This event is called after Mira resets votes, so if you plan on adding votes to a specific player, do it with this event.
|
||||
/// </summary>
|
||||
public class StartMeetingEvent : MiraEvent
|
||||
/// <param name="meetingHud">The <see cref="global::MeetingHud"/> instance.</param>
|
||||
public class StartMeetingEvent(MeetingHud meetingHud) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="global::MeetingHud"/> instance.
|
||||
/// </summary>
|
||||
public MeetingHud MeetingHud { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StartMeetingEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="meetingHud">The <see cref="global::MeetingHud"/> instance.</param>
|
||||
public StartMeetingEvent(MeetingHud meetingHud)
|
||||
{
|
||||
MeetingHud = meetingHud;
|
||||
}
|
||||
public MeetingHud MeetingHud { get; } = meetingHud;
|
||||
}
|
||||
@@ -3,26 +3,17 @@
|
||||
/// <summary>
|
||||
/// Event that is invoked after the local player successfully votes a player or skips. This event is not cancelable.
|
||||
/// </summary>
|
||||
public class AfterVoteEvent : MiraEvent
|
||||
/// <param name="playerVoteArea">The <see cref="PlayerVoteArea"/> that was voted on.</param>
|
||||
/// <param name="voter">The player who voted.</param>
|
||||
public class AfterVoteEvent(PlayerVoteArea playerVoteArea, PlayerControl voter) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the voter's <see cref="PlayerVoteArea"/>.
|
||||
/// </summary>
|
||||
public PlayerVoteArea VoteArea { get; }
|
||||
public PlayerVoteArea VoteArea { get; } = playerVoteArea;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player who voted.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AfterVoteEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="playerVoteArea">The <see cref="PlayerVoteArea"/> that was voted on.</param>
|
||||
/// <param name="voter">The player who voted.</param>
|
||||
public AfterVoteEvent(PlayerVoteArea playerVoteArea, PlayerControl voter)
|
||||
{
|
||||
VoteArea = playerVoteArea;
|
||||
Player = voter;
|
||||
}
|
||||
public PlayerControl Player { get; } = voter;
|
||||
}
|
||||
@@ -3,26 +3,17 @@
|
||||
/// <summary>
|
||||
/// Event that is invoked before the local player confirms a vote on a player or when skipping. This event is cancelable.
|
||||
/// </summary>
|
||||
public class BeforeVoteEvent : MiraCancelableEvent
|
||||
/// <param name="playerVoteArea">The <see cref="PlayerVoteArea"/> that was voted on.</param>
|
||||
/// <param name="voter">The player who voted.</param>
|
||||
public class BeforeVoteEvent(PlayerVoteArea playerVoteArea, PlayerControl voter) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the voter's <see cref="PlayerVoteArea"/>.
|
||||
/// </summary>
|
||||
public PlayerVoteArea VoteArea { get; }
|
||||
public PlayerVoteArea VoteArea { get; } = playerVoteArea;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player who voted.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BeforeVoteEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="playerVoteArea">The <see cref="PlayerVoteArea"/> that was voted on.</param>
|
||||
/// <param name="voter">The player who voted.</param>
|
||||
public BeforeVoteEvent(PlayerVoteArea playerVoteArea, PlayerControl voter)
|
||||
{
|
||||
VoteArea = playerVoteArea;
|
||||
Player = voter;
|
||||
}
|
||||
public PlayerControl Player { get; } = voter;
|
||||
}
|
||||
@@ -3,24 +3,16 @@
|
||||
/// <summary>
|
||||
/// Checks if voting is complete. If canceled, the default end voting logic will be skipped.
|
||||
/// </summary>
|
||||
public class CheckForEndVotingEvent : MiraCancelableEvent
|
||||
/// <param name="isVotingComplete"><see langword="true"/> if voting is complete, <see langword="false"/> otherwise.</param>
|
||||
public class CheckForEndVotingEvent(bool isVotingComplete) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether default voting logic determines that voting is complete.
|
||||
/// </summary>
|
||||
public bool IsVotingComplete { get; }
|
||||
public bool IsVotingComplete { get; } = isVotingComplete;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the voting should be forced to end, regardless of the default logic.
|
||||
/// </summary>
|
||||
public bool ForceEndVoting { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckForEndVotingEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="isVotingComplete"><see langword="true"/> if voting is complete, <see langword="false"/> otherwise.</param>
|
||||
public CheckForEndVotingEvent(bool isVotingComplete)
|
||||
{
|
||||
IsVotingComplete = isVotingComplete;
|
||||
}
|
||||
}
|
||||
@@ -7,38 +7,27 @@ namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
/// <summary>
|
||||
/// Invoked before the dummy selects their vote. If canceled, the dummy won't vote.
|
||||
/// </summary>
|
||||
public class DummyVoteEvent : MiraCancelableEvent
|
||||
/// <param name="dummy">The voting dummy.</param>
|
||||
public class DummyVoteEvent(DummyBehaviour dummy) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the dummy that needs to vote.
|
||||
/// </summary>
|
||||
public DummyBehaviour Dummy { get; }
|
||||
public DummyBehaviour Dummy { get; } = dummy;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the dummy's <see cref="PlayerVoteData"/>.
|
||||
/// </summary>
|
||||
public PlayerVoteData VoteData { get; }
|
||||
public PlayerVoteData VoteData { get; } = dummy.myPlayer.GetVoteData();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the dummy can vote to skip the meeting.
|
||||
/// </summary>
|
||||
public bool CanSkip { get; set; }
|
||||
public bool CanSkip { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a predicate for validating whether the dummy can vote on a player.
|
||||
/// By default, excludes dead and disconnected players.
|
||||
/// </summary>
|
||||
public Predicate<PlayerControl> PlayerIsValid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DummyVoteEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="dummy">The voting dummy.</param>
|
||||
public DummyVoteEvent(DummyBehaviour dummy)
|
||||
{
|
||||
Dummy = dummy;
|
||||
VoteData = dummy.myPlayer.GetVoteData();
|
||||
CanSkip = true;
|
||||
PlayerIsValid = x => !x.Data.IsDead && !x.Data.Disconnected;
|
||||
}
|
||||
public Predicate<PlayerControl> PlayerIsValid { get; set; } = x => !x.Data.IsDead && !x.Data.Disconnected;
|
||||
}
|
||||
@@ -4,47 +4,37 @@ namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when Mira handles a vote. This is invoked before Mira's behaviour, so be cautious.
|
||||
/// If you intend on adding custom vote behaviour, cancel the event and do so.
|
||||
/// If you are NOT canceling the event, keep in mind that Mira automatically removes a vote and adds the suspect to the <see cref="PlayerVoteData.Votes"/> list after this event is invoked.
|
||||
/// </summary>
|
||||
public class HandleVoteEvent : MiraCancelableEvent
|
||||
/// <remarks>
|
||||
/// If you intend on adding custom vote behaviour, cancel the event and do so.<br/>
|
||||
/// If you are NOT canceling the event, keep in mind that Mira automatically removes a vote and adds the suspect to the <see cref="PlayerVoteData.Votes"/> list after this event is invoked.
|
||||
/// </remarks>
|
||||
/// <param name="playerVoteData">The voter's <see cref="PlayerVoteData"/>.</param>
|
||||
/// <param name="targetId">The target's playerId.</param>
|
||||
public class HandleVoteEvent(PlayerVoteData playerVoteData, byte targetId) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the voter's <see cref="PlayerVoteData"/>.
|
||||
/// </summary>
|
||||
public PlayerVoteData VoteData { get; }
|
||||
public PlayerVoteData VoteData { get; } = playerVoteData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player who voted.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
public PlayerControl Player { get; } = playerVoteData.Owner;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player id of the target.
|
||||
/// </summary>
|
||||
public byte TargetId { get; }
|
||||
public byte TargetId { get; } = targetId;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to prevent the vote from commencing.
|
||||
/// </summary>
|
||||
public bool PreventVote { get; set; }
|
||||
public bool PreventVote { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="NetworkedPlayerInfo"/> of the target.
|
||||
/// </summary>
|
||||
public NetworkedPlayerInfo TargetPlayerInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HandleVoteEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="playerVoteData">The voter's <see cref="PlayerVoteData"/>.</param>
|
||||
/// <param name="targetId">The target's playerId.</param>
|
||||
public HandleVoteEvent(PlayerVoteData playerVoteData, byte targetId)
|
||||
{
|
||||
VoteData = playerVoteData;
|
||||
Player = playerVoteData.Owner;
|
||||
TargetId = targetId;
|
||||
PreventVote = false;
|
||||
TargetPlayerInfo = GameData.Instance.GetPlayerById(targetId);
|
||||
}
|
||||
public NetworkedPlayerInfo TargetPlayerInfo { get; } = GameData.Instance.GetPlayerById(targetId);
|
||||
}
|
||||
@@ -5,39 +5,28 @@ namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
/// <summary>
|
||||
/// The event that is invoked when the player tries to select another player to vote.
|
||||
/// </summary>
|
||||
public class MeetingSelectEvent : MiraEvent
|
||||
/// <param name="playerVoteData">The voter's <see cref="PlayerVoteData"/>.</param>
|
||||
/// <param name="targetId">The target's playerId.</param>
|
||||
/// <param name="allowSelect">Whether the player is allowed to select the target.</param>
|
||||
public class MeetingSelectEvent(PlayerVoteData playerVoteData, int targetId, bool allowSelect) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the voter's <see cref="PlayerVoteData"/>.
|
||||
/// </summary>
|
||||
public PlayerVoteData VoteData { get; }
|
||||
public PlayerVoteData VoteData { get; } = playerVoteData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the player id of the target.
|
||||
/// </summary>
|
||||
public int TargetId { get; }
|
||||
public int TargetId { get; } = targetId;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="NetworkedPlayerInfo"/> of the target.
|
||||
/// </summary>
|
||||
public NetworkedPlayerInfo TargetPlayerInfo { get; }
|
||||
public NetworkedPlayerInfo TargetPlayerInfo { get; } = GameData.Instance.GetPlayerById((byte)targetId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the player is allowed to select the target.
|
||||
/// </summary>
|
||||
public bool AllowSelect { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MeetingSelectEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="playerVoteData">The voter's <see cref="PlayerVoteData"/>.</param>
|
||||
/// <param name="targetId">The target's playerId.</param>
|
||||
/// <param name="allowSelect">Whether the player is allowed to select the target.</param>
|
||||
public MeetingSelectEvent(PlayerVoteData playerVoteData, int targetId, bool allowSelect)
|
||||
{
|
||||
VoteData = playerVoteData;
|
||||
TargetId = targetId;
|
||||
TargetPlayerInfo = GameData.Instance.GetPlayerById((byte)targetId);
|
||||
AllowSelect = allowSelect;
|
||||
}
|
||||
public bool AllowSelect { get; set; } = allowSelect;
|
||||
}
|
||||
@@ -5,21 +5,15 @@ namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
|
||||
/// <summary>
|
||||
/// Called in <see cref="VotingUtils.HandlePopulateResults"/>.
|
||||
/// Cancelling is NOT advised but if you do plan on cancelling, please ensure you account for displaying ALL player's votes.
|
||||
/// </summary>
|
||||
public class PopulateResultsEvent : MiraCancelableEvent
|
||||
/// <remarks>
|
||||
/// Cancelling is NOT advised but if you do plan on cancelling, please ensure you account for displaying ALL player's votes.
|
||||
/// </remarks>
|
||||
/// <param name="votes">The list of <see cref="CustomVote"/>s.</param>
|
||||
public class PopulateResultsEvent(List<CustomVote> votes) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a list of networked <see cref="CustomVote"/>s.
|
||||
/// </summary>
|
||||
public List<CustomVote> Votes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PopulateResultsEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="votes">The list of <see cref="CustomVote"/>s.</param>
|
||||
public PopulateResultsEvent(List<CustomVote> votes)
|
||||
{
|
||||
Votes = votes;
|
||||
}
|
||||
public List<CustomVote> Votes { get; } = votes;
|
||||
}
|
||||
@@ -7,9 +7,6 @@ namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
/// <summary>
|
||||
/// Ran after calculating votes and before displaying the results. Only ran on the host.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Initializes a new instance of the <see cref="ProcessVotesEvent"/> class.
|
||||
/// </remarks>
|
||||
/// <param name="votes">The list of <see cref="CustomVote"/>s that are being processed.</param>
|
||||
/// <param name="exiledPlayer">The player to be exiled. Will be <see langword="null"/> if no player is to be exiled.</param>
|
||||
public class ProcessVotesEvent(List<CustomVote> votes, NetworkedPlayerInfo? exiledPlayer = null) : MiraEvent
|
||||
|
||||
@@ -3,33 +3,23 @@
|
||||
/// <summary>
|
||||
/// The event that is invoked when a player completes a task within Hide and Seek. Non-cancelable.
|
||||
/// </summary>
|
||||
public class CompleteHnsTaskEvent : MiraEvent
|
||||
/// <param name="hnsManager">The <see cref="HideAndSeekManager"/> currently active.</param>
|
||||
/// <param name="player">The player who completed the task.</param>
|
||||
/// <param name="task">The task that the player completed.</param>
|
||||
public class CompleteHnsTaskEvent(HideAndSeekManager hnsManager, PlayerControl player, PlayerTask task) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="PlayerControl"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
public PlayerControl Player { get; } = player;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="PlayerTask"/> that the player completed.
|
||||
/// </summary>
|
||||
public PlayerTask Task { get; }
|
||||
public PlayerTask Task { get; } = task;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="HideAndSeekManager"/> attached to the game.
|
||||
/// </summary>
|
||||
public HideAndSeekManager HnsManager { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CompleteHnsTaskEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="hnsManager">The <see cref="HideAndSeekManager"/> currently active.</param>
|
||||
/// <param name="player">The player who completed the task.</param>
|
||||
/// <param name="task">The task that the player completed.</param>
|
||||
public CompleteHnsTaskEvent(HideAndSeekManager hnsManager, PlayerControl player, PlayerTask task)
|
||||
{
|
||||
HnsManager = hnsManager;
|
||||
Player = player;
|
||||
Task = task;
|
||||
}
|
||||
public HideAndSeekManager HnsManager { get; } = hnsManager;
|
||||
}
|
||||
@@ -3,26 +3,17 @@
|
||||
/// <summary>
|
||||
/// The event that is invoked when a player completes a task. Non cancelable.
|
||||
/// </summary>
|
||||
public class CompleteTaskEvent : MiraEvent
|
||||
/// <param name="player">The player who completed the task.</param>
|
||||
/// <param name="task">The task that the player completed.</param>
|
||||
public class CompleteTaskEvent(PlayerControl player, PlayerTask task) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="PlayerControl"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
public PlayerControl Player { get; } = player;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="PlayerTask"/> that the player completed.
|
||||
/// </summary>
|
||||
public PlayerTask Task { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CompleteTaskEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player who completed the task.</param>
|
||||
/// <param name="task">The task that the player completed.</param>
|
||||
public CompleteTaskEvent(PlayerControl player, PlayerTask task)
|
||||
{
|
||||
Player = player;
|
||||
Task = task;
|
||||
}
|
||||
public PlayerTask Task { get; } = task;
|
||||
}
|
||||
@@ -3,33 +3,23 @@
|
||||
/// <summary>
|
||||
/// Event that is invoked when a player dies. Non cancelable.
|
||||
/// </summary>
|
||||
public class PlayerDeathEvent : MiraEvent
|
||||
/// <param name="player">The player who died.</param>
|
||||
/// <param name="reason">The reason the player died.</param>
|
||||
/// <param name="deadBody">The player's <see cref="global::DeadBody"/>, if it exists.</param>
|
||||
public class PlayerDeathEvent(PlayerControl player, DeathReason reason, DeadBody? deadBody) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player who died.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
public PlayerControl Player { get; } = player;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reason the player died.
|
||||
/// </summary>
|
||||
public DeathReason DeathReason { get; }
|
||||
public DeathReason DeathReason { get; } = reason;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="global::DeadBody"/> associated with the player, if any.
|
||||
/// </summary>
|
||||
public DeadBody? DeadBody { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerDeathEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player who died.</param>
|
||||
/// <param name="reason">The reason the player died.</param>
|
||||
/// <param name="deadBody">The player's <see cref="global::DeadBody"/>, if it exists.</param>
|
||||
public PlayerDeathEvent(PlayerControl player, DeathReason reason, DeadBody? deadBody)
|
||||
{
|
||||
Player = player;
|
||||
DeathReason = reason;
|
||||
DeadBody = deadBody;
|
||||
}
|
||||
public DeadBody? DeadBody { get; } = deadBody;
|
||||
}
|
||||
@@ -5,19 +5,11 @@ namespace MiraAPI.Events.Vanilla.Player;
|
||||
/// <summary>
|
||||
/// Event that is invoked when a player joins the lobby. Non cancelable.
|
||||
/// </summary>
|
||||
public class PlayerJoinEvent : MiraEvent
|
||||
/// <param name="data">The data of the player who joined.</param>
|
||||
public class PlayerJoinEvent(ClientData data) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player who joined.
|
||||
/// </summary>
|
||||
public ClientData ClientData { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerJoinEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="data">The data of the player who joined.</param>
|
||||
public PlayerJoinEvent(ClientData data)
|
||||
{
|
||||
ClientData = data;
|
||||
}
|
||||
public ClientData ClientData { get; } = data;
|
||||
}
|
||||
@@ -5,26 +5,17 @@ namespace MiraAPI.Events.Vanilla.Player;
|
||||
/// <summary>
|
||||
/// Event that is invoked when a player leaves the game. Non cancelable.
|
||||
/// </summary>
|
||||
public class PlayerLeaveEvent : MiraEvent
|
||||
/// <param name="data">The data of the player who left.</param>
|
||||
/// <param name="reason">The reason why the player left.</param>
|
||||
public class PlayerLeaveEvent(ClientData data, DisconnectReasons reason) : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player who left.
|
||||
/// </summary>
|
||||
public ClientData ClientData { get; }
|
||||
public ClientData ClientData { get; } = data;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reason why the player left.
|
||||
/// </summary>
|
||||
public DisconnectReasons Reason { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerLeaveEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="data">The data of the player who left.</param>
|
||||
/// <param name="reason">The reason why the player left.</param>
|
||||
public PlayerLeaveEvent(ClientData data, DisconnectReasons reason)
|
||||
{
|
||||
ClientData = data;
|
||||
Reason = reason;
|
||||
}
|
||||
public DisconnectReasons Reason { get; } = reason;
|
||||
}
|
||||
@@ -3,26 +3,17 @@
|
||||
/// <summary>
|
||||
/// Event that is invoked when a player enters a vent. This event is cancelable.
|
||||
/// </summary>
|
||||
public class EnterVentEvent : MiraCancelableEvent
|
||||
/// <param name="player">The <see cref="PlayerControl"/> that is entering the <paramref name="vent"/>.</param>
|
||||
/// <param name="vent">The <see cref="global::Vent"/> being entered.</param>
|
||||
public class EnterVentEvent(PlayerControl player, Vent? vent) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PlayerControl"/> that is entering the <see cref="Vent"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
public PlayerControl Player { get; } = player;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="global::Vent"/> that the <see cref="Player"/> is entering.
|
||||
/// </summary>
|
||||
public Vent? Vent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnterVentEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The <see cref="PlayerControl"/> that is entering the <paramref name="vent"/>.</param>
|
||||
/// <param name="vent">The <see cref="global::Vent"/> being entered.</param>
|
||||
public EnterVentEvent(PlayerControl player, Vent? vent)
|
||||
{
|
||||
Player = player;
|
||||
Vent = vent;
|
||||
}
|
||||
public Vent? Vent { get; } = vent;
|
||||
}
|
||||
@@ -3,26 +3,17 @@
|
||||
/// <summary>
|
||||
/// Event that is invoked when a player exits a vent. This event is cancelable.
|
||||
/// </summary>
|
||||
public class ExitVentEvent : MiraCancelableEvent
|
||||
/// <param name="player">The <see cref="PlayerControl"/> who is exiting the <paramref name="vent"/>.</param>
|
||||
/// <param name="vent">The <see cref="global::Vent"/> being exited from.</param>
|
||||
public class ExitVentEvent(PlayerControl player, Vent? vent) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="PlayerControl"/> that is exiting the <see cref="Vent"/>.
|
||||
/// </summary>
|
||||
public PlayerControl Player { get; }
|
||||
public PlayerControl Player { get; } = player;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="global::Vent"/> that the <see cref="Player"/> is exiting.
|
||||
/// </summary>
|
||||
public Vent? Vent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ExitVentEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The <see cref="PlayerControl"/> who is exiting the <paramref name="vent"/>.</param>
|
||||
/// <param name="vent">The <see cref="global::Vent"/> being exited from.</param>
|
||||
public ExitVentEvent(PlayerControl player, Vent? vent)
|
||||
{
|
||||
Player = player;
|
||||
Vent = vent;
|
||||
}
|
||||
public Vent? Vent { get; } = vent;
|
||||
}
|
||||
@@ -3,13 +3,5 @@
|
||||
/// <summary>
|
||||
/// Event for if a <see cref="PlayerControl"/> can use an <see cref="IUsable"/> from Vanilla Among Us. Will always be ran locally.
|
||||
/// </summary>
|
||||
public class PlayerCanUseEvent : PlayerUseEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerCanUseEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="usable">The <see cref="IUsable"/>.</param>
|
||||
public PlayerCanUseEvent(IUsable usable) : base(usable)
|
||||
{
|
||||
}
|
||||
}
|
||||
/// <param name="usable">The <see cref="IUsable"/>.</param>
|
||||
public class PlayerCanUseEvent(IUsable usable) : PlayerUseEvent(usable);
|
||||
@@ -3,32 +3,21 @@
|
||||
/// <summary>
|
||||
/// Event for <see cref="PlayerControl"/> using a <see cref="IUsable"/> from Vanilla Among Us. Will always be ran locally.
|
||||
/// </summary>
|
||||
public class PlayerUseEvent : MiraCancelableEvent
|
||||
/// <param name="usable">The <see cref="IUsable"/>.</param>
|
||||
public class PlayerUseEvent(IUsable usable) : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of <see cref="IUsable"/> that was used.
|
||||
/// </summary>
|
||||
public IUsable Usable { get; }
|
||||
public IUsable Usable { get; } = usable;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the <see cref="Usable"/> is a <see cref="Console"/>, <see cref="MapConsole"/>, or <see cref="SystemConsole"/>.
|
||||
/// </summary>
|
||||
public bool IsPrimaryConsole { get; }
|
||||
public bool IsPrimaryConsole { get; } = usable.TryCast<Console>() || usable.TryCast<SystemConsole>() || usable.TryCast<MapConsole>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the <see cref="Usable"/> is a <see cref="Vent"/>.
|
||||
/// </summary>
|
||||
public bool IsVent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlayerUseEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="usable">The <see cref="IUsable"/>.</param>
|
||||
public PlayerUseEvent(IUsable usable)
|
||||
{
|
||||
Usable = usable;
|
||||
|
||||
IsPrimaryConsole = usable.TryCast<Console>() || usable.TryCast<SystemConsole>() || usable.TryCast<MapConsole>();
|
||||
IsVent = usable.TryCast<Vent>();
|
||||
}
|
||||
public bool IsVent { get; } = usable.TryCast<Vent>();
|
||||
}
|
||||
@@ -81,9 +81,8 @@ public static class GameOverManager
|
||||
/// <exception cref="ArgumentException">Thrown when the type is not registered.</exception>
|
||||
public static int GetGameOverId(Type gameOverType)
|
||||
{
|
||||
if (GameOverIds.TryGetValue(gameOverType, out var id))
|
||||
return id;
|
||||
|
||||
throw new ArgumentException($"{gameOverType.FullName} is not a registered custom game over!");
|
||||
return GameOverIds.TryGetValue(gameOverType, out var id)
|
||||
? id
|
||||
: throw new ArgumentException($"{gameOverType.FullName} is not a registered custom game over!");
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
[*.cs]
|
||||
dotnet_diagnostic.CS1591.severity = none
|
||||
|
||||
# CS1591: Missing XML comment for publicly visible type or member.
|
||||
# dotnet_diagnostic.CS1591.severity = none
|
||||
@@ -89,60 +89,87 @@ public abstract class CustomGameMode
|
||||
/// Should Roles Settings be available when this gamemode is selected.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if Role Settings are enabled in this game mode.</returns>
|
||||
public virtual bool AreRoleSettingsEnabled() => true;
|
||||
public virtual bool AreRoleSettingsEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Should Game Settings be available when this gamemode is selected.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if Game Settings are enabled in this mode.</returns>
|
||||
public virtual bool AreGameSettingsEnabled() => true;
|
||||
public virtual bool AreGameSettingsEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom winner selection.
|
||||
/// </summary>
|
||||
/// <returns>List of winners or <see langword="null"/>.</returns>
|
||||
public virtual List<NetworkedPlayerInfo>? CalculateWinners() => null;
|
||||
public virtual List<NetworkedPlayerInfo>? CalculateWinners()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show gamemode in <see cref="IntroCutscene"/>.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if the game mode should be shown in the intro cutscene.</returns>
|
||||
public virtual bool ShowGameModeIntroCutscene() => false;
|
||||
public virtual bool ShowGameModeIntroCutscene()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can Admin be used in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">Admin Console.</param>
|
||||
/// <returns><see langword="true"/> if Admin console is enabled.</returns>
|
||||
public virtual bool CanUseMapConsole(MapConsole console) => true;
|
||||
public virtual bool CanUseMapConsole(MapConsole console)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can a <see cref="DeadBody"/> be reported in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="body">Target <see cref="DeadBody"/> for reporting.</param>
|
||||
/// <returns><see langword="true"/> if <see cref="DeadBody"/>s can be reported.</returns>
|
||||
public virtual bool CanReport(DeadBody body) => true;
|
||||
public virtual bool CanReport(DeadBody body)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can <see cref="SystemConsole"/>s be used in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">System Console.</param>
|
||||
/// <returns><see langword="true"/> if <see cref="SystemConsole"/>s are enabled in this mode.</returns>
|
||||
public virtual bool CanUseSystemConsole(SystemConsole console) => true;
|
||||
public virtual bool CanUseSystemConsole(SystemConsole console)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can tasks be interacted with in this gamemode.
|
||||
/// </summary>
|
||||
/// <param name="console">Task console.</param>
|
||||
/// <returns><see langword="true"/> if tasks are enabled in this mode.</returns>
|
||||
public virtual bool CanUseTasks(Console console) => true;
|
||||
public virtual bool CanUseTasks(Console console)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Should the sabotage map be used when attempting to open sabotage overlay.
|
||||
/// </summary>
|
||||
/// <param name="map"><see cref="MapBehaviour"/> object.</param>
|
||||
/// <returns><see langword="true"/> if the sabotage map should be shown.</returns>
|
||||
public virtual bool ShouldShowSabotageMap(MapBehaviour map) => true;
|
||||
public virtual bool ShouldShowSabotageMap(MapBehaviour map)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can a player vent in this gamemode.
|
||||
@@ -150,5 +177,8 @@ public abstract class CustomGameMode
|
||||
/// <param name="vent">Target vent.</param>
|
||||
/// <param name="playerInfo">Player attempting to vent.</param>
|
||||
/// <returns><see langword="true"/> if venting is enabled in this mode.</returns>
|
||||
public virtual bool CanVent(Vent vent, NetworkedPlayerInfo playerInfo) => true;
|
||||
public virtual bool CanVent(Vent vent, NetworkedPlayerInfo playerInfo)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,10 @@ public static class CustomGameModeManager
|
||||
/// </summary>
|
||||
internal static readonly Dictionary<int, CustomGameMode> GameModes = [];
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if the currently selected gamemode is vanilla.
|
||||
/// </summary>
|
||||
/// <returns>true if there is no custom gamemode selected.</returns>
|
||||
public static bool IsDefault()
|
||||
{
|
||||
return ActiveMode?.Id == 0;
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
namespace MiraAPI.GameModes;
|
||||
|
||||
/// <summary>
|
||||
/// The default gamemode of Among Us.
|
||||
/// </summary>
|
||||
public class DefaultMode : CustomGameMode
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public override string Name => "Default";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string Description => "Default Among Us GameMode";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int Id => 0;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.Roles;
|
||||
@@ -33,10 +34,9 @@ public abstract class AbstractOptionGroup
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the group should be shown in the modifiers menu.
|
||||
/// </summary>
|
||||
// TODO: make this not a boolean
|
||||
#pragma warning disable S1133
|
||||
// Completed: make this not a boolean
|
||||
[Obsolete("Use ParentMenu instead.")]
|
||||
#pragma warning restore S1133
|
||||
[SuppressMessage("Info Code Smell", "S1133:Deprecated code should be removed", Justification = "Retained.")]
|
||||
public virtual bool ShowInModifiersMenu => false;
|
||||
|
||||
/// <summary>
|
||||
@@ -118,11 +118,9 @@ public abstract class AbstractRoleOptionGroup<T>() : AbstractOptionGroup<T> wher
|
||||
get
|
||||
{
|
||||
var role = CustomRoleManager.CustomMiraRoles.FirstOrDefault(x => x.GetType() == OptionableType);
|
||||
if (role == null)
|
||||
{
|
||||
return new(new Color(0.7333f, 0.7333f, 0.7333f, 1));
|
||||
}
|
||||
return new(role.RoleColor, role.Configuration.IconTmp);
|
||||
return role == null
|
||||
? new(new Color(0.7333f, 0.7333f, 0.7333f, 1))
|
||||
: new(role.RoleColor, role.Configuration.IconTmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +131,7 @@ public abstract class AbstractRoleOptionGroup<T>() : AbstractOptionGroup<T> wher
|
||||
public enum MenuCategory
|
||||
{
|
||||
/// <summary>
|
||||
/// Placeholder for indexing purposes. Options don't exist in the presset tab.
|
||||
/// Placeholder for indexing purposes. Options don't exist in the preset tab.
|
||||
/// </summary>
|
||||
Preset,
|
||||
|
||||
|
||||
@@ -42,10 +42,8 @@ public class ModdedNumberOptionAttribute(
|
||||
/// <inheritdoc />
|
||||
public override object GetValue()
|
||||
{
|
||||
if (HolderOption is ModdedNumberOption opt)
|
||||
{
|
||||
return opt.Value;
|
||||
}
|
||||
throw new InvalidOperationException($"HolderOption for option \"{Title}\" is not a ModdedNumberOption");
|
||||
return HolderOption is ModdedNumberOption opt
|
||||
? (object)opt.Value
|
||||
: throw new InvalidOperationException($"HolderOption for option \"{Title}\" is not a ModdedNumberOption");
|
||||
}
|
||||
}
|
||||
@@ -27,10 +27,8 @@ public class ModdedToggleOptionAttribute(string title) : ModdedOptionAttribute(t
|
||||
/// <inheritdoc />
|
||||
public override object GetValue()
|
||||
{
|
||||
if (HolderOption is ModdedToggleOption opt)
|
||||
{
|
||||
return opt.Value;
|
||||
}
|
||||
throw new InvalidOperationException($"Holder option for {Title} is not a ModdedToggleOption.");
|
||||
return HolderOption is ModdedToggleOption opt
|
||||
? (object)opt.Value
|
||||
: throw new InvalidOperationException($"Holder option for {Title} is not a ModdedToggleOption.");
|
||||
}
|
||||
}
|
||||
@@ -32,13 +32,21 @@ public static class ModdedOptionsManager
|
||||
internal static uint NextId => _nextId++;
|
||||
private static uint _nextId = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Pops a message notification of a setting being changed.
|
||||
/// </summary>
|
||||
/// <param name="notif">The game's notification popper.</param>
|
||||
/// <param name="key">The <see cref="StringNames"/> key of the option that changed.</param>
|
||||
/// <param name="value">The new value of the option.</param>
|
||||
/// <param name="textColor">The color of the notification.</param>
|
||||
/// <param name="sprite">The optional sprite of the notification.</param>
|
||||
/// <param name="playSound">A flag that indicates if a notification sound should be played.</param>
|
||||
public static void AddSettingsChangeMessage(NotificationPopper notif, StringNames key, string value, Color textColor, TMP_SpriteAsset? sprite, bool playSound = true)
|
||||
{
|
||||
var item = string.Empty;
|
||||
string item;
|
||||
var text = textColor.ToTextColor();
|
||||
if (sprite != null)
|
||||
{
|
||||
item = TranslationController.Instance.GetString(
|
||||
item = sprite != null
|
||||
? TranslationController.Instance.GetString(
|
||||
StringNames.LobbyChangeSettingNotification,
|
||||
string.Concat(
|
||||
"<sprite name=\"",
|
||||
@@ -48,20 +56,21 @@ public static class ModdedOptionsManager
|
||||
TranslationController.Instance.GetString(key),
|
||||
"</color></font>"),
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + value + "</font>"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
item = TranslationController.Instance.GetString(
|
||||
)
|
||||
: TranslationController.Instance.GetString(
|
||||
StringNames.LobbyChangeSettingNotification,
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" +
|
||||
text +
|
||||
TranslationController.Instance.GetString(key) + "</color></font>",
|
||||
"<font=\"Barlow-Black SDF\" material=\"Barlow-Black Outline\">" + value + "</font>");
|
||||
}
|
||||
notif.SettingsChangeMessageLogic(key, item, playSound);
|
||||
}
|
||||
|
||||
[SuppressMessage(
|
||||
"Major Code Smell",
|
||||
"S3011:Reflection should not be used to increase accessibility of classes, methods, or fields",
|
||||
Justification = "Dynamic singleton initialization requires reflection to bypass the private field access modifier because the type is only known at runtime."
|
||||
)]
|
||||
internal static bool RegisterGroup(Type type, MiraPluginInfo pluginInfo)
|
||||
{
|
||||
if (Activator.CreateInstance(type) is not AbstractOptionGroup group)
|
||||
@@ -80,9 +89,7 @@ public static class ModdedOptionsManager
|
||||
pluginInfo.InternalOptionGroups.Add(group);
|
||||
|
||||
typeof(OptionGroupSingleton<>).MakeGenericType(type)
|
||||
#pragma warning disable S3011
|
||||
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!
|
||||
#pragma warning restore S3011
|
||||
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)! // Message suppression points to here
|
||||
.SetValue(null, group);
|
||||
|
||||
return true;
|
||||
@@ -211,10 +218,9 @@ public static class ModdedOptionsManager
|
||||
/// </summary>
|
||||
/// <param name="__originalMethod">The original setter method.</param>
|
||||
/// <param name="value">The new object value.</param>
|
||||
#pragma warning disable CA1707
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony naming convention")]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony naming convention.")]
|
||||
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Harmony naming convention.")]
|
||||
public static void PropertySetterPatch(MethodBase __originalMethod, object value)
|
||||
#pragma warning restore CA1707
|
||||
{
|
||||
var attribute = OptionAttributes.First(pair => pair.Key.GetSetMethod() == __originalMethod).Value;
|
||||
attribute.SetValue(value);
|
||||
@@ -226,10 +232,9 @@ public static class ModdedOptionsManager
|
||||
/// <param name="__originalMethod">The original getter method.</param>
|
||||
/// <param name="__result">The result of the property getter.</param>
|
||||
/// <returns><see langword="false"/> so the original getter gets skipped.</returns>
|
||||
#pragma warning disable CA1707
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Harmony naming convention")]
|
||||
[SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Harmony naming convention.")]
|
||||
public static bool PropertyGetterPatch(MethodBase __originalMethod, ref object __result)
|
||||
#pragma warning restore CA1707
|
||||
{
|
||||
var attribute = OptionAttributes.First(pair => pair.Key.GetGetMethod() == __originalMethod).Value;
|
||||
__result = attribute.GetValue();
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
#pragma warning disable CA1852
|
||||
internal class ModifierOptionGroup : AbstractOptionGroup
|
||||
#pragma warning restore CA1852
|
||||
internal sealed class ModifierOptionGroup : AbstractOptionGroup
|
||||
{
|
||||
public override string GroupName { get; }
|
||||
|
||||
@@ -12,6 +10,6 @@ internal class ModifierOptionGroup : AbstractOptionGroup
|
||||
{
|
||||
GroupName = name;
|
||||
Options.AddRange(options);
|
||||
Options.AddRange(groups.SelectMany(x=>x.Options));
|
||||
Options.AddRange(groups.SelectMany(x => x.Options));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
@@ -13,7 +14,6 @@ public static class OptionGroupSingleton<T> where T : AbstractOptionGroup
|
||||
/// <summary>
|
||||
/// Gets the instance of the <typeparamref name="T"/> group.
|
||||
/// </summary>
|
||||
#pragma warning disable CA1000
|
||||
[SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "This is a utility class to get the instance of a custom option group.")]
|
||||
public static T Instance => _instance ??= ModdedOptionsManager.Groups.OfType<T>().Single();
|
||||
#pragma warning restore CA1000
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.GameOptions;
|
||||
|
||||
/// <summary>
|
||||
@@ -9,14 +11,13 @@ namespace MiraAPI.GameOptions;
|
||||
/// </summary>
|
||||
public record struct OptionNotifConfiguration
|
||||
{
|
||||
#pragma warning disable S1133
|
||||
[Obsolete("Default constructor is not supported")]
|
||||
#pragma warning restore S1133
|
||||
[Obsolete("Default constructor is not supported. Please use the constructor that takes an AbstractOptionGroup parameter.")]
|
||||
[SuppressMessage("Info Code Smell", "S1133:Deprecated code should be removed", Justification = "Will not be removed, as this throws instead.")]
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
public OptionNotifConfiguration()
|
||||
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
|
||||
{
|
||||
throw new NotImplementedException("Default constructor is not supported.");
|
||||
throw new NotImplementedException("Default constructor is not supported. Please use the constructor that takes an AbstractOptionGroup parameter.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -28,19 +28,17 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
/// <param name="enumType">The <see cref="Enum"/> type.</param>
|
||||
/// <param name="values">An option list of string values to use in place of the <see langword="enum"/> name.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public ModdedEnumOption(string title, int defaultValue, Type enumType, string[]? values = null, bool includeInPreset=true) : base(title, defaultValue, includeInPreset)
|
||||
public ModdedEnumOption(string title, int defaultValue, Type enumType, string[]? values = null, bool includeInPreset = true) : base(title, defaultValue, includeInPreset)
|
||||
{
|
||||
Values = values ?? Enum.GetNames(enumType);
|
||||
Data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
var data = (StringGameSetting)Data;
|
||||
|
||||
var data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.String;
|
||||
data.Values = values is null ?
|
||||
Enum.GetNames(enumType).Select(CustomStringName.CreateAndRegister).ToArray()
|
||||
: [.. values.Select(CustomStringName.CreateAndRegister)];
|
||||
|
||||
data.Values = Values.Select(CustomStringName.CreateAndRegister).ToArray();
|
||||
data.Index = Value;
|
||||
|
||||
Data = data;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -53,7 +51,7 @@ public class ModdedEnumOption : ModdedOption<int>
|
||||
stringOption.SetUpFromData(Data, 20);
|
||||
stringOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
// SetUpFromData method doesnt work correctly so we must set the values manually
|
||||
// SetUpFromData method doesn't work correctly so we must set the values manually
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Values = (Data as StringGameSetting)?.Values ?? new Il2CppStructArray<StringNames>(0);
|
||||
stringOption.Value = Value;
|
||||
@@ -127,19 +125,17 @@ public class ModdedEnumOption<T> : ModdedOption<T> where T : Enum
|
||||
/// <param name="defaultValue">The default value as an <see langword="int"/>.</param>
|
||||
/// <param name="values">An option list of string values to use in place of the <see langword="enum"/> name.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public ModdedEnumOption(string title, T defaultValue, string[]? values = null, bool includeInPreset=true) : base(title, defaultValue, includeInPreset)
|
||||
public ModdedEnumOption(string title, T defaultValue, string[]? values = null, bool includeInPreset = true) : base(title, defaultValue, includeInPreset)
|
||||
{
|
||||
Values = values ?? Enum.GetNames(typeof(T));
|
||||
Data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
var data = (StringGameSetting)Data;
|
||||
|
||||
var data = ScriptableObject.CreateInstance<StringGameSetting>();
|
||||
data.Title = StringName;
|
||||
data.Type = global::OptionTypes.String;
|
||||
data.Values = values is null ?
|
||||
Enum.GetNames(typeof(T)).Select(CustomStringName.CreateAndRegister).ToArray()
|
||||
: [.. values.Select(CustomStringName.CreateAndRegister)];
|
||||
|
||||
data.Values = Values.Select(CustomStringName.CreateAndRegister).ToArray();
|
||||
data.Index = Convert.ToInt32(Value, NumberFormatInfo.InvariantInfo);
|
||||
|
||||
Data = data;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -152,7 +148,7 @@ public class ModdedEnumOption<T> : ModdedOption<T> where T : Enum
|
||||
stringOption.SetUpFromData(Data, 20);
|
||||
stringOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
// SetUpFromData method doesnt work correctly so we must set the values manually
|
||||
// SetUpFromData method doesn't work correctly so we must set the values manually
|
||||
stringOption.Title = StringName;
|
||||
stringOption.Values = (Data as StringGameSetting)?.Values ?? new Il2CppStructArray<StringNames>(0);
|
||||
stringOption.Value = Convert.ToInt32(Value, NumberFormatInfo.InvariantInfo);
|
||||
|
||||
@@ -138,7 +138,7 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
SuffixType = suffixType;
|
||||
ZeroWordValue = zeroInfinity ? "∞" : "#";
|
||||
NegativeWordValue = "#";
|
||||
ShiftIncrement = increment != 1f;
|
||||
ShiftIncrement = Mathf.Approximately(increment, 1f);
|
||||
|
||||
Value = Mathf.Clamp(defaultValue, min, max);
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ public abstract class ModdedOption<T> : IModdedOption
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SaveToPreset(ConfigFile presetConfig, bool saveDefault=false)
|
||||
public void SaveToPreset(ConfigFile presetConfig, bool saveDefault = false)
|
||||
{
|
||||
if (ConfigDefinition is null)
|
||||
{
|
||||
|
||||
@@ -85,9 +85,7 @@ public class ModdedPlayerOption : ModdedOption<int>
|
||||
/// <returns>A list of filtered players.</returns>
|
||||
public System.Collections.Generic.List<NetworkedPlayerInfo> GetFilteredPlayers()
|
||||
{
|
||||
return GameData.Instance.AllPlayers.ToArray()
|
||||
.Where(x => PlayerFilter?.Invoke(x) ?? true)
|
||||
.ToList();
|
||||
return [.. GameData.Instance.AllPlayers.ToArray().Where(x => PlayerFilter?.Invoke(x) ?? true)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ModdedToggleOption : ModdedOption<bool>
|
||||
/// <param name="title">The option title.</param>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
/// <param name="includeInPreset">Whether to include this option in the preset or not.</param>
|
||||
public ModdedToggleOption(string title, bool defaultValue, bool includeInPreset=true) : base(title, defaultValue, includeInPreset)
|
||||
public ModdedToggleOption(string title, bool defaultValue, bool includeInPreset = true) : base(title, defaultValue, includeInPreset)
|
||||
{
|
||||
Data = ScriptableObject.CreateInstance<CheckboxGameSetting>();
|
||||
|
||||
|
||||
@@ -447,7 +447,10 @@ public abstract class CustomActionButton
|
||||
/// Always <see langword="false"/> by default.
|
||||
/// </summary>
|
||||
/// <returns>Can the effect be canceled.</returns>
|
||||
public virtual bool IsEffectCancellable() => false;
|
||||
public virtual bool IsEffectCancellable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When the button is usable, this method is called to determine if the button can be clicked.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
using MiraAPI.Events.Mira;
|
||||
using MiraAPI.PluginLoading;
|
||||
@@ -21,6 +22,11 @@ public static class CustomButtonManager
|
||||
internal static readonly Dictionary<Type, Type> ButtonEventTypes = [];
|
||||
internal static readonly Dictionary<Type, Type> ButtonCancelledEventTypes = [];
|
||||
|
||||
[SuppressMessage(
|
||||
"Major Code Smell",
|
||||
"S3011:Reflection should not be used to increase accessibility of classes, methods, or fields",
|
||||
Justification = "Dynamic singleton initialization requires reflection to bypass the private field access modifier because the type is only known at runtime."
|
||||
)]
|
||||
internal static bool RegisterButton(Type buttonType, MiraPluginInfo pluginInfo)
|
||||
{
|
||||
if (!buttonType.IsAssignableTo(typeof(CustomActionButton)) || Activator.CreateInstance(buttonType) is not CustomActionButton button)
|
||||
@@ -31,9 +37,7 @@ public static class CustomButtonManager
|
||||
CustomButtons.Add(button);
|
||||
pluginInfo.InternalButtons.Add(button);
|
||||
typeof(CustomButtonSingleton<>).MakeGenericType(buttonType)
|
||||
#pragma warning disable S3011
|
||||
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!
|
||||
#pragma warning restore S3011
|
||||
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)! // Suppression message refers to this
|
||||
.SetValue(null, button);
|
||||
|
||||
ButtonEventTypes.Add(buttonType, typeof(MiraButtonClickEvent<>).MakeGenericType(buttonType));
|
||||
|
||||
@@ -10,7 +10,6 @@ using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
@@ -19,9 +18,9 @@ namespace MiraAPI.Hud;
|
||||
/// </summary>
|
||||
/// <param name="il2CppPtr">Used by Il2Cpp. Do not use constructor, this is a <see cref="MonoBehaviour"/>.</param>
|
||||
[RegisterInIl2Cpp]
|
||||
[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity Convention")]
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Unity Convention")]
|
||||
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Unity Convention")]
|
||||
[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity Convention.")]
|
||||
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Unity Convention.")]
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Unity Convention.")]
|
||||
public class CustomPlayerMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr)
|
||||
{
|
||||
public ShapeshifterPanel panelPrefab;
|
||||
@@ -69,6 +68,7 @@ public class CustomPlayerMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr)
|
||||
return customMenu;
|
||||
}
|
||||
|
||||
[SuppressMessage("Style", "IDE0051:Remove unused private members", Justification = "Unity convention.")]
|
||||
private void OnDisable()
|
||||
{
|
||||
ControllerManager.Instance.CloseOverlayMenu(name);
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class MultiTargetButton<T> : CustomActionButton where T : MonoBe
|
||||
/// <summary>
|
||||
/// Sets the outline of the target <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
/// <param name="target">The target <typeparamref name="T"/> to set the oultine.</param>
|
||||
/// <param name="target">The target <typeparamref name="T"/> to set the outline.</param>
|
||||
/// <param name="active">Should the outline be active.</param>
|
||||
public abstract void SetOutline(T target, bool active);
|
||||
|
||||
@@ -54,10 +54,9 @@ public abstract class MultiTargetButton<T> : CustomActionButton where T : MonoBe
|
||||
}
|
||||
}
|
||||
|
||||
Targets = newTargets
|
||||
Targets = [.. newTargets
|
||||
.Where(IsTargetValid)
|
||||
.Take(MaxTargets)
|
||||
.ToArray();
|
||||
.Take(MaxTargets)];
|
||||
Targets.Do(t => SetOutline(t, true));
|
||||
|
||||
return base.CanUse() && Targets.Length > 0;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace MiraAPI.Keybinds;
|
||||
public class BaseKeybind
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Rewired <see cref="InputAction"/> assinged for this keybind.
|
||||
/// Gets the Rewired <see cref="InputAction"/> assigned for this keybind.
|
||||
/// </summary>
|
||||
public InputAction? RewiredInputAction { get; internal set; }
|
||||
|
||||
@@ -38,6 +38,9 @@ public class BaseKeybind
|
||||
Handler = () => { };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BaseKeybind"/> class.
|
||||
/// </summary>
|
||||
public BaseKeybind()
|
||||
{
|
||||
Handler = () => { };
|
||||
@@ -67,6 +70,8 @@ public class BaseKeybind
|
||||
/// <param name="action">The <see cref="Action"/> to remove.</param>
|
||||
public void RemoveOnActivate(Action action)
|
||||
{
|
||||
#pragma warning disable CS8601 // Possible null reference assignment.
|
||||
Handler -= action;
|
||||
#pragma warning restore CS8601 // Possible null reference assignment.
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public static class KeybindManager
|
||||
/// <summary>
|
||||
/// Gets a list of all registered <see cref="MiraKeybind"/>s.
|
||||
/// </summary>
|
||||
public static List<MiraKeybind> Keybinds { get; } = new();
|
||||
public static List<MiraKeybind> Keybinds { get; } = [];
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
internal static Dictionary<Type, VanillaKeybind> VanillaKeybinds { get; set; } = [];
|
||||
@@ -61,7 +61,7 @@ public static class KeybindManager
|
||||
{
|
||||
if (!conflicts.TryGetValue(keybind.CurrentKey, out var group))
|
||||
{
|
||||
conflicts.Add(keybind.CurrentKey, new List<MiraKeybind>());
|
||||
conflicts.Add(keybind.CurrentKey, []);
|
||||
group = conflicts[keybind.CurrentKey];
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public static class KeybindManager
|
||||
/// Returns all <see cref="MiraKeybind"/>s for a specified keycode.
|
||||
/// </summary>
|
||||
/// <param name="keyCode">The key to look for.</param>
|
||||
/// /// <param name="exclusiveCheck">Should only exlusive keybinds be present.</param>
|
||||
/// /// <param name="exclusiveCheck">Should only exclusive keybinds be present.</param>
|
||||
/// <returns>The list of <see cref="MiraKeybind"/>s.</returns>
|
||||
public static MiraKeybind[] GetKeybindsForKey(KeyboardKeyCode keyCode, bool exclusiveCheck = false)
|
||||
{
|
||||
@@ -92,6 +92,6 @@ public static class KeybindManager
|
||||
}
|
||||
}
|
||||
|
||||
return all.ToArray();
|
||||
return [.. all];
|
||||
}
|
||||
}
|
||||
@@ -20,12 +20,7 @@ public static class KeybindUtils
|
||||
/// <returns>The currently assigned keycode.</returns>
|
||||
public static KeyboardKeyCode GetKeycodeByKeybind(BaseKeybind keybind)
|
||||
{
|
||||
if (keybind.RewiredInputAction == null)
|
||||
{
|
||||
return KeyboardKeyCode.None;
|
||||
}
|
||||
|
||||
return GetKeycodeByActionId(keybind.RewiredInputAction.id);
|
||||
return keybind.RewiredInputAction == null ? KeyboardKeyCode.None : GetKeycodeByActionId(keybind.RewiredInputAction.id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -20,7 +20,7 @@ public static class MiraGlobalKeybinds
|
||||
public static MiraKeybind SecondaryAbility { get; } = new("Secondary Ability", KeyboardKeyCode.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keybind for Tetiary abilities.
|
||||
/// Gets the keybind for Tertiary abilities.
|
||||
/// </summary>
|
||||
public static MiraKeybind TertiaryAbility { get; } = new("Tertiary Ability", KeyboardKeyCode.U);
|
||||
|
||||
@@ -35,7 +35,7 @@ public static class MiraGlobalKeybinds
|
||||
public static MiraKeybind ModifierSecondaryAbility { get; } = new("Modifier Secondary Ability", KeyboardKeyCode.O);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keybind for Tetiary modifier abilities.
|
||||
/// Gets the keybind for Tertiary modifier abilities.
|
||||
/// </summary>
|
||||
public static MiraKeybind ModifierTertiaryAbility { get; } = new("Modifier Tertiary Ability", KeyboardKeyCode.P);
|
||||
}
|
||||
@@ -6,50 +6,39 @@ namespace MiraAPI.Keybinds;
|
||||
/// <summary>
|
||||
/// Represents a registered keybind.
|
||||
/// </summary>
|
||||
public class MiraKeybind : BaseKeybind
|
||||
/// <param name="name">The name of the keybind.</param>
|
||||
/// <param name="defaultKeycode">The default keycode.</param>
|
||||
/// <param name="modifierKeys">Up to 3 optional <see cref="ModifierKey"/>s.</param>
|
||||
/// <param name="exclusive">Is exclusive.</param>
|
||||
public class MiraKeybind(
|
||||
string name,
|
||||
KeyboardKeyCode? defaultKeycode,
|
||||
ModifierKey[]? modifierKeys = null,
|
||||
bool exclusive = true) : BaseKeybind(name.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_'))
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets name of the keybind.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
public string Name { get; } = name;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default keycode of this keybind.
|
||||
/// </summary>
|
||||
public KeyboardKeyCode DefaultKey { get; }
|
||||
public KeyboardKeyCode DefaultKey { get; } = defaultKeycode ?? KeyboardKeyCode.None;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ModifierKey"/>s assigned to this keybind.
|
||||
/// Due to Rewired limitations, there can only be 3 <see cref="ModifierKey"/>s.
|
||||
/// </summary>
|
||||
public ModifierKey[] ModifierKeys { get; }
|
||||
public ModifierKey[] ModifierKeys { get; } = modifierKeys ?? [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this keybind should be checked for conflicts with other exclusive keybinds using the same key.
|
||||
/// </summary>
|
||||
public bool Exclusive { get; }
|
||||
public bool Exclusive { get; } = exclusive;
|
||||
|
||||
internal string? SourcePluginName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MiraKeybind"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the keybind.</param>
|
||||
/// <param name="defaultKeycode">The default keycode.</param>
|
||||
/// <param name="modifierKeys">Up to 3 optional <see cref="ModifierKey"/>s.</param>
|
||||
/// <param name="exclusive">Is exclusive.</param>
|
||||
public MiraKeybind(
|
||||
string name,
|
||||
KeyboardKeyCode? defaultKeycode,
|
||||
ModifierKey[]? modifierKeys = null,
|
||||
bool exclusive = true) : base(name.ToLower(CultureInfo.InvariantCulture).Replace(' ', '_'))
|
||||
{
|
||||
Name = name;
|
||||
DefaultKey = defaultKeycode ?? KeyboardKeyCode.None;
|
||||
ModifierKeys = modifierKeys ?? [];
|
||||
Exclusive = exclusive;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace MiraAPI.Keybinds;
|
||||
public class VanillaKeybind : BaseKeybind
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ActionButton"/> this keybind is binded to.
|
||||
/// Gets the <see cref="ActionButton"/> this keybind is bound to.
|
||||
/// </summary>
|
||||
public ActionButton? Button { get; internal set; }
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
namespace MiraAPI.Keybinds;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace MiraAPI.Keybinds;
|
||||
|
||||
/// <summary>
|
||||
/// Singleton for getting a <see cref="VanillaKeybind"/> by <see cref="ActionButton"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"><see cref="AccountButton"/> type.</typeparam>
|
||||
/// <typeparam name="T"><see cref="ActionButton"/> type.</typeparam>
|
||||
public static class VanillaKeybinding<T> where T : ActionButton
|
||||
{
|
||||
[SuppressMessage("Major Code Smell", "S2743:Static fields should not be used in generic types", Justification = "The instance holds a reference to the button that defines the class's type parameter.")]
|
||||
private static VanillaKeybind? _instance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the <see cref="VanillaKeybind"/>.
|
||||
/// </summary>
|
||||
#pragma warning disable CA1000
|
||||
[SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "This is a utility class to get the instance of a vanilla keybind.")]
|
||||
public static VanillaKeybind Instance => _instance ??= KeybindManager.VanillaKeybinds[typeof(T)];
|
||||
#pragma warning restore CA1000
|
||||
}
|
||||
@@ -7,8 +7,9 @@ namespace MiraAPI.LocalSettings.Attributes;
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LocalEnumSetting"/> for the <see cref="ConfigEntry{T}"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the setting.</param>
|
||||
/// <param name="description">The description of the setting.</param>
|
||||
/// <param name="names">Optional custom <see langword="enum"/> names.</param>
|
||||
/// <inheritdoc/>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class LocalEnumSettingAttribute(
|
||||
string? name = null,
|
||||
|
||||
@@ -8,11 +8,13 @@ namespace MiraAPI.LocalSettings.Attributes;
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LocalNumberSetting"/> for the <see cref="ConfigEntry{T}"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the setting.</param>
|
||||
/// <param name="description">The description of the setting.</param>
|
||||
/// <param name="min">Minimum range.</param>
|
||||
/// <param name="max">Maximum range.</param>
|
||||
/// <param name="increment">Increment per use.</param>
|
||||
/// <param name="suffixType">Suffix for the value.</param>
|
||||
/// <param name="formatString">Format string used when formating.</param>
|
||||
/// <param name="formatString">Format string used when formatting.</param>
|
||||
/// <inheritdoc/>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class LocalNumberSettingAttribute(
|
||||
|
||||
@@ -7,11 +7,13 @@ namespace MiraAPI.LocalSettings.Attributes;
|
||||
/// Base class for all local settings attributes.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the setting. Defaults to entry key.</param>
|
||||
/// <param name="description">The description of the setting. Defalts to entry description.</param>
|
||||
/// <param name="description">The description of the setting. Defaults to entry description.</param>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public abstract class LocalSettingAttribute(
|
||||
#pragma warning disable CS9113 // Parameter is unread.
|
||||
string? name = null,
|
||||
string? description = null
|
||||
#pragma warning restore CS9113 // Parameter is unread.
|
||||
) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -9,10 +9,14 @@ namespace MiraAPI.LocalSettings.Attributes;
|
||||
/// Creates a <see cref="LocalSliderSetting"/> for the <see cref="ConfigEntry{T}"/>.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
/// <param name="name">The name of the setting.</param>
|
||||
/// <param name="description">The description of the setting.</param>
|
||||
/// <param name="min">Minimum range.</param>
|
||||
/// <param name="max">Maximum range.</param>
|
||||
/// <param name="roundValue">Should the value be rounded.</param>
|
||||
/// <param name="suffixType">Suffix for the value.</param>
|
||||
/// <param name="displayValue">Should display the value next to the name.</param>
|
||||
/// <param name="formatString">The format string used for formatting.</param>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class LocalSliderSettingAttribute(
|
||||
string? name = null,
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace MiraAPI.LocalSettings.Attributes;
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LocalToggleSetting"/> for the <see cref="ConfigEntry{T}"/>.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class LocalToggleSettingAttribute(
|
||||
string? name = null,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
|
||||
@@ -14,6 +15,11 @@ public static class LocalSettingsManager
|
||||
internal static readonly List<LocalSettingsTab> Tabs = [];
|
||||
internal static readonly List<LocalSettingsTab> AvailableTabs = [];
|
||||
|
||||
[SuppressMessage(
|
||||
"Major Code Smell",
|
||||
"S3011:Reflection should not be used to increase accessibility of classes, methods, or fields",
|
||||
Justification = "Dynamic singleton initialization requires reflection to bypass the private field access modifier because the type is only known at runtime."
|
||||
)]
|
||||
internal static bool RegisterTab(Type type, BasePlugin pluginInfo)
|
||||
{
|
||||
if (Activator.CreateInstance(type, pluginInfo.Config) is not LocalSettingsTab tab)
|
||||
@@ -35,9 +41,7 @@ public static class LocalSettingsManager
|
||||
TypeToTab.Add(type, tab);
|
||||
|
||||
typeof(LocalSettingsTabSingleton<>).MakeGenericType(type)
|
||||
#pragma warning disable S3011
|
||||
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!
|
||||
#pragma warning restore S3011
|
||||
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)! // Suppression message refers to this
|
||||
.SetValue(null, tab);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -84,115 +84,115 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
/// <summary>
|
||||
/// Creates the tab <see cref="GameObject"/> and it's content.
|
||||
/// </summary>
|
||||
/// <param name="instance">The <see cref="OptionsMenuBehaviour"/> instace.</param>
|
||||
/// <param name="instance">The <see cref="OptionsMenuBehaviour"/> instance.</param>
|
||||
/// <returns>The created tab <see cref="GameObject"/>.</returns>
|
||||
public virtual GameObject CreateTab(OptionsMenuBehaviour instance)
|
||||
{
|
||||
var tab = Object.Instantiate(instance.transform.FindChild("GeneralTab").gameObject, instance.transform);
|
||||
tab.name = $"{TabName}Tab";
|
||||
tab.transform.DestroyChildren();
|
||||
tab.gameObject.SetActive(false);
|
||||
var tab = Object.Instantiate(instance.transform.FindChild("GeneralTab").gameObject, instance.transform);
|
||||
tab.name = $"{TabName}Tab";
|
||||
tab.transform.DestroyChildren();
|
||||
tab.gameObject.SetActive(false);
|
||||
|
||||
if (Scroller == null)
|
||||
{
|
||||
Scroller = Helpers.CreateScroller(tab.transform, OptionsMenuPatches.MaskCollider);
|
||||
}
|
||||
if (Scroller == null)
|
||||
{
|
||||
Scroller = Helpers.CreateScroller(tab.transform, OptionsMenuPatches.MaskCollider);
|
||||
}
|
||||
|
||||
if (TabButton != null)
|
||||
{
|
||||
TabButton.Content = tab.gameObject;
|
||||
}
|
||||
if (TabButton != null)
|
||||
{
|
||||
TabButton.Content = tab.gameObject;
|
||||
}
|
||||
|
||||
var generalLabel = instance.transform.FindChild("GeneralTab").FindChild("ControlGroup")
|
||||
.FindChild("ControlText_TMP").gameObject;
|
||||
var toggle = instance.transform.FindChild("GeneralTab").FindChild("ChatGroup").FindChild("CensorChatButton").GetComponent<ToggleButtonBehaviour>();
|
||||
var slider = instance.transform.FindChild("GeneralTab").FindChild("SoundGroup").FindChild("SFXSlider").GetComponent<SlideBar>();
|
||||
var generalLabel = instance.transform.FindChild("GeneralTab").FindChild("ControlGroup")
|
||||
.FindChild("ControlText_TMP").gameObject;
|
||||
var toggle = instance.transform.FindChild("GeneralTab").FindChild("ChatGroup").FindChild("CensorChatButton").GetComponent<ToggleButtonBehaviour>();
|
||||
var slider = instance.transform.FindChild("GeneralTab").FindChild("SoundGroup").FindChild("SFXSlider").GetComponent<SlideBar>();
|
||||
|
||||
Dictionary<string, List<ILocalSetting>> entriesByGroup = new();
|
||||
foreach (var entry in Settings)
|
||||
{
|
||||
var group = entry.ConfigEntry.Definition.Section;
|
||||
if (!entriesByGroup.ContainsKey(group))
|
||||
entriesByGroup.Add(group, []);
|
||||
Dictionary<string, List<ILocalSetting>> entriesByGroup = [];
|
||||
foreach (var entry in Settings)
|
||||
{
|
||||
var group = entry.ConfigEntry.Definition.Section;
|
||||
if (!entriesByGroup.ContainsKey(group))
|
||||
entriesByGroup.Add(group, []);
|
||||
|
||||
entriesByGroup[group].Add(entry);
|
||||
}
|
||||
entriesByGroup[group].Add(entry);
|
||||
}
|
||||
|
||||
float contentOffset = 0;
|
||||
var contentOrder = 1;
|
||||
var contentIndex = 1;
|
||||
float contentOffset = 0;
|
||||
var contentOrder = 1;
|
||||
var contentIndex = 1;
|
||||
|
||||
foreach (var pair in entriesByGroup)
|
||||
{
|
||||
if (ShouldCreateLabels)
|
||||
{
|
||||
CreateLabel(generalLabel, Scroller.Inner, pair.Key, ref contentOffset);
|
||||
contentOrder = 1;
|
||||
contentIndex = 1;
|
||||
}
|
||||
foreach (var pair in entriesByGroup)
|
||||
{
|
||||
if (ShouldCreateLabels)
|
||||
{
|
||||
CreateLabel(generalLabel, Scroller.Inner, pair.Key, ref contentOffset);
|
||||
contentOrder = 1;
|
||||
contentIndex = 1;
|
||||
}
|
||||
|
||||
foreach (var setting in pair.Value)
|
||||
{
|
||||
var obj = setting.CreateOption(
|
||||
toggle,
|
||||
slider,
|
||||
Scroller.Inner,
|
||||
ref contentOffset,
|
||||
ref contentOrder,
|
||||
contentIndex == pair.Value.Count);
|
||||
foreach (var setting in pair.Value)
|
||||
{
|
||||
var obj = setting.CreateOption(
|
||||
toggle,
|
||||
slider,
|
||||
Scroller.Inner,
|
||||
ref contentOffset,
|
||||
ref contentOrder,
|
||||
contentIndex == pair.Value.Count);
|
||||
|
||||
obj!.GetComponentsInChildren<SpriteRenderer>(true).Do(x =>
|
||||
{
|
||||
x.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
||||
x.sortingOrder = 150;
|
||||
x.sortingLayerName = "Default";
|
||||
});
|
||||
obj!.GetComponentsInChildren<SpriteRenderer>(true).Do(x =>
|
||||
{
|
||||
x.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
||||
x.sortingOrder = 150;
|
||||
x.sortingLayerName = "Default";
|
||||
});
|
||||
|
||||
obj.GetComponentsInChildren<MeshRenderer>(true).Do(x =>
|
||||
{
|
||||
x.sortingOrder = 151;
|
||||
x.sortingLayerName = "Default";
|
||||
});
|
||||
obj.GetComponentsInChildren<MeshRenderer>(true).Do(x =>
|
||||
{
|
||||
x.sortingOrder = 151;
|
||||
x.sortingLayerName = "Default";
|
||||
});
|
||||
|
||||
obj.GetComponentsInChildren<PassiveButton>().Do(x => { x.ClickMask = OptionsMenuPatches.MaskCollider; });
|
||||
obj.GetComponentsInChildren<PassiveButton>().Do(x => { x.ClickMask = OptionsMenuPatches.MaskCollider; });
|
||||
|
||||
contentIndex++;
|
||||
}
|
||||
contentIndex++;
|
||||
}
|
||||
|
||||
contentOrder = 1;
|
||||
}
|
||||
contentOrder = 1;
|
||||
}
|
||||
|
||||
contentIndex = 1;
|
||||
contentOrder = 1;
|
||||
foreach (var button in Buttons)
|
||||
{
|
||||
var obj = button.CreateButton(
|
||||
toggle,
|
||||
Scroller.Inner,
|
||||
ref contentOffset,
|
||||
ref contentOrder,
|
||||
contentIndex == Buttons.Count);
|
||||
contentIndex = 1;
|
||||
contentOrder = 1;
|
||||
foreach (var button in Buttons)
|
||||
{
|
||||
var obj = button.CreateButton(
|
||||
toggle,
|
||||
Scroller.Inner,
|
||||
ref contentOffset,
|
||||
ref contentOrder,
|
||||
contentIndex == Buttons.Count);
|
||||
|
||||
obj!.GetComponentsInChildren<SpriteRenderer>(true).Do(x =>
|
||||
{
|
||||
x.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
||||
x.sortingOrder = 150;
|
||||
x.sortingLayerName = "Default";
|
||||
});
|
||||
obj!.GetComponentsInChildren<SpriteRenderer>(true).Do(x =>
|
||||
{
|
||||
x.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
||||
x.sortingOrder = 150;
|
||||
x.sortingLayerName = "Default";
|
||||
});
|
||||
|
||||
obj.GetComponentsInChildren<MeshRenderer>(true).Do(x =>
|
||||
{
|
||||
x.sortingOrder = 151;
|
||||
x.sortingLayerName = "Default";
|
||||
});
|
||||
obj.GetComponentsInChildren<MeshRenderer>(true).Do(x =>
|
||||
{
|
||||
x.sortingOrder = 151;
|
||||
x.sortingLayerName = "Default";
|
||||
});
|
||||
|
||||
obj.GetComponentsInChildren<PassiveButton>().Do(x => { x.ClickMask = OptionsMenuPatches.MaskCollider; });
|
||||
obj.GetComponentsInChildren<PassiveButton>().Do(x => { x.ClickMask = OptionsMenuPatches.MaskCollider; });
|
||||
|
||||
contentIndex++;
|
||||
}
|
||||
contentIndex++;
|
||||
}
|
||||
|
||||
Scroller.SetBounds(new FloatRange(0, (Settings.Count + Buttons.Count) * 0.5f - 5f), new FloatRange(0, 0));
|
||||
return tab;
|
||||
Scroller.SetBounds(new FloatRange(0, (Settings.Count + Buttons.Count) * 0.5f - 5f), new FloatRange(0, 0));
|
||||
return tab;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -252,8 +252,10 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
{
|
||||
if (!tabButtonObject.Content.gameObject.activeSelf)
|
||||
{
|
||||
//tabButtonObject.Button.color = TabColor;
|
||||
//tabButtonObject.Rollover.OutColor = TabColor;
|
||||
#pragma warning disable S125 // Sections of code should not be commented out
|
||||
// tabButtonObject.Button.color = TabColor;
|
||||
// tabButtonObject.Rollover.OutColor = TabColor;
|
||||
#pragma warning restore S125 // Sections of code should not be commented out
|
||||
}
|
||||
|
||||
tabButton.transform.localPosition = new Vector3(2.4f, 2.1f - tabOffset, 5.5f);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace MiraAPI.LocalSettings;
|
||||
|
||||
@@ -13,7 +14,6 @@ public static class LocalSettingsTabSingleton<T> where T : LocalSettingsTab
|
||||
/// <summary>
|
||||
/// Gets the instance of the <typeparamref name="T"/> setting tab.
|
||||
/// </summary>
|
||||
#pragma warning disable CA1000
|
||||
[SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "This is a utility class to get the instance of a local settings tab.")]
|
||||
public static T Instance => _instance ??= LocalSettingsManager.Tabs.OfType<T>().Single();
|
||||
#pragma warning restore CA1000
|
||||
}
|
||||
@@ -13,40 +13,32 @@ namespace MiraAPI.LocalSettings.SettingTypes;
|
||||
/// <summary>
|
||||
/// Local setting class for <see langword="enum"/>s.
|
||||
/// </summary>
|
||||
public class LocalEnumSetting : LocalSettingBase<int>
|
||||
/// <param name="tab">The tab to create the setting in.</param>
|
||||
/// <param name="configEntry">The config entry.</param>
|
||||
/// <param name="enumType">The <see cref="Enum"/> type.</param>
|
||||
/// <param name="name">The name of the setting.</param>
|
||||
/// <param name="description">The description of the setting.</param>
|
||||
/// <param name="values">The optional values array to replace the <see langword="enum"/> names.</param>
|
||||
public class LocalEnumSetting(
|
||||
Type tab,
|
||||
ConfigEntryBase configEntry,
|
||||
Type enumType,
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
string[]? values = null) : LocalSettingBase<int>(tab, configEntry, name, description)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Enum"/> type of the setting.
|
||||
/// </summary>
|
||||
public Type EnumType { get; }
|
||||
public Type EnumType { get; } = enumType;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see langword="enum"/> values.
|
||||
/// </summary>
|
||||
public string[] Values { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalEnumSetting"/> class.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
/// <param name="enumType">The <see cref="Enum"/> type.</param>
|
||||
/// <param name="values">The optional values array to replace the <see langword="enum"/> names.</param>
|
||||
public LocalEnumSetting(
|
||||
Type tab,
|
||||
ConfigEntryBase configEntry,
|
||||
Type enumType,
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
string[]? values = null)
|
||||
: base(tab, configEntry, name, description)
|
||||
{
|
||||
EnumType = enumType;
|
||||
Values = values ?? Enum
|
||||
public string[] Values { get; } = values ?? [.. Enum
|
||||
.GetValues(configEntry.SettingType)
|
||||
.Cast<Enum>()
|
||||
.Select(x => x.ToDisplayString())
|
||||
.ToArray();
|
||||
}
|
||||
.Select(x => x.ToDisplayString())];
|
||||
|
||||
/// <inheritdoc />
|
||||
public override GameObject CreateOption(ToggleButtonBehaviour toggle, SlideBar slider, Transform parent, ref float offset, ref int order, bool last)
|
||||
|
||||
@@ -12,52 +12,43 @@ namespace MiraAPI.LocalSettings.SettingTypes;
|
||||
/// <summary>
|
||||
/// Local setting class for numbers.
|
||||
/// </summary>
|
||||
public class LocalNumberSetting : LocalSettingBase<float>
|
||||
/// <param name="tab">The tab to create the setting in.</param>
|
||||
/// <param name="configEntry">The config entry.</param>
|
||||
/// <param name="numberRange">The value range.</param>
|
||||
/// <param name="name">The name of the setting.</param>
|
||||
/// <param name="description">The description of the setting.</param>
|
||||
/// <param name="increment">The increment per click.</param>
|
||||
/// <param name="suffixType">The suffix used for formatting.</param>
|
||||
/// <param name="formatString">The format string used for formatting.</param>
|
||||
public class LocalNumberSetting(
|
||||
Type tab,
|
||||
ConfigEntryBase configEntry,
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
FloatRange? numberRange = null,
|
||||
float? increment = null,
|
||||
MiraNumberSuffixes? suffixType = null,
|
||||
string? formatString = null) : LocalSettingBase<float>(tab, configEntry, name, description)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the range of the button.
|
||||
/// </summary>
|
||||
public FloatRange NumberRange { get; }
|
||||
public FloatRange NumberRange { get; } = numberRange ?? new FloatRange(1, 5);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the increment of the value when button is pressed.
|
||||
/// </summary>
|
||||
public float Increment { get; }
|
||||
public float Increment { get; } = increment ?? 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a format for the text to use to format the number.
|
||||
/// </summary>
|
||||
public string FormatString { get; }
|
||||
public string FormatString { get; } = formatString ?? "0";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the suffix for the number value.
|
||||
/// </summary>
|
||||
public MiraNumberSuffixes SuffixType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalNumberSetting"/> class.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
/// <param name="numberRange">The value range.</param>
|
||||
/// <param name="increment">The increment per click.</param>
|
||||
/// <param name="suffixType">The suffix used for formating.</param>
|
||||
/// <param name="formatString">The format string used for formating.</param>
|
||||
public LocalNumberSetting(
|
||||
Type tab,
|
||||
ConfigEntryBase configEntry,
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
FloatRange? numberRange = null,
|
||||
float? increment = null,
|
||||
MiraNumberSuffixes? suffixType = null,
|
||||
string? formatString = null)
|
||||
: base(tab, configEntry, name, description)
|
||||
{
|
||||
SuffixType = suffixType ?? MiraNumberSuffixes.None;
|
||||
NumberRange = numberRange ?? new FloatRange(1, 5);
|
||||
Increment = increment ?? 1;
|
||||
FormatString = formatString ?? "0";
|
||||
}
|
||||
public MiraNumberSuffixes SuffixType { get; } = suffixType ?? MiraNumberSuffixes.None;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override GameObject CreateOption(ToggleButtonBehaviour toggle, SlideBar slider, Transform parent, ref float offset, ref int order, bool last)
|
||||
@@ -139,7 +130,7 @@ public class LocalNumberSetting : LocalSettingBase<float>
|
||||
protected override string GetValueText()
|
||||
{
|
||||
var value = GetValue();
|
||||
var formated = Helpers.FormatValue(value, SuffixType, FormatString);
|
||||
return $"<font=\"LiberationSans SDF\" material=\"LiberationSans SDF - Chat Message Masked\">{Name}: <b>{formated}</font></b>";
|
||||
var formatted = Helpers.FormatValue(value, SuffixType, FormatString);
|
||||
return $"<font=\"LiberationSans SDF\" material=\"LiberationSans SDF - Chat Message Masked\">{Name}: <b>{formatted}</font></b>";
|
||||
}
|
||||
}
|
||||
@@ -12,59 +12,50 @@ namespace MiraAPI.LocalSettings.SettingTypes;
|
||||
/// <summary>
|
||||
/// Local setting class for sliders.
|
||||
/// </summary>
|
||||
public class LocalSliderSetting : LocalSettingBase<float>
|
||||
/// <param name="tab">The tab to create the setting in.</param>
|
||||
/// <param name="configEntry">The config entry.</param>
|
||||
/// <param name="name">The name of the setting.</param>
|
||||
/// <param name="description">The description of the setting.</param>
|
||||
/// <param name="sliderRange">The value range.</param>
|
||||
/// <param name="suffixType">The suffix used for formatting.</param>
|
||||
/// <param name="formatString">The format string used for formatting.</param>
|
||||
/// <param name="roundValue">Should the value be rounded.</param>
|
||||
/// <param name="displayValue">Should display the value next to the name.</param>
|
||||
public class LocalSliderSetting(
|
||||
Type tab,
|
||||
ConfigEntryBase configEntry,
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
FloatRange? sliderRange = null,
|
||||
bool displayValue = false,
|
||||
MiraNumberSuffixes? suffixType = null,
|
||||
string? formatString = null,
|
||||
bool roundValue = false) : LocalSettingBase<float>(tab, configEntry, name, description)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the range of the slider.
|
||||
/// </summary>
|
||||
public FloatRange SliderRange { get; }
|
||||
public FloatRange SliderRange { get; } = sliderRange ?? new FloatRange(0, 100);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the value should be displayed next to name.
|
||||
/// </summary>
|
||||
public bool DisplayValue { get; }
|
||||
public bool DisplayValue { get; } = displayValue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a format for the text to use to format the number.
|
||||
/// </summary>
|
||||
public string FormatString { get; }
|
||||
public string FormatString { get; } = formatString ?? "0.0";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the value should be rounded.
|
||||
/// </summary>
|
||||
public bool RoundValue { get; }
|
||||
public bool RoundValue { get; } = roundValue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the suffix for the number value.
|
||||
/// </summary>
|
||||
public MiraNumberSuffixes SuffixType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalSliderSetting"/> class.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
/// <param name="sliderRange">The value range.</param>
|
||||
/// <param name="suffixType">The suffix used for formating.</param>
|
||||
/// <param name="formatString">The format string used for formating.</param>
|
||||
/// <param name="roundValue">Should the value be rounded.</param>
|
||||
public LocalSliderSetting(
|
||||
Type tab,
|
||||
ConfigEntryBase configEntry,
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
FloatRange? sliderRange = null,
|
||||
bool displayValue = false,
|
||||
MiraNumberSuffixes? suffixType = null,
|
||||
string? formatString = null,
|
||||
bool roundValue = false)
|
||||
: base(tab, configEntry, name, description)
|
||||
{
|
||||
SliderRange = sliderRange ?? new FloatRange(0, 100);
|
||||
DisplayValue = displayValue;
|
||||
SuffixType = suffixType ?? MiraNumberSuffixes.None;
|
||||
FormatString = formatString ?? "0.0";
|
||||
RoundValue = roundValue;
|
||||
}
|
||||
public MiraNumberSuffixes SuffixType { get; } = suffixType ?? MiraNumberSuffixes.None;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override GameObject CreateOption(ToggleButtonBehaviour toggle, SlideBar slider, Transform parent, ref float offset, ref int order, bool last)
|
||||
@@ -110,9 +101,9 @@ public class LocalSliderSetting : LocalSettingBase<float>
|
||||
if (DisplayValue)
|
||||
{
|
||||
var value = GetValue();
|
||||
var formated = Helpers.FormatValue(value, SuffixType, FormatString);
|
||||
var maxFormated = Helpers.FormatValue(SliderRange.max, SuffixType, FormatString);
|
||||
return $"<font=\"LiberationSans SDF\" material=\"LiberationSans SDF - Chat Message Masked\">{Name}: <b>{formated} / {maxFormated}</font></b>";
|
||||
var formatted = Helpers.FormatValue(value, SuffixType, FormatString);
|
||||
var maxFormatted = Helpers.FormatValue(SliderRange.max, SuffixType, FormatString);
|
||||
return $"<font=\"LiberationSans SDF\" material=\"LiberationSans SDF - Chat Message Masked\">{Name}: <b>{formatted} / {maxFormatted}</font></b>";
|
||||
}
|
||||
|
||||
return $"<font=\"LiberationSans SDF\" material=\"LiberationSans SDF - Chat Message Masked\">{Name}</font></b>";
|
||||
|
||||
@@ -12,21 +12,17 @@ namespace MiraAPI.LocalSettings.SettingTypes;
|
||||
/// <summary>
|
||||
/// Local setting class for toggles.
|
||||
/// </summary>
|
||||
public class LocalToggleSetting : LocalSettingBase<bool>
|
||||
/// <param name="tab">The tab to create the setting in.</param>
|
||||
/// <param name="configEntry">The config entry.</param>
|
||||
/// <param name="name">The name of the setting.</param>
|
||||
/// <param name="description">The description of the setting.</param>
|
||||
public class LocalToggleSetting(
|
||||
Type tab,
|
||||
ConfigEntryBase configEntry,
|
||||
string? name = null,
|
||||
string? description = null
|
||||
) : LocalSettingBase<bool>(tab, configEntry, name, description)
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalToggleSetting"/> class.
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public LocalToggleSetting(
|
||||
Type tab,
|
||||
ConfigEntryBase configEntry,
|
||||
string? name = null,
|
||||
string? description = null
|
||||
) : base(tab, configEntry, name, description)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override GameObject CreateOption(ToggleButtonBehaviour toggle, SlideBar slider, Transform parent, ref float offset, ref int order, bool last)
|
||||
{
|
||||
|
||||
@@ -5,16 +5,17 @@
|
||||
<PackageId>AllOfUs.MiraAPI</PackageId>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>IDE0031;IDE0032</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\**\*.*" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="../AmongUs.props" />
|
||||
|
||||
<Import Project="../AmongUs.props" />
|
||||
|
||||
</Project>
|
||||
@@ -1,4 +1,5 @@
|
||||
global using static Reactor.Utilities.Logger<MiraAPI.MiraApiPlugin>;
|
||||
|
||||
using System;
|
||||
using BepInEx;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
|
||||
@@ -71,15 +71,13 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
/// Gets the scale of the buttons.
|
||||
/// </summary>
|
||||
[LocalSliderSetting(min: 0.5f, max: 1.5f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
|
||||
public ConfigEntry<float> ButtonUIFactorSlider { get; private set; } =
|
||||
config.Bind("Visuals/UI", "Button Scale Factor", 0.75f);
|
||||
public ConfigEntry<float> ButtonUIFactorSlider { get; private set; } = config.Bind("Visuals/UI", "Button Scale Factor", 0.75f);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fps specified by the player.
|
||||
/// </summary>
|
||||
[LocalSliderSetting(min: 60f, max: 240f, suffixType: MiraNumberSuffixes.None, formatString: "0", displayValue: true, roundValue: true)]
|
||||
public ConfigEntry<float> SetFpsSlider { get; private set; } =
|
||||
config.Bind("Visuals/UI", "Max FPS", 120f);
|
||||
public ConfigEntry<float> SetFpsSlider { get; private set; } = config.Bind("Visuals/UI", "Max FPS", 120f);
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether to apply cosmetic changes to the TaskAdder.
|
||||
|
||||
@@ -78,7 +78,10 @@ public abstract class BaseModifier : IOptionable
|
||||
/// Gets the HUD description for this modifier. Does nothing if <see cref="HideOnUi"/> is <see langword="true"/>. Required to be visible on UI.
|
||||
/// </summary>
|
||||
/// <returns>The description string for the HUD.</returns>
|
||||
public virtual string GetDescription() => string.Empty;
|
||||
public virtual string GetDescription()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the modifier is activated.
|
||||
@@ -127,5 +130,8 @@ public abstract class BaseModifier : IOptionable
|
||||
/// Determines whether the player can vent.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if the player can vent, <see langword="false"/> otherwise. <see langword="null"/> for no effect.</returns>
|
||||
public virtual bool? CanVent() => null;
|
||||
public virtual bool? CanVent()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ namespace MiraAPI.Modifiers;
|
||||
/// The component for handling <see cref="BaseModifier"/>s.
|
||||
/// </summary>
|
||||
[RegisterInIl2Cpp]
|
||||
[SuppressMessage("Style", "IDE0051:Remove unused private members", Justification = "Unity Convention.")]
|
||||
public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
/// <summary>
|
||||
@@ -170,7 +171,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
/// <typeparam name="T">The Type of the <see cref="BaseModifier"/>e.</typeparam>
|
||||
/// <returns>An <see cref="IEnumerable{T}"/> of <typeparamref name="T"/>s.</returns>
|
||||
[HideFromIl2Cpp]
|
||||
public IEnumerable<T> GetModifiers<T>(Func<T, bool>? predicate=null) where T : BaseModifier
|
||||
public IEnumerable<T> GetModifiers<T>(Func<T, bool>? predicate = null) where T : BaseModifier
|
||||
{
|
||||
return ActiveModifiers.OfType<T>().Where(x => predicate == null || predicate(x));
|
||||
}
|
||||
@@ -182,7 +183,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
/// <param name="predicate">The predicate to check the <see cref="BaseModifier"/> by.</param>
|
||||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="BaseModifier"/>s.</returns>
|
||||
[HideFromIl2Cpp]
|
||||
public IEnumerable<BaseModifier> GetModifiers(Type type, Func<BaseModifier, bool>? predicate=null)
|
||||
public IEnumerable<BaseModifier> GetModifiers(Type type, Func<BaseModifier, bool>? predicate = null)
|
||||
{
|
||||
return ActiveModifiers.Where(x => x.GetType() == type && (predicate == null || predicate(x)));
|
||||
}
|
||||
@@ -194,7 +195,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
/// <param name="predicate">The predicate to check the <see cref="BaseModifier"/> by.</param>
|
||||
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="BaseModifier"/>s.</returns>
|
||||
[HideFromIl2Cpp]
|
||||
public IEnumerable<BaseModifier> GetModifiers(uint id, Func<BaseModifier, bool>? predicate=null)
|
||||
public IEnumerable<BaseModifier> GetModifiers(uint id, Func<BaseModifier, bool>? predicate = null)
|
||||
{
|
||||
var type = ModifierManager.GetModifierType(id) ?? throw new InvalidOperationException(
|
||||
$"Cannot get modifier with id {id} because it is not registered.");
|
||||
@@ -446,20 +447,10 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
[HideFromIl2Cpp]
|
||||
public BaseModifier? AddModifier(Type type, params object[] args)
|
||||
{
|
||||
BaseModifier? modifier;
|
||||
if (args.Length > 0)
|
||||
{
|
||||
modifier = ModifierFactory.CreateInstance(type, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
modifier = Activator.CreateInstance(type) as BaseModifier;
|
||||
if (modifier == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot add modifier {type.Name} because it is not a valid modifier.");
|
||||
}
|
||||
}
|
||||
|
||||
var modifier = args.Length > 0
|
||||
? ModifierFactory.CreateInstance(type, args)
|
||||
: Activator.CreateInstance(type) as BaseModifier
|
||||
?? throw new InvalidOperationException($"Cannot add modifier {type.Name} because it is not a valid modifier.");
|
||||
return AddModifier(modifier);
|
||||
}
|
||||
|
||||
@@ -485,7 +476,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
/// <typeparam name="T">The Type of the <see cref="BaseModifier"/>.</typeparam>
|
||||
/// <returns><see langword="true"/> if the <typeparamref name="T"/> is present, <see langword="false"/> otherwise.</returns>
|
||||
[HideFromIl2Cpp]
|
||||
public bool HasModifier<T>(Func<T, bool>? predicate=null) where T : BaseModifier
|
||||
public bool HasModifier<T>(Func<T, bool>? predicate = null) where T : BaseModifier
|
||||
{
|
||||
return ActiveModifiers.Exists(x => x is T modifier && (predicate == null || predicate(modifier)));
|
||||
}
|
||||
@@ -497,7 +488,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
/// <param name="predicate">The predicate to check the <see cref="BaseModifier"/>.</param>
|
||||
/// <returns><see langword="true"/> if the <see cref="BaseModifier"/> is present, <see langword="false"/> otherwise.</returns>
|
||||
[HideFromIl2Cpp]
|
||||
public bool HasModifier(Type type, Func<BaseModifier, bool>? predicate=null)
|
||||
public bool HasModifier(Type type, Func<BaseModifier, bool>? predicate = null)
|
||||
{
|
||||
return ActiveModifiers.Exists(x => x.GetType() == type && (predicate == null || predicate(x)));
|
||||
}
|
||||
@@ -509,7 +500,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
/// <param name="predicate">The predicate to check the <see cref="BaseModifier"/>.</param>
|
||||
/// <returns><see langword="true"/> if the <see cref="BaseModifier"/> is present, <see langword="false"/> otherwise.</returns>
|
||||
[HideFromIl2Cpp]
|
||||
public bool HasModifier(uint id, Func<BaseModifier, bool>? predicate=null)
|
||||
public bool HasModifier(uint id, Func<BaseModifier, bool>? predicate = null)
|
||||
{
|
||||
var type = ModifierManager.GetModifierType(id) ?? throw new InvalidOperationException(
|
||||
$"Cannot get modifier with id {id} because it is not registered.");
|
||||
@@ -536,10 +527,13 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
/// <typeparam name="T">The Type of the <see cref="BaseModifier"/>.</typeparam>
|
||||
/// <returns><see langword="true"/> if the <typeparamref name="T"/> is present, <see langword="false"/> otherwise.</returns>
|
||||
[HideFromIl2Cpp]
|
||||
public bool HasModifier<T>(bool checkInactive, Func<T, bool>? predicate=null) where T : BaseModifier
|
||||
public bool HasModifier<T>(bool checkInactive, Func<T, bool>? predicate = null) where T : BaseModifier
|
||||
{
|
||||
return ActiveModifiers.Exists(MatchExpr) || (checkInactive && _toAdd.Exists(MatchExpr));
|
||||
bool MatchExpr(BaseModifier bm) => bm is T modifier && (predicate == null || predicate(modifier));
|
||||
bool MatchExpr(BaseModifier bm)
|
||||
{
|
||||
return bm is T modifier && (predicate == null || predicate(modifier));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -550,10 +544,13 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
/// <param name="predicate">The predicate to check the <see cref="BaseModifier"/>.</param>
|
||||
/// <returns><see langword="true"/> if the <see cref="BaseModifier"/> is present, <see langword="false"/> otherwise.</returns>
|
||||
[HideFromIl2Cpp]
|
||||
public bool HasModifier(Type type, bool checkInactive, Func<BaseModifier, bool>? predicate=null)
|
||||
public bool HasModifier(Type type, bool checkInactive, Func<BaseModifier, bool>? predicate = null)
|
||||
{
|
||||
return ActiveModifiers.Exists(MatchExpr) || (checkInactive && _toAdd.Exists(MatchExpr));
|
||||
bool MatchExpr(BaseModifier bm) => bm.GetType() == type && (predicate == null || predicate(bm));
|
||||
bool MatchExpr(BaseModifier bm)
|
||||
{
|
||||
return bm.GetType() == type && (predicate == null || predicate(bm));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -564,7 +561,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
/// <param name="predicate">The predicate to check the <see cref="BaseModifier"/>.</param>
|
||||
/// <returns><see langword="true"/> if the <see cref="BaseModifier"/> is present, <see langword="false"/> otherwise.</returns>
|
||||
[HideFromIl2Cpp]
|
||||
public bool HasModifier(uint id, bool checkInactive, Func<BaseModifier, bool>? predicate=null)
|
||||
public bool HasModifier(uint id, bool checkInactive, Func<BaseModifier, bool>? predicate = null)
|
||||
{
|
||||
var type = ModifierManager.GetModifierType(id) ?? throw new InvalidOperationException(
|
||||
$"Cannot get modifier with id {id} because it is not registered.");
|
||||
@@ -582,6 +579,9 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
public bool HasModifier(Guid id, bool checkInactive)
|
||||
{
|
||||
return ActiveModifiers.Exists(MatchExpr) || (checkInactive && _toAdd.Exists(MatchExpr));
|
||||
bool MatchExpr(BaseModifier bm) => bm.UniqueId == id;
|
||||
bool MatchExpr(BaseModifier bm)
|
||||
{
|
||||
return bm.UniqueId == id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
@@ -18,6 +19,7 @@ namespace MiraAPI.Modifiers.ModifierDisplay;
|
||||
/// The code used to display <see cref="BaseModifier"/>s.
|
||||
/// </summary>
|
||||
[RegisterInIl2Cpp]
|
||||
[SuppressMessage("Style", "IDE0051:Remove unused private members", Justification = "Unity Convention.")]
|
||||
public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -9,6 +10,7 @@ namespace MiraAPI.Modifiers.ModifierDisplay;
|
||||
/// The code placed on every <see cref="BaseModifier"/> HUD object. Used to handle updating.
|
||||
/// </summary>
|
||||
[RegisterInIl2Cpp]
|
||||
[SuppressMessage("Style", "IDE0051:Remove unused private members", Justification = "Unity Convention.")]
|
||||
public class ModifierUiComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -57,12 +57,7 @@ public static class ModifierManager
|
||||
/// <returns>The ID of the modifier.</returns>
|
||||
public static uint? GetModifierTypeId(Type type)
|
||||
{
|
||||
if (!TypeToIdModifierMap.TryGetValue(type, out var id))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return id;
|
||||
return !TypeToIdModifierMap.TryGetValue(type, out var id) ? null : id;
|
||||
}
|
||||
|
||||
internal static bool RegisterModifier(Type modifierType, MiraPluginInfo info)
|
||||
@@ -121,7 +116,7 @@ public static class ModifierManager
|
||||
|
||||
// Filter and sort modifiers by descending priority.
|
||||
var modifiers = IdToTypeModifierMap
|
||||
.Where(x=>x.Value.IsAssignableTo(typeof(GameModifier)))
|
||||
.Where(x => x.Value.IsAssignableTo(typeof(GameModifier)))
|
||||
.Select(x => Activator.CreateInstance(x.Value) as GameModifier)
|
||||
.OfType<GameModifier>()
|
||||
.Where(x => x.GetAmountPerGame() > 0 && x.GetAssignmentChance() > 0)
|
||||
|
||||
@@ -24,32 +24,47 @@ public abstract class GameModifier : BaseModifier
|
||||
/// Gets the priority at which the modifier will spawn. The higher the value, the higher up on the assignment list.
|
||||
/// </summary>
|
||||
/// <returns>An <see langword="int"/> value greater than or equal to -1.</returns>
|
||||
public virtual int Priority() => -1;
|
||||
public virtual int Priority()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the modifier is valid on a role.
|
||||
/// </summary>
|
||||
/// <param name="role">The role to be checked.</param>
|
||||
/// <returns><see langword="true"/> if the modifier is valid on the role, otherwise <see langword="false"/>.</returns>
|
||||
public virtual bool IsModifierValidOn(RoleBehaviour role) => true;
|
||||
public virtual bool IsModifierValidOn(RoleBehaviour role)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the modifier is valid on a role, which runs after players are determined but before the modifiers are given.
|
||||
/// </summary>
|
||||
/// <param name="role">The role to be checked.</param>
|
||||
/// <returns><see langword="true"/> if the modifier is valid on the role, otherwise <see langword="false"/>.</returns>
|
||||
public virtual bool IsModifierValidOnPostCheck(RoleBehaviour role) => IsModifierValidOn(role);
|
||||
public virtual bool IsModifierValidOnPostCheck(RoleBehaviour role)
|
||||
{
|
||||
return IsModifierValidOn(role);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the player won the game with this modifier. The modifier with the highest priority will override other modifiers.
|
||||
/// </summary>
|
||||
/// <param name="reason">The reason why the game ended.</param>
|
||||
/// <returns><see langword="true"/> if the player won, <see langword="false"/> if they lost. Return <see langword="null"/> to use the player's default win condition.</returns>
|
||||
public virtual bool? DidWin(GameOverReason reason) => null;
|
||||
public virtual bool? DidWin(GameOverReason reason)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the modifier can spawn in general, accounting for gamemodes and everything else.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> if the modifier is able to spawn, otherwise <see langword="false"/>.</returns>
|
||||
public virtual bool CanSpawnOnCurrentMode() => !GameManager.Instance.IsHideAndSeek();
|
||||
public virtual bool CanSpawnOnCurrentMode()
|
||||
{
|
||||
return !GameManager.Instance.IsHideAndSeek();
|
||||
}
|
||||
}
|
||||
@@ -57,19 +57,10 @@ public class AddModifierRpc(MiraApiPlugin plugin, uint id) : PlayerCustomRpc<Mir
|
||||
public override void Handle(PlayerControl player, ModifierData data)
|
||||
{
|
||||
var type = ModifierManager.GetModifierType(data.TypeId) ?? throw new InvalidOperationException($"Modifier type not found for ID {data.TypeId}.");
|
||||
BaseModifier? modifier;
|
||||
if (data.Args.Length > 0)
|
||||
{
|
||||
modifier = ModifierFactory.CreateInstance(type, data.Args);
|
||||
}
|
||||
else
|
||||
{
|
||||
modifier = Activator.CreateInstance(type) as BaseModifier;
|
||||
if (modifier == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot add modifier {type.Name} because it is not a valid modifier.");
|
||||
}
|
||||
}
|
||||
var modifier = data.Args.Length > 0
|
||||
? ModifierFactory.CreateInstance(type, data.Args)
|
||||
: Activator.CreateInstance(type) as BaseModifier
|
||||
?? throw new InvalidOperationException($"Cannot add modifier {type.Name} because it is not a valid modifier.");
|
||||
modifier.UniqueId = data.UniqueId;
|
||||
player.AddModifier(modifier);
|
||||
}
|
||||
|
||||
@@ -21,5 +21,8 @@ public readonly struct NetData(uint id, byte[] data)
|
||||
/// Gets the length of the data in bytes.
|
||||
/// </summary>
|
||||
/// <returns>An int representing the number of bytes this NetData takes up.</returns>
|
||||
public int GetLength() => 4 + Data.Length;
|
||||
public int GetLength()
|
||||
{
|
||||
return 4 + Data.Length;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 167 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user