From 1daffd75609012964eef5f31a7be86fa642d3b4d Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Thu, 22 Oct 2026 21:15:57 -0400 Subject: [PATCH] code ordering and cleanup --- .editorconfig | 3 + MiraAPI.Example/ExampleEventHandlers.cs | 4 +- MiraAPI/Events/MiraEventManager.cs | 4 +- MiraAPI/Modifiers/ModifierComponent.cs | 8 +-- MiraAPI/Modifiers/Types/GameModifier.cs | 3 +- MiraAPI/Networking/CustomMurderRpc.cs | 4 +- MiraAPI/Patches/Freeplay/TaskAdderPatches.cs | 6 +- MiraAPI/PluginLoading/MiraPluginInfo.cs | 72 +++++++++----------- MiraAPI/PluginLoading/MiraPluginManager.cs | 4 +- MiraAPI/Utilities/Extensions.cs | 17 ++++- 10 files changed, 68 insertions(+), 57 deletions(-) diff --git a/.editorconfig b/.editorconfig index 6daa6a7..2847fc2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -104,3 +104,6 @@ dotnet_diagnostic.S1244.severity = none # S2325: Methods and properties that don't access instance data should be static dotnet_diagnostic.S2325.severity = none + +# IDE0005: Using directive is unnecessary. +dotnet_diagnostic.IDE0005.severity = warning diff --git a/MiraAPI.Example/ExampleEventHandlers.cs b/MiraAPI.Example/ExampleEventHandlers.cs index 20c0def..c14710a 100644 --- a/MiraAPI.Example/ExampleEventHandlers.cs +++ b/MiraAPI.Example/ExampleEventHandlers.cs @@ -31,7 +31,7 @@ public static class ExampleEventHandlers MiraEventManager.RegisterEventHandler(@event => { - Logger.Info($"{@event.Player.Data.PlayerName} completed {@event.Task.TaskType.ToString()}"); + Logger.Info($"{@event.Player.Data.PlayerName} completed {@event.Task.TaskType}"); }); // You can also unregister event handlers using the handle returned from RegisterEventHandler. @@ -89,7 +89,7 @@ public static class ExampleEventHandlers [RegisterEvent] public static void UpdateSystemEventHandler(UpdateSystemEvent @event) { - Logger.Error(@event.SystemType.ToString()); + Logger.Error(@event.SystemType); } // Example event handler diff --git a/MiraAPI/Events/MiraEventManager.cs b/MiraAPI/Events/MiraEventManager.cs index 066ef74..a8b34f1 100644 --- a/MiraAPI/Events/MiraEventManager.cs +++ b/MiraAPI/Events/MiraEventManager.cs @@ -35,7 +35,7 @@ public static class MiraEventManager } catch (Exception ex) { - Error($"Error invoking event handler for {typeof(T).Name}: {ex.ToString()}"); + Error($"Error invoking event handler for {typeof(T).Name}: {ex}"); } } @@ -65,7 +65,7 @@ public static class MiraEventManager } catch (Exception ex) { - Error($"Error invoking event handler for {type.Name}: {ex.ToString()}"); + Error($"Error invoking event handler for {type.Name}: {ex}"); } } diff --git a/MiraAPI/Modifiers/ModifierComponent.cs b/MiraAPI/Modifiers/ModifierComponent.cs index aeebfa2..9953892 100644 --- a/MiraAPI/Modifiers/ModifierComponent.cs +++ b/MiraAPI/Modifiers/ModifierComponent.cs @@ -77,7 +77,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr) } catch (Exception e) { - Error($"Error while deactivating modifier {modifier.ModifierName}: {e.ToString()}"); + Error($"Error while deactivating modifier {modifier.ModifierName}: {e}"); } Modifiers.Remove(modifier); @@ -95,7 +95,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr) } catch (Exception e) { - Error($"Error while activating modifier {modifier.ModifierName}: {e.ToString()}"); + Error($"Error while activating modifier {modifier.ModifierName}: {e}"); } if (modifier is TimedModifier { AutoStart: true } timer) @@ -122,7 +122,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr) } catch (Exception e) { - Error($"Error while (fixed) updating modifier {modifier.ModifierName}: {e.ToString()}"); + Error($"Error while (fixed) updating modifier {modifier.ModifierName}: {e}"); } } @@ -153,7 +153,7 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr) } catch (Exception e) { - Error($"Error while updating modifier {modifier.ModifierName}: {e.ToString()}"); + Error($"Error while updating modifier {modifier.ModifierName}: {e}"); } } } diff --git a/MiraAPI/Modifiers/Types/GameModifier.cs b/MiraAPI/Modifiers/Types/GameModifier.cs index 4f0b088..b432920 100644 --- a/MiraAPI/Modifiers/Types/GameModifier.cs +++ b/MiraAPI/Modifiers/Types/GameModifier.cs @@ -1,5 +1,4 @@ -using System.Globalization; -using MiraAPI.GameModes; +using MiraAPI.GameModes; using MiraAPI.PluginLoading; namespace MiraAPI.Modifiers.Types; diff --git a/MiraAPI/Networking/CustomMurderRpc.cs b/MiraAPI/Networking/CustomMurderRpc.cs index 4be8723..8a5a701 100644 --- a/MiraAPI/Networking/CustomMurderRpc.cs +++ b/MiraAPI/Networking/CustomMurderRpc.cs @@ -571,7 +571,7 @@ public static class CustomMurderRpc } catch (Exception e) { - Error($"Error with kill animation: {e.ToString()}"); + Error($"Error with kill animation: {e}"); } } @@ -705,7 +705,7 @@ public static class CustomMurderRpc } catch (Exception e) { - Error($"Error with kill animation: {e.ToString()}"); + Error($"Error with kill animation: {e}"); } } diff --git a/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs b/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs index 7db4211..6a97687 100644 --- a/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs +++ b/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs @@ -186,9 +186,11 @@ public static class TaskAdderPatches systemTypes = SystemTypes.UpperEngine; } - if (!folders.TryGetValue(systemTypes.ToString(), out var taskFolder3)) + var systemType = systemTypes.ToString(); + + if (!folders.TryGetValue(systemType, out var taskFolder3)) { - taskFolder3 = folders[systemTypes.ToString()] = Object.Instantiate(__instance.RootFolderPrefab, __instance.transform); + taskFolder3 = folders[systemType] = Object.Instantiate(__instance.RootFolderPrefab, __instance.transform); taskFolder3.SetFolderColor(TaskFolder.FolderColor.Tan); taskFolder3.gameObject.SetActive(false); taskFolder3.FolderName = systemTypes == SystemTypes.UpperEngine diff --git a/MiraAPI/PluginLoading/MiraPluginInfo.cs b/MiraAPI/PluginLoading/MiraPluginInfo.cs index d1b5d51..ca7812c 100644 --- a/MiraAPI/PluginLoading/MiraPluginInfo.cs +++ b/MiraAPI/PluginLoading/MiraPluginInfo.cs @@ -25,6 +25,26 @@ public class MiraPluginInfo PluginId = info.Metadata.GUID; } + /// + /// Gets the plugin's ID, as defined in the plugin's BepInEx metadata. + /// + public string PluginId { get; } + + /// + /// Gets the plugin's instance as an . + /// + public IMiraPlugin MiraPlugin { get; } + + /// + /// Gets the plugin's BepInEx metadata. + /// + public PluginInfo PluginInfo { get; } + + /// + /// Gets the plugin's . + /// + public ConfigFile PluginConfig { get; } + /// /// Gets a of this 's s. This is not safe for s with constructors. /// @@ -45,15 +65,6 @@ public class MiraPluginInfo /// public ReadOnlyDictionary Roles { get; private set; } = null!; - /// - /// Gets a read only dictionary of Game Mode IDs and the AbstractGameMode object they are associated with. - /// - /// Read only dictionary of IDs and Game Modes. - public ReadOnlyDictionary GetModes() - { - return new ReadOnlyDictionary(GameModes); - } - /// /// Gets a of this 's . /// @@ -74,6 +85,15 @@ public class MiraPluginInfo /// public IReadOnlyCollection Presets { get; internal set; } = null!; + /// + /// Gets a read only dictionary of Game Mode IDs and the AbstractGameMode object they are associated with. + /// + /// Read only dictionary of IDs and Game Modes. + public ReadOnlyDictionary GetModes() + { + return new ReadOnlyDictionary(GameModes); + } + internal void SavePublicCollections() { Presets = [.. InternalPresets]; @@ -87,39 +107,13 @@ public class MiraPluginInfo } internal List InternalPresets { get; } = []; - - internal List InternalOptionGroups { get; } = []; - internal List InternalOptions { get; } = []; - internal List InternalModifiers { get; } = []; + internal List InternalButtons { get; } = []; + internal List InternalOptionGroups { get; } = []; + internal List InternalMeetingButtons { get; } = []; + internal List InternalTargetedMeetingButtons { get; } = []; internal Dictionary GameModes { get; } = []; internal Dictionary InternalRoles { get; } = []; - - internal List InternalButtons { get; } = []; - - internal List InternalTargetedMeetingButtons { get; } = []; - - internal List InternalMeetingButtons { get; } = []; - - /// - /// Gets the plugin's ID, as defined in the plugin's BepInEx metadata. - /// - public string PluginId { get; } - - /// - /// Gets the plugin's instance as an . - /// - public IMiraPlugin MiraPlugin { get; } - - /// - /// Gets the plugin's BepInEx metadata. - /// - public PluginInfo PluginInfo { get; } - - /// - /// Gets the plugin's . - /// - public ConfigFile PluginConfig { get; } } diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index f021c3f..ed1776e 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -358,7 +358,7 @@ public sealed class MiraPluginManager } catch (Exception e) { - Error($"Failed to register options for {type.Name}: {e.ToString()}"); + Error($"Failed to register options for {type.Name}: {e}"); } return false; @@ -543,7 +543,7 @@ public sealed class MiraPluginManager } catch (Exception e) { - Error($"Failed to register options for {type.Name}: {e.ToString()}"); + Error($"Failed to register options for {type.Name}: {e}"); } return false; diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs index 21112f6..57fcd1a 100644 --- a/MiraAPI/Utilities/Extensions.cs +++ b/MiraAPI/Utilities/Extensions.cs @@ -492,16 +492,29 @@ public static class Extensions } /// - /// Gets a proper string for an . (with spaces). + /// Gets a proper string for an (with spaces). /// /// The you would like to change. - /// A proper string for the . + /// A proper string for the provided . public static string ToDisplayString(this Enum @enum) { var regex = new Regex(@"([^\^])([A-Z][a-z$])", default, Regex.InfiniteMatchTimeout); return regex.Replace(@enum.ToString(), m => $"{m.Groups[1].Value} {m.Groups[2].Value}"); } + /// + /// Gets a proper string for a(n) value (with spaces). + /// + /// The type of the enum value. + /// The enum value you would like to change. + /// A proper string for the provided value. + public static string ToDisplayString(this T @enum) + where T : struct, Enum + { + var regex = new Regex(@"([^\^])([A-Z][a-z$])", default, Regex.InfiniteMatchTimeout); + return regex.Replace(@enum.ToString(), m => $"{m.Groups[1].Value} {m.Groups[2].Value}"); + } + /// /// Gets the constructors of a type that match the specified arguments. ///