diff --git a/.editorconfig b/.editorconfig
index 20f92823..52a6d992 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -110,3 +110,6 @@ dotnet_diagnostic.CA1710.severity = silent
# CA1010: Generic interface should also be implemented
dotnet_diagnostic.CA1010.severity = silent
+
+# IDE0005: Using directive is unnecessary.
+dotnet_diagnostic.IDE0005.severity = warning
diff --git a/Directory.Build.props b/Directory.Build.props
index 4bdcab7b..8e2a2e36 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -8,7 +8,7 @@
true
- 0.5.0
+ 0.6.0
dev
All Of Us, XtraCube, Angxl
diff --git a/MiraAPI.Example/ExampleAssets.cs b/MiraAPI.Example/ExampleAssets.cs
index b0ca484e..fbf5e1b9 100644
--- a/MiraAPI.Example/ExampleAssets.cs
+++ b/MiraAPI.Example/ExampleAssets.cs
@@ -1,14 +1,17 @@
-using MiraAPI.Utilities.Assets;
+using System.Reflection;
+using MiraAPI.Utilities.Assets;
namespace MiraAPI.Example;
public static class ExampleAssets
{
- public static LoadableResourceAsset ExampleButton { get; } = new("MiraAPI.Example.Resources.ExampleButton.png");
- public static LoadableResourceAsset CallMeetingButton { get; } = new("MiraAPI.Example.Resources.CallMeeting.png");
+ private static readonly Assembly _assembly = typeof(MiraAssets).Assembly;
+
+ public static LoadableResourceAsset ExampleButton { get; } = new("MiraAPI.Example.Resources.ExampleButton.png", _assembly);
+ public static LoadableResourceAsset CallMeetingButton { get; } = new("MiraAPI.Example.Resources.CallMeeting.png", _assembly);
// Credit to EpicHorrors for the teleport button asset.
- public static LoadableResourceAsset TeleportButton { get; } = new("MiraAPI.Example.Resources.TeleportButton.png");
- public static LoadableResourceAsset SharpshootButton { get; } = new("MiraAPI.Example.Resources.SharpshootButton.png");
- public static LoadableResourceAsset Banner { get; } = new("MiraAPI.Example.Resources.FortniteBanner.jpeg");
+ public static LoadableResourceAsset TeleportButton { get; } = new("MiraAPI.Example.Resources.TeleportButton.png", _assembly);
+ public static LoadableResourceAsset SharpshootButton { get; } = new("MiraAPI.Example.Resources.SharpshootButton.png", _assembly);
+ public static LoadableResourceAsset Banner { get; } = new("MiraAPI.Example.Resources.FortniteBanner.jpeg", _assembly);
}
diff --git a/MiraAPI.Example/ExampleEventHandlers.cs b/MiraAPI.Example/ExampleEventHandlers.cs
index 20c0def5..c14710a9 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 066ef745..a8b34f16 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/GameOptions/OptionTypes/ModdedEnumOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs
index 2f209b58..1fa3245c 100644
--- a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs
+++ b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs
@@ -103,6 +103,7 @@ public class ModdedEnumOption : ModdedOption
Configuration.PopUpIconTmp,
false);
}
+
if (!OptionBehaviour)
{
return;
diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs
index 3aa3bb52..5def08da 100644
--- a/MiraAPI/MiraApiPlugin.cs
+++ b/MiraAPI/MiraApiPlugin.cs
@@ -102,7 +102,7 @@ public partial class MiraApiPlugin : BasePlugin, IMiraPlugin
PluginManager = new MiraPluginManager();
PluginManager.Initialize(this, this);
- MiraLocaleManager.Register("mira.api");
+ MiraLocaleManager.Register("mira.api", typeof(MiraApiPlugin).Assembly);
LocalizationManager.Register(new MiraLocalizationProvider());
IL2CPPChainloader.Instance.Finished +=
diff --git a/MiraAPI/Modifiers/ModifierComponent.cs b/MiraAPI/Modifiers/ModifierComponent.cs
index aeebfa28..99538929 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 4f0b0883..b4329203 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 4be87235..8a5a701a 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/Events/CanUsePatches.cs b/MiraAPI/Patches/Events/CanUsePatches.cs
index 7af9acd2..f99d2b90 100644
--- a/MiraAPI/Patches/Events/CanUsePatches.cs
+++ b/MiraAPI/Patches/Events/CanUsePatches.cs
@@ -3,6 +3,7 @@ using System.Reflection;
using HarmonyLib;
using MiraAPI.Events;
using MiraAPI.Events.Vanilla.Usables;
+using UnityEngine;
namespace MiraAPI.Patches.Events;
@@ -27,7 +28,7 @@ public static class CanUsePatches
[HarmonyPriority(Priority.Last)]
[HarmonyPrefix]
- public static bool CanUsePatch(Il2CppSystem.Object __instance, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse)
+ public static bool CanUsePatch(MonoBehaviour __instance, [HarmonyArgument(1)] out bool canUse, [HarmonyArgument(2)] out bool couldUse)
{
canUse = couldUse = false;
diff --git a/MiraAPI/Patches/Events/UsePatches.cs b/MiraAPI/Patches/Events/UsePatches.cs
index a6c4b1d4..4d783f39 100644
--- a/MiraAPI/Patches/Events/UsePatches.cs
+++ b/MiraAPI/Patches/Events/UsePatches.cs
@@ -3,6 +3,7 @@ using System.Reflection;
using HarmonyLib;
using MiraAPI.Events;
using MiraAPI.Events.Vanilla.Usables;
+using UnityEngine;
namespace MiraAPI.Patches.Events;
@@ -25,7 +26,7 @@ public static class UsePatches
[HarmonyPriority(Priority.Last)]
[HarmonyPrefix]
- public static bool UsePatch(Il2CppSystem.Object __instance)
+ public static bool UsePatch(MonoBehaviour __instance)
{
var @event = new PlayerUseEvent(__instance.Cast());
MiraEventManager.InvokeEvent(@event);
diff --git a/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs b/MiraAPI/Patches/Freeplay/TaskAdderPatches.cs
index 7db4211c..6a97687f 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 d1b5d515..ca7812cd 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 2874c7d9..0de516eb 100644
--- a/MiraAPI/PluginLoading/MiraPluginManager.cs
+++ b/MiraAPI/PluginLoading/MiraPluginManager.cs
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
+using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
@@ -24,7 +25,6 @@ using MiraAPI.Roles;
using MiraAPI.Translation;
using MiraAPI.Utilities;
using Reactor.Networking;
-using Reactor.Utilities;
namespace MiraAPI.PluginLoading;
@@ -49,100 +49,14 @@ public sealed class MiraPluginManager
Instance = this;
CustomGameModeManager.RegisterDefaultMode();
CustomGameModeManager.GetAndSetGameMode();
+
if (IL2CPPChainloader.Instance.Plugins.TryGetValue(MiraApiPlugin.Id, out var newPlugin))
{
- var assembly = Assembly.GetCallingAssembly();
- var info = new MiraPluginInfo(apiPlugin, newPlugin);
- var roles = new List();
+ var info = RegisterPlugin(typeof(MiraPluginManager).Assembly, apiPlugin, newPlugin, miraApiPlugin, true);
- var oldConfigSetting = info.PluginConfig.SaveOnConfigSet;
- info.PluginConfig.SaveOnConfigSet = false;
-
- foreach (var type in assembly.GetTypes())
- {
- if (type.IsAbstract || type.GetCustomAttribute() != null)
- {
- continue;
- }
-
- foreach (var method in AccessTools.GetDeclaredMethods(type))
- {
- var eventAttribute = method.GetCustomAttribute();
- if (eventAttribute == null)
- {
- continue;
- }
-
- if (!method.IsStatic)
- {
- Error($"Event method {method.Name} in {type.Name} must be static.");
- continue;
- }
-
- var parameters = method.GetParameters();
- if (parameters.Length != 1 || !parameters[0].ParameterType.IsSubclassOf(typeof(MiraEvent)))
- {
- Error($"Invalid event registration method {method.Name} in {type.Name}");
- continue;
- }
-
- var paramType = parameters[0].ParameterType;
- MiraEventManager.RegisterEventHandler(paramType, method, eventAttribute.Priority);
- }
-
- if (RegisterModifier(type, info))
- {
- continue;
- }
-
- if (RegisterOptions(type, info))
- {
- continue;
- }
-
- if (RegisterLocalTabs(type, miraApiPlugin))
- {
- continue;
- }
-
- if (RegisterRole(type, info, out var role))
- {
- roles.Add(role);
- continue;
- }
-
- if (RegisterButton(type, info))
- {
- continue;
- }
-
- if (RegisterGameOver(type))
- {
- continue;
- }
-
- if (RegisterGameModeAttribute(type, info))
- {
- continue;
- }
-
- RegisterColorClasses(type);
- RegisterKeybinds(type, miraApiPlugin);
- }
-
- info.PluginConfig.Save();
- info.PluginConfig.SaveOnConfigSet = oldConfigSetting;
MiraApiConfig = info.PluginConfig;
-
- info.InternalOptionGroups.Sort((x, y) => x.GroupPriority.CompareTo(y.GroupPriority));
- QueuedRoleRegistrations.Add(info, roles);
-
- _registeredPlugins.Add(assembly, info);
MiraApiPluginInfo = info;
- info.SavePublicCollections();
- PresetManager.CreateDefaultPreset(info);
- PresetManager.LoadPresets(info);
Info($"Registering Mira API as mod.");
}
@@ -153,110 +67,14 @@ public sealed class MiraPluginManager
return;
}
- var info = new MiraPluginInfo(miraPlugin, pluginInfo);
- var roles = new List();
-
- var oldConfigSetting = info.PluginConfig.SaveOnConfigSet;
- info.PluginConfig.SaveOnConfigSet = false;
-
- foreach (var type in assembly.GetTypes())
- {
- if (type.GetCustomAttribute() != null)
- {
- continue;
- }
-
- foreach (var method in AccessTools.GetDeclaredMethods(type))
- {
- var eventAttribute = method.GetCustomAttribute();
- if (eventAttribute == null)
- {
- continue;
- }
-
- if (!method.IsStatic)
- {
- Error($"Event method {method.Name} in {type.Name} must be static.");
- continue;
- }
-
- var parameters = method.GetParameters();
- if (parameters.Length != 1 || !parameters[0].ParameterType.IsSubclassOf(typeof(MiraEvent)))
- {
- Error($"Invalid event registration method {method.Name} in {type.Name}");
- continue;
- }
-
- var paramType = parameters[0].ParameterType;
- MiraEventManager.RegisterEventHandler(paramType, method, eventAttribute.Priority);
- }
-
- if (RegisterModifier(type, info))
- {
- continue;
- }
-
- if (RegisterOptions(type, info))
- {
- continue;
- }
-
- if (RegisterLocalTabs(type, plugin))
- {
- continue;
- }
-
- if (RegisterRole(type, info, out var role))
- {
- roles.Add(role);
- continue;
- }
-
- if (RegisterButton(type, info))
- {
- continue;
- }
-
- if (RegisterGameOver(type))
- {
- continue;
- }
-
- if (RegisterMeetingAbility(type, info))
- {
- continue;
- }
-
- if (RegisterTargetedMeetingAbility(type, info))
- {
- continue;
- }
-
- if (RegisterGameModeAttribute(type, info))
- {
- continue;
- }
-
- RegisterColorClasses(type);
- RegisterKeybinds(type, plugin);
- }
-
- info.PluginConfig.Save();
- info.PluginConfig.SaveOnConfigSet = oldConfigSetting;
-
- info.InternalOptionGroups.Sort((x, y) => x.GroupPriority.CompareTo(y.GroupPriority));
- QueuedRoleRegistrations.Add(info, roles);
-
- _registeredPlugins.Add(assembly, info);
-
- info.SavePublicCollections();
- PresetManager.CreateDefaultPreset(info);
- PresetManager.LoadPresets(info);
+ RegisterPlugin(assembly, miraPlugin, pluginInfo, plugin, false);
Info($"Registering mod {pluginInfo.Metadata.GUID} with Mira API.");
};
- IL2CPPChainloader.Instance.Finished += PaletteManager.RegisterAllColors;
+
IL2CPPChainloader.Instance.Finished += () =>
{
+ PaletteManager.RegisterAllColors();
+
// Save all buttons into a read-only collection for easy access
CustomButtonManager.Buttons = new ReadOnlyCollection(CustomButtonManager.CustomButtons);
CustomButtonManager.EventTypes = new ReadOnlyDictionary(CustomButtonManager.ButtonEventTypes);
@@ -269,9 +87,101 @@ public sealed class MiraPluginManager
ModifierManager.Modifiers = new ReadOnlyCollection(ModifierManager.InternalModifiers);
};
+ }
- RegisterKeybinds(typeof(MiraGlobalKeybinds), PluginSingleton.Instance);
- RegisterLocalTabs(typeof(MiraApiSettings), PluginSingleton.Instance);
+ private MiraPluginInfo RegisterPlugin(Assembly assembly, IMiraPlugin plugin, PluginInfo pluginInfo, BasePlugin basePlugin, bool isMira)
+ {
+ var info = new MiraPluginInfo(plugin, pluginInfo);
+ var roles = new List();
+
+ var oldConfigSetting = info.PluginConfig.SaveOnConfigSet;
+ info.PluginConfig.SaveOnConfigSet = false;
+
+ ProcessAssemblyTypes(assembly, info, basePlugin, roles, isMira);
+
+ info.PluginConfig.Save();
+ info.PluginConfig.SaveOnConfigSet = oldConfigSetting;
+
+ info.InternalOptionGroups.Sort((x, y) => x.GroupPriority.CompareTo(y.GroupPriority));
+ QueuedRoleRegistrations.Add(info, roles);
+ _registeredPlugins.Add(assembly, info);
+
+ info.SavePublicCollections();
+ PresetManager.CreateDefaultPreset(info);
+ PresetManager.LoadPresets(info);
+
+ return info;
+ }
+
+ private static void ProcessAssemblyTypes(Assembly assembly, MiraPluginInfo info, BasePlugin basePlugin, List roles, bool isMira)
+ {
+ foreach (var type in assembly.GetTypes())
+ {
+ if ((isMira && type.IsAbstract) || type.GetCustomAttribute() != null)
+ continue;
+
+ RegisterEvents(type);
+
+ if (RegisterModifier(type, info))
+ continue;
+
+ if (RegisterOptions(type, info))
+ continue;
+
+ if (RegisterLocalTabs(type, basePlugin))
+ continue;
+
+ if (RegisterRole(type, info, out var role))
+ {
+ roles.Add(role);
+ continue;
+ }
+
+ if (RegisterButton(type, info))
+ continue;
+
+ if (RegisterGameOver(type))
+ continue;
+
+ if (RegisterMeetingAbility(type, info))
+ continue;
+
+ if (RegisterTargetedMeetingAbility(type, info))
+ continue;
+
+ if (RegisterGameModeAttribute(type, info))
+ continue;
+
+ RegisterColorClasses(type);
+ RegisterKeybinds(type, basePlugin);
+ }
+ }
+
+ private static void RegisterEvents(Type type)
+ {
+ foreach (var method in AccessTools.GetDeclaredMethods(type))
+ {
+ var eventAttribute = method.GetCustomAttribute();
+
+ if (eventAttribute == null)
+ continue;
+
+ if (!method.IsStatic)
+ {
+ Error($"Event method {method.Name} in {type.Name} must be static.");
+ continue;
+ }
+
+ var parameters = method.GetParameters();
+ if (parameters.Length != 1 || !parameters[0].ParameterType.IsSubclassOf(typeof(MiraEvent)))
+ {
+ Error($"Invalid event registration method {method.Name} in {type.Name}");
+ continue;
+ }
+
+ var paramType = parameters[0].ParameterType;
+ MiraEventManager.RegisterEventHandler(paramType, method, eventAttribute.Priority);
+ }
}
///
@@ -358,7 +268,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 +453,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/Translation/MiraLocaleManager.cs b/MiraAPI/Translation/MiraLocaleManager.cs
index 0bce8ca0..1bd925df 100644
--- a/MiraAPI/Translation/MiraLocaleManager.cs
+++ b/MiraAPI/Translation/MiraLocaleManager.cs
@@ -72,6 +72,7 @@ public static class MiraLocaleManager
///
public static Dictionary LangCultureList { get; } = new()
{
+ // Vanilla
{ MiraLanguage.English, "en-US" },
{ MiraLanguage.Latam, "es-419" },
{ MiraLanguage.Brazilian, "pt-BR" },
@@ -88,15 +89,17 @@ public static class MiraLocaleManager
{ MiraLanguage.SChinese, "zh-CN" },
{ MiraLanguage.TChinese, "zh-TW" },
{ MiraLanguage.Irish, "ga-IE" },
- { MiraLanguage.Polish, "pl-PL" }, // Custom
- { MiraLanguage.Turkish, "tr-TR" }, // Custom
- { MiraLanguage.Swedish, "sv-SE" }, // Custom
- { MiraLanguage.Lithuanian, "lt-LT" }, // Custom
- { MiraLanguage.Czech, "cs-CZ" }, // Custom
- { MiraLanguage.LChinese, "lzh-CN" }, // Custom
- { MiraLanguage.Greek, "el-GR" }, // Custom
- { MiraLanguage.Arabic, "arb" }, // Custom
- { MiraLanguage.Hebrew, "heb" }, // Custom
+
+ // Custom
+ { MiraLanguage.Polish, "pl-PL" },
+ { MiraLanguage.Turkish, "tr-TR" },
+ { MiraLanguage.Swedish, "sv-SE" },
+ { MiraLanguage.Lithuanian, "lt-LT" },
+ { MiraLanguage.Czech, "cs-CZ" },
+ { MiraLanguage.LChinese, "lzh-CN" },
+ { MiraLanguage.Greek, "el-GR" },
+ { MiraLanguage.Arabic, "arb" },
+ { MiraLanguage.Hebrew, "heb" },
};
///
@@ -123,26 +126,49 @@ public static class MiraLocaleManager
/// Call once per mod during plugin Load().
///
/// The mod GUID (e.g., "mira.example").
+ [Obsolete("Pass typeof(YourPlugin).Assembly directly to Register for better performance.")]
public static void Register(string modGuid)
{
var callingAssembly = Assembly.GetCallingAssembly();
-
LoadInternalStrings(callingAssembly, callingAssembly.GetName().Name!, modGuid);
}
+ ///
+ /// Registers translations for a mod.
+ /// Call once per mod during plugin Load().
+ ///
+ /// The mod GUID (e.g., "mira.example").
+ /// The to load the strings from.
+ public static void Register(string modGuid, Assembly assembly)
+ {
+ LoadInternalStrings(assembly, assembly.GetName().Name!, modGuid);
+ }
+
///
/// Registers translations for a mod.
/// Call once per mod during plugin Load().
///
/// The mod GUID (e.g., "mira.example").
/// The mod's root namespace (e.g., "mira.api").
+ [Obsolete("Pass typeof(YourPlugin).Assembly directly to Register for better performance.")]
public static void Register(string modGuid, string internalName)
{
var callingAssembly = Assembly.GetCallingAssembly();
-
LoadInternalStrings(callingAssembly, internalName, modGuid);
}
+ ///
+ /// Registers translations for a mod.
+ /// Call once per mod during plugin Load().
+ ///
+ /// The mod GUID (e.g., "mira.example").
+ /// The mod's root namespace (e.g., "mira.api").
+ /// The to load the strings from.
+ public static void Register(string modGuid, string internalName, Assembly assembly)
+ {
+ LoadInternalStrings(assembly, internalName, modGuid);
+ }
+
///
/// Translates a key into the current language.
///
diff --git a/MiraAPI/Utilities/Assets/LoadableAudioResourceAsset.cs b/MiraAPI/Utilities/Assets/LoadableAudioResourceAsset.cs
index 49529a55..164a3c78 100644
--- a/MiraAPI/Utilities/Assets/LoadableAudioResourceAsset.cs
+++ b/MiraAPI/Utilities/Assets/LoadableAudioResourceAsset.cs
@@ -1,3 +1,4 @@
+using System;
using System.Reflection;
using UnityEngine;
@@ -6,17 +7,39 @@ namespace MiraAPI.Utilities.Assets;
///
/// A utility class for loading .WAV audio assets from the DLL's embedded resources.
///
-/// The path of the wave file.
-public class LoadableAudioResourceAsset(string path) : LoadableAsset
+public class LoadableAudioResourceAsset : LoadableAsset
{
- private readonly Assembly _assembly = Assembly.GetCallingAssembly();
+ private readonly string _path;
+ private readonly Assembly _assembly;
+
+ ///
+ /// Initializes a new instance of the class with the provided resource path and the assembly containing the asset.
+ ///
+ /// The path of the wave file.
+ /// The containing the asset.
+ public LoadableAudioResourceAsset(string path, Assembly assembly)
+ {
+ _path = path;
+ _assembly = assembly;
+ }
+
+ ///
+ /// Initializes a new instance of the class with the provided resource path.
+ ///
+ /// The path of the wave file.
+ [Obsolete("Pass typeof(YourPlugin).Assembly directly to the constructor for better performance.")]
+ public LoadableAudioResourceAsset(string path)
+ {
+ _path = path;
+ _assembly = Assembly.GetCallingAssembly();
+ }
///
public override AudioClip LoadAsset()
{
if (!LoadedAsset)
{
- LoadedAsset = AudioTools.LoadAudioFromResources(path, _assembly);
+ LoadedAsset = AudioTools.LoadAudioFromResources(_path, _assembly);
}
return LoadedAsset!;
diff --git a/MiraAPI/Utilities/Assets/LoadableResourceAsset.cs b/MiraAPI/Utilities/Assets/LoadableResourceAsset.cs
index 4fffd2fe..02303d43 100644
--- a/MiraAPI/Utilities/Assets/LoadableResourceAsset.cs
+++ b/MiraAPI/Utilities/Assets/LoadableResourceAsset.cs
@@ -1,4 +1,5 @@
-using System.Reflection;
+using System;
+using System.Reflection;
using UnityEngine;
namespace MiraAPI.Utilities.Assets;
@@ -6,18 +7,44 @@ namespace MiraAPI.Utilities.Assets;
///
/// A utility class for loading assets from embedded resources.
///
-/// The path to the embedded resource.
-/// The pixels per unit for the loaded sprite.
-public class LoadableResourceAsset(string path, float pixelsPerUnit = 100f) : LoadableAsset
+public class LoadableResourceAsset : LoadableAsset
{
- private readonly Assembly _assembly = Assembly.GetCallingAssembly();
+ private readonly string _path;
+ private readonly float _pixelsPerUnit;
+ private readonly Assembly _assembly;
+
+ ///
+ /// Initializes a new instance of the class with the provided resource path and the assembly containing the asset.
+ ///
+ /// The path to the embedded resource.
+ /// The containing the asset.
+ /// The pixels per unit for the loaded sprite.
+ public LoadableResourceAsset(string path, Assembly assembly, float pixelsPerUnit = 100f)
+ {
+ _path = path;
+ _assembly = assembly;
+ _pixelsPerUnit = pixelsPerUnit;
+ }
+
+ ///
+ /// Initializes a new instance of the class with the provided resource path and the assembly containing the asset.
+ ///
+ /// The path to the embedded resource.
+ /// The pixels per unit for the loaded sprite.
+ [Obsolete("Pass typeof(YourPlugin).Assembly directly to the constructor for better performance.")]
+ public LoadableResourceAsset(string path, float pixelsPerUnit = 100f)
+ {
+ _path = path;
+ _pixelsPerUnit = pixelsPerUnit;
+ _assembly = Assembly.GetCallingAssembly();
+ }
///
public override Sprite LoadAsset()
{
if (!LoadedAsset)
{
- LoadedAsset = SpriteTools.LoadSpriteFromPath(path, _assembly, pixelsPerUnit);
+ LoadedAsset = SpriteTools.LoadSpriteFromPath(_path, _assembly, _pixelsPerUnit);
}
return LoadedAsset!;
diff --git a/MiraAPI/Utilities/Assets/MiraAssets.cs b/MiraAPI/Utilities/Assets/MiraAssets.cs
index 96ac0788..66386aa2 100644
--- a/MiraAPI/Utilities/Assets/MiraAssets.cs
+++ b/MiraAPI/Utilities/Assets/MiraAssets.cs
@@ -1,4 +1,5 @@
-using Reactor.Utilities;
+using System.Reflection;
+using Reactor.Utilities;
using UnityEngine;
namespace MiraAPI.Utilities.Assets;
@@ -8,11 +9,13 @@ namespace MiraAPI.Utilities.Assets;
///
public static class MiraAssets
{
+ private static readonly Assembly _assembly = typeof(MiraAssets).Assembly;
+
static MiraAssets()
{
var boxTex = SpriteTools.LoadTextureFromResourcePath(
"MiraAPI.Resources.RoundedBox.png",
- System.Reflection.Assembly.GetExecutingAssembly());
+ _assembly);
var boxSprite = Sprite.Create(
boxTex,
new Rect(0, 0, boxTex.width, boxTex.height),
@@ -58,7 +61,7 @@ public static class MiraAssets
///
/// Gets the empty asset.
///
- public static LoadableResourceAsset Empty { get; } = new("MiraAPI.Resources.Empty.png");
+ public static LoadableResourceAsset Empty { get; } = new("MiraAPI.Resources.Empty.png", _assembly);
///
/// Gets the RoundedBox , which is a rounded rectangle used for UI elements.
@@ -68,312 +71,312 @@ public static class MiraAssets
///
/// Gets the Next Button sprite.
///
- public static LoadableResourceAsset NextButton { get; } = new("MiraAPI.Resources.NextButton.png");
+ public static LoadableResourceAsset NextButton { get; } = new("MiraAPI.Resources.NextButton.png", _assembly);
///
/// Gets the Mira settings icon.
///
- public static LoadableResourceAsset SettingsIcon { get; } = new("MiraAPI.Resources.Settings.png");
+ public static LoadableResourceAsset SettingsIcon { get; } = new("MiraAPI.Resources.Settings.png", _assembly);
///
/// Gets the highlighted Next Button sprite.
///
- public static LoadableResourceAsset NextButtonActive { get; } = new("MiraAPI.Resources.NextButtonActive.png");
+ public static LoadableResourceAsset NextButtonActive { get; } = new("MiraAPI.Resources.NextButtonActive.png", _assembly);
///
/// Gets the Cog icon used in Role Settings Menu.
///
- public static LoadableResourceAsset Cog { get; } = new("MiraAPI.Resources.Cog.png");
+ public static LoadableResourceAsset Cog { get; } = new("MiraAPI.Resources.Cog.png", _assembly);
///
/// Gets the Checkmark Box used in the Settings Menu.
///
- public static LoadableResourceAsset CheckmarkBox { get; } = new("MiraAPI.Resources.CheckMarkBox.png");
+ public static LoadableResourceAsset CheckmarkBox { get; } = new("MiraAPI.Resources.CheckMarkBox.png", _assembly);
///
/// Gets the Reset Box used in the Settings Menu.
///
- public static LoadableResourceAsset ResetButton { get; } = new("MiraAPI.Resources.ResetButton.png");
+ public static LoadableResourceAsset ResetButton { get; } = new("MiraAPI.Resources.ResetButton.png", _assembly);
///
/// Gets the Checkmark used in the Settings Menu.
///
- public static LoadableResourceAsset Checkmark { get; } = new("MiraAPI.Resources.Checkmark.png");
+ public static LoadableResourceAsset Checkmark { get; } = new("MiraAPI.Resources.Checkmark.png", _assembly);
///
/// Gets the white CategoryHeader used in the Settings Menu.
///
- public static LoadableResourceAsset CategoryHeader { get; } = new("MiraAPI.Resources.CategoryHeader.png");
+ public static LoadableResourceAsset CategoryHeader { get; } = new("MiraAPI.Resources.CategoryHeader.png", _assembly);
///
/// Gets the sprite used for the Keybind icons.
///
- public static LoadableResourceAsset KeybindButton { get; } = new("MiraAPI.Resources.KeybindButton.png");
+ public static LoadableResourceAsset KeybindButton { get; } = new("MiraAPI.Resources.KeybindButton.png", _assembly);
///
/// Gets the sprite used for crewmate role files in TaskAdderGame.
///
- public static LoadableResourceAsset CrewmateFile { get; } = new("MiraAPI.Resources.CrewmateFile.png");
+ public static LoadableResourceAsset CrewmateFile { get; } = new("MiraAPI.Resources.CrewmateFile.png", _assembly);
///
/// Gets the sprite used for impostor role files in TaskAdderGame.
///
- public static LoadableResourceAsset ImpostorFile { get; } = new("MiraAPI.Resources.ImpostorFile.png");
+ public static LoadableResourceAsset ImpostorFile { get; } = new("MiraAPI.Resources.ImpostorFile.png", _assembly);
///
/// Gets the sprite used for custom team role files in TaskAdderGame.
///
- public static LoadableResourceAsset CustomTeamFile { get; } = new("MiraAPI.Resources.CustomFile.png");
+ public static LoadableResourceAsset CustomTeamFile { get; } = new("MiraAPI.Resources.CustomFile.png", _assembly);
///
/// Gets the sprite used for modifier file in TaskAdderGame.
///
- public static LoadableResourceAsset ModifierFile { get; } = new("MiraAPI.Resources.ModifierFile.png");
+ public static LoadableResourceAsset ModifierFile { get; } = new("MiraAPI.Resources.ModifierFile.png", _assembly);
///
/// Gets the sprite used for the Classic gamemode.
///
- public static LoadableResourceAsset ClassicGamemodeIcon { get; } = new("MiraAPI.Resources.ClassicGamemodeIcon.png");
+ public static LoadableResourceAsset ClassicGamemodeIcon { get; } = new("MiraAPI.Resources.ClassicGamemodeIcon.png", _assembly);
///
/// Gets the sprite used for the Hide n Seek gamemode.
///
- public static LoadableResourceAsset HnSGamemodeIcon { get; } = new("MiraAPI.Resources.HnSGamemodeIcon.png");
+ public static LoadableResourceAsset HnSGamemodeIcon { get; } = new("MiraAPI.Resources.HnSGamemodeIcon.png", _assembly);
///
/// Gets the sprite used for timed modifier file in TaskAdderGame.
///
- public static LoadableResourceAsset TimedModifierFile { get; } = new("MiraAPI.Resources.TimedModifierFile.png");
+ public static LoadableResourceAsset TimedModifierFile { get; } = new("MiraAPI.Resources.TimedModifierFile.png", _assembly);
///
/// Gets the sprite used for the new chat button while hovering.
///
- public static LoadableResourceAsset ChatHoverSprite { get; } = new("MiraAPI.Resources.NormalChatHover.png");
+ public static LoadableResourceAsset ChatHoverSprite { get; } = new("MiraAPI.Resources.NormalChatHover.png", _assembly);
///
/// Gets the sprite used for the new chat button while hovering.
///
- public static LoadableResourceAsset ChatIdleSprite { get; } = new("MiraAPI.Resources.NormalChatIdle.png");
+ public static LoadableResourceAsset ChatIdleSprite { get; } = new("MiraAPI.Resources.NormalChatIdle.png", _assembly);
///
/// Gets the sprite used for the new chat button while hovering.
///
- public static LoadableResourceAsset ChatOpenSprite { get; } = new("MiraAPI.Resources.NormalChatOpen.png");
+ public static LoadableResourceAsset ChatOpenSprite { get; } = new("MiraAPI.Resources.NormalChatOpen.png", _assembly);
///
/// Gets the sprite used for players button while hovering.
///
- public static LoadableResourceAsset WikiPlayersButtonHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarPlayersButtonHover.png");
+ public static LoadableResourceAsset WikiPlayersButtonHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarPlayersButtonHover.png", _assembly);
///
/// Gets the sprite used for the players button while hovering.
///
- public static LoadableResourceAsset WikiPlayersButtonIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarPlayersButtonIdle.png");
+ public static LoadableResourceAsset WikiPlayersButtonIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarPlayersButtonIdle.png", _assembly);
///
/// Gets the sprite used for the players button while hovering.
///
- public static LoadableResourceAsset WikiPlayersButtonOpenSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarPlayersButtonOpen.png");
+ public static LoadableResourceAsset WikiPlayersButtonOpenSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarPlayersButtonOpen.png", _assembly);
///
/// Gets the sprite used for the settings button while hovering.
///
- public static LoadableResourceAsset WikiSettingsButtonHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarSettingsButtonHover.png");
+ public static LoadableResourceAsset WikiSettingsButtonHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarSettingsButtonHover.png", _assembly);
///
/// Gets the sprite used for the settings button while hovering.
///
- public static LoadableResourceAsset WikiSettingsButtonIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarSettingsButtonIdle.png");
+ public static LoadableResourceAsset WikiSettingsButtonIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarSettingsButtonIdle.png", _assembly);
///
/// Gets the sprite used for the settings button while hovering.
///
- public static LoadableResourceAsset WikiSettingsButtonOpenSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarSettingsButtonOpen.png");
+ public static LoadableResourceAsset WikiSettingsButtonOpenSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarSettingsButtonOpen.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset WikiRolesButtonHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarRolesButtonHover.png");
+ public static LoadableResourceAsset WikiRolesButtonHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarRolesButtonHover.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset WikiRolesButtonIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarRolesButtonIdle.png");
+ public static LoadableResourceAsset WikiRolesButtonIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarRolesButtonIdle.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset WikiRolesButtonOpenSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarRolesButtonOpen.png");
+ public static LoadableResourceAsset WikiRolesButtonOpenSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarRolesButtonOpen.png", _assembly);
///
/// Gets the sprite used for the modifiers button while hovering.
///
- public static LoadableResourceAsset WikiModifiersButtonHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarModifiersButtonHover.png");
+ public static LoadableResourceAsset WikiModifiersButtonHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarModifiersButtonHover.png", _assembly);
///
/// Gets the sprite used for the modifiers button while hovering.
///
- public static LoadableResourceAsset WikiModifiersButtonIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarModifiersButtonIdle.png");
+ public static LoadableResourceAsset WikiModifiersButtonIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarModifiersButtonIdle.png", _assembly);
///
/// Gets the sprite used for the modifiers button while hovering.
///
- public static LoadableResourceAsset WikiModifiersButtonOpenSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarModifiersButtonOpen.png");
+ public static LoadableResourceAsset WikiModifiersButtonOpenSprite { get; } = new("MiraAPI.Resources.Wiki.SidebarModifiersButtonOpen.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset GroupCountHoverSprite { get; } = new("MiraAPI.Resources.Wiki.GroupCountHover.png");
+ public static LoadableResourceAsset GroupCountHoverSprite { get; } = new("MiraAPI.Resources.Wiki.GroupCountHover.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset GroupCountIdleSprite { get; } = new("MiraAPI.Resources.Wiki.GroupCountIdle.png");
+ public static LoadableResourceAsset GroupCountIdleSprite { get; } = new("MiraAPI.Resources.Wiki.GroupCountIdle.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset GroupFactionHoverSprite { get; } = new("MiraAPI.Resources.Wiki.GroupFactionHover.png");
+ public static LoadableResourceAsset GroupFactionHoverSprite { get; } = new("MiraAPI.Resources.Wiki.GroupFactionHover.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset GroupFactionIdleSprite { get; } = new("MiraAPI.Resources.Wiki.GroupFactionIdle.png");
+ public static LoadableResourceAsset GroupFactionIdleSprite { get; } = new("MiraAPI.Resources.Wiki.GroupFactionIdle.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset GroupNoneHoverSprite { get; } = new("MiraAPI.Resources.Wiki.GroupNoneHover.png");
+ public static LoadableResourceAsset GroupNoneHoverSprite { get; } = new("MiraAPI.Resources.Wiki.GroupNoneHover.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset GroupNoneIdleSprite { get; } = new("MiraAPI.Resources.Wiki.GroupNoneIdle.png");
+ public static LoadableResourceAsset GroupNoneIdleSprite { get; } = new("MiraAPI.Resources.Wiki.GroupNoneIdle.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset SearchClearHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SearchClearHover.png");
+ public static LoadableResourceAsset SearchClearHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SearchClearHover.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset SearchClearIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SearchClearIdle.png");
+ public static LoadableResourceAsset SearchClearIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SearchClearIdle.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset SearchIconHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SearchIconHover.png");
+ public static LoadableResourceAsset SearchIconHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SearchIconHover.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset SearchIconIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SearchIconIdle.png");
+ public static LoadableResourceAsset SearchIconIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SearchIconIdle.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset SortingAzHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SortingAzHover.png");
+ public static LoadableResourceAsset SortingAzHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SortingAzHover.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset SortingAzIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SortingAzIdle.png");
+ public static LoadableResourceAsset SortingAzIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SortingAzIdle.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset SortingZaHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SortingZaHover.png");
+ public static LoadableResourceAsset SortingZaHoverSprite { get; } = new("MiraAPI.Resources.Wiki.SortingZaHover.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset SortingZaIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SortingZaIdle.png");
+ public static LoadableResourceAsset SortingZaIdleSprite { get; } = new("MiraAPI.Resources.Wiki.SortingZaIdle.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset VisibleAllHoverSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleAllHover.png");
+ public static LoadableResourceAsset VisibleAllHoverSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleAllHover.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset VisibleAllIdleSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleAllIdle.png");
+ public static LoadableResourceAsset VisibleAllIdleSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleAllIdle.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset VisibleOffHoverSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleOffHover.png");
+ public static LoadableResourceAsset VisibleOffHoverSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleOffHover.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset VisibleOffIdleSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleOffIdle.png");
+ public static LoadableResourceAsset VisibleOffIdleSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleOffIdle.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset VisibleOnHoverSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleOnHover.png");
+ public static LoadableResourceAsset VisibleOnHoverSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleOnHover.png", _assembly);
///
/// Gets the sprite used for the roles button while hovering.
///
- public static LoadableResourceAsset VisibleOnIdleSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleOnIdle.png");
+ public static LoadableResourceAsset VisibleOnIdleSprite { get; } = new("MiraAPI.Resources.Wiki.VisibleOnIdle.png", _assembly);
///
/// Gets the sprite used for crewmates.
///
- public static LoadableResourceAsset IconCrewmate { get; } = new("MiraAPI.Resources.Wiki.IconCrewmate.png");
+ public static LoadableResourceAsset IconCrewmate { get; } = new("MiraAPI.Resources.Wiki.IconCrewmate.png", _assembly);
///
/// Gets the sprite used for impostors.
///
- public static LoadableResourceAsset IconImpostor { get; } = new("MiraAPI.Resources.Wiki.IconImpostor.png");
+ public static LoadableResourceAsset IconImpostor { get; } = new("MiraAPI.Resources.Wiki.IconImpostor.png", _assembly);
///
/// Gets the sprite used for neutrals.
///
- public static LoadableResourceAsset IconNeutral { get; } = new("MiraAPI.Resources.Wiki.IconNeutral.png");
+ public static LoadableResourceAsset IconNeutral { get; } = new("MiraAPI.Resources.Wiki.IconNeutral.png", _assembly);
///
/// Gets the sprite used for the player list.
///
- public static LoadableResourceAsset IconPlayerList { get; } = new("MiraAPI.Resources.Wiki.IconPlayerList.png");
+ public static LoadableResourceAsset IconPlayerList { get; } = new("MiraAPI.Resources.Wiki.IconPlayerList.png", _assembly);
///
/// Gets the sprite used for settings.
///
- public static LoadableResourceAsset IconSettings { get; } = new("MiraAPI.Resources.Wiki.IconSettings.png");
+ public static LoadableResourceAsset IconSettings { get; } = new("MiraAPI.Resources.Wiki.IconSettings.png", _assembly);
///
/// Gets the sprite used for terminology.
///
- public static LoadableResourceAsset IconTerminology { get; } = new("MiraAPI.Resources.Wiki.IconTerminology.png");
+ public static LoadableResourceAsset IconTerminology { get; } = new("MiraAPI.Resources.Wiki.IconTerminology.png", _assembly);
///
/// Gets the Page switching sprite.
///
- public static LoadableResourceAsset PageLeftHover { get; } = new("MiraAPI.Resources.Wiki.PageLeftHover.png");
+ public static LoadableResourceAsset PageLeftHover { get; } = new("MiraAPI.Resources.Wiki.PageLeftHover.png", _assembly);
///
/// Gets the Page switching sprite.
///
- public static LoadableResourceAsset PageLeftIdle { get; } = new("MiraAPI.Resources.Wiki.PageLeftIdle.png");
+ public static LoadableResourceAsset PageLeftIdle { get; } = new("MiraAPI.Resources.Wiki.PageLeftIdle.png", _assembly);
///
/// Gets the Page switching sprite.
///
- public static LoadableResourceAsset PageRightHover { get; } = new("MiraAPI.Resources.Wiki.PageRightHover.png");
+ public static LoadableResourceAsset PageRightHover { get; } = new("MiraAPI.Resources.Wiki.PageRightHover.png", _assembly);
///
/// Gets the Page switching sprite.
///
- public static LoadableResourceAsset PageRightIdle { get; } = new("MiraAPI.Resources.Wiki.PageRightIdle.png");
+ public static LoadableResourceAsset PageRightIdle { get; } = new("MiraAPI.Resources.Wiki.PageRightIdle.png", _assembly);
///
/// Gets the sprite used below the tab icons in the wiki.
///
- public static LoadableResourceAsset TabButtonContainer { get; } = new("MiraAPI.Resources.Wiki.TabButtonContainer.png");
+ public static LoadableResourceAsset TabButtonContainer { get; } = new("MiraAPI.Resources.Wiki.TabButtonContainer.png", _assembly);
- internal static LoadableResourceAsset BlankSprite { get; } = new("MiraAPI.Resources.BlankSprite.png");
+ internal static LoadableResourceAsset BlankSprite { get; } = new("MiraAPI.Resources.BlankSprite.png", _assembly);
}
diff --git a/MiraAPI/Utilities/BasicGuideComparer.cs b/MiraAPI/Utilities/BasicGuideComparer.cs
index 2ca80412..15cef202 100644
--- a/MiraAPI/Utilities/BasicGuideComparer.cs
+++ b/MiraAPI/Utilities/BasicGuideComparer.cs
@@ -4,25 +4,15 @@ using System.Linq;
namespace MiraAPI.Utilities;
+///
+/// A comparer used to sort role/modifier IDs based on which ones are currently active.
+///
+/// The collection of currently active IDs.
public class BasicGuideComparer(IEnumerable activeIds) : IComparer
{
+ ///
public int Compare(uint x, uint y)
{
- if (x == null && y == null)
- {
- return 0;
- }
-
- if (x == null)
- {
- return -1;
- }
-
- if (y == null)
- {
- return 1;
- }
-
var xActive = activeIds.Contains(x);
var yActive = activeIds.Contains(y);
@@ -38,4 +28,4 @@ public class BasicGuideComparer(IEnumerable activeIds) : IComparer
return 0;
}
-}
\ No newline at end of file
+}
diff --git a/MiraAPI/Utilities/Extensions.cs b/MiraAPI/Utilities/Extensions.cs
index 21112f69..57fcd1a3 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.
///