allow access to plugin information externally

This commit is contained in:
XtraCube committed 2024-09-17 12:26:01 -04:00
1 parent d0161ba85c
commit be28948e7e
5 files changed
+52 -5

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@ using UnityEngine;
namespace MiraAPI.GameOptions;
internal interface IModdedOption
public interface IModdedOption
{
uint Id { get; }
string Title { get; }
+3 -1
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using MiraAPI.PluginLoading;
using Reactor.Utilities;
namespace MiraAPI.Hud;
@@ -9,7 +10,7 @@ internal static class CustomButtonManager
{
internal static readonly List<CustomActionButton> CustomButtons = [];
internal static void RegisterButton(Type buttonType)
internal static void RegisterButton(Type buttonType, MiraPluginInfo pluginInfo)
{
if (!typeof(CustomActionButton).IsAssignableFrom(buttonType))
{
@@ -24,6 +25,7 @@ internal static class CustomButtonManager
}
CustomButtons.Add(button);
pluginInfo.Buttons.Add(button);
typeof(CustomButtonSingleton<>).MakeGenericType(buttonType)
.GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic)!
.SetValue(null, button);
+1
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using MiraAPI.Modifiers.Types;
using MiraAPI.Networking;
using MiraAPI.PluginLoading;
using MiraAPI.Roles;
using MiraAPI.Utilities;
using Reactor.Networking.Rpc;
+44
View File
@@ -3,6 +3,12 @@ using BepInEx.Configuration;
using MiraAPI.GameModes;
using MiraAPI.GameOptions;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Linq;
using MiraAPI.GameOptions.OptionTypes;
using MiraAPI.Hud;
using MiraAPI.Roles;
namespace MiraAPI.PluginLoading;
@@ -19,6 +25,42 @@ public class MiraPluginInfo
PluginId = info.Metadata.GUID;
}
/// <summary>
/// Get a read only collection of this plugin's Option Groups.
/// </summary>
/// <returns>Readonly collection of option groups.</returns>
public IReadOnlyCollection<AbstractOptionGroup> GetOptionGroups()
{
return OptionGroups.AsReadOnly();
}
/// <summary>
/// Gets a read only collection of this plugin's options.
/// </summary>
/// <returns>Read only collection of options.</returns>
public IReadOnlyCollection<IModdedOption> GetOptions()
{
return Options.AsReadOnly();
}
/// <summary>
/// Gets a read only dictionary of Role IDs and the RoleBehaviour object they are associated with.
/// </summary>
/// <returns>Read only dictionary of IDs and Roles.</returns>
public ReadOnlyDictionary<ushort, RoleBehaviour> GetRoles()
{
return new ReadOnlyDictionary<ushort, RoleBehaviour>(CustomRoles);
}
/// <summary>
/// Gets a read only collection of this plugin's custom buttons.
/// </summary>
/// <returns>Read only collection of buttons.</returns>
public IReadOnlyCollection<CustomActionButton> GetButtons()
{
return Buttons.AsReadOnly();
}
internal List<AbstractOptionGroup> OptionGroups { get; } = [];
internal List<IModdedOption> Options { get; } = [];
@@ -27,6 +69,8 @@ public class MiraPluginInfo
internal Dictionary<int, CustomGameMode> GameModes { get; } = [];
internal List<CustomActionButton> Buttons { get; } = [];
/// <summary>
/// Gets the plugin's ID, as defined in the plugin's BepInEx metadata.
/// </summary>
+3 -3
View File
@@ -39,7 +39,7 @@ internal sealed class MiraPluginManager
RegisterAllOptions(assembly, info);
RegisterRoleAttribute(assembly, info);
RegisterButtonAttribute(assembly);
RegisterButtonAttribute(assembly, info);
RegisterColorClasses(assembly);
@@ -161,14 +161,14 @@ internal sealed class MiraPluginManager
}
}
private static void RegisterButtonAttribute(Assembly assembly)
private static void RegisterButtonAttribute(Assembly assembly, MiraPluginInfo pluginInfo)
{
foreach (var type in assembly.GetTypes())
{
var attribute = type.GetCustomAttribute<RegisterButtonAttribute>();
if (attribute != null)
{
CustomButtonManager.RegisterButton(type);
CustomButtonManager.RegisterButton(type, pluginInfo);
}
}
}