mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
make it an extension instead
This commit is contained in:
7 files changed
+18
-12
No files matched your search
@@ -83,7 +83,7 @@ public static class PaletteManager
|
||||
return true;
|
||||
|
||||
foreach (var field in type.GetFields(MiraPluginManager.DeclaredStaticMembers)
|
||||
.Where(f => !MiraPluginManager.IsAutoPropertyBackingField(f) && f.FieldType.IsAssignableTo(typeof(CustomColor))))
|
||||
.Where(f => !f.IsAutoPropertyBackingField() && f.FieldType.IsAssignableTo(typeof(CustomColor))))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for colors.");
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public static class ModdedOptionsManager
|
||||
}
|
||||
|
||||
foreach (var field in type.GetFields(MiraPluginManager.DeclaredInstanceMembers)
|
||||
.Where(f => !MiraPluginManager.IsAutoPropertyBackingField(f)
|
||||
.Where(f => !f.IsAutoPropertyBackingField()
|
||||
&& (f.FieldType.IsAssignableTo(typeof(IModdedOption)) || f.FieldType.IsAssignableTo(typeof(IBaseModdedOptionList)))))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for options.");
|
||||
|
||||
@@ -109,7 +109,7 @@ public static class KeybindManager
|
||||
return true;
|
||||
|
||||
foreach (var field in type.GetFields(MiraPluginManager.DeclaredStaticMembers)
|
||||
.Where(f => !MiraPluginManager.IsAutoPropertyBackingField(f) && f.FieldType.IsAssignableTo(typeof(MiraKeybind))))
|
||||
.Where(f => !f.IsAutoPropertyBackingField() && f.FieldType.IsAssignableTo(typeof(MiraKeybind))))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for keybinds.");
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public static class LocalSettingsManager
|
||||
}
|
||||
|
||||
foreach (var field in type.GetFields(MiraPluginManager.DeclaredInstanceMembers)
|
||||
.Where(f => !MiraPluginManager.IsAutoPropertyBackingField(f)
|
||||
.Where(f => !f.IsAutoPropertyBackingField()
|
||||
&& (f.FieldType.IsAssignableTo(typeof(ConfigEntryBase)) || f.FieldType.IsAssignableTo(typeof(LocalSettingsButton)))))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for local settings or buttons.");
|
||||
|
||||
@@ -119,7 +119,7 @@ public class MiraPluginInfo
|
||||
Modifiers = [.. InternalModifiers];
|
||||
OptionGroups = [.. InternalOptionGroups];
|
||||
Options = [.. InternalOptions];
|
||||
Roles = new ReadOnlyDictionary<ushort, RoleBehaviour>(InternalRoles);
|
||||
Roles = new(InternalRoles);
|
||||
Buttons = [.. InternalButtons];
|
||||
MeetingButtons = [.. InternalMeetingButtons];
|
||||
TargetedMeetingButtons = [.. InternalTargetedMeetingButtons];
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
@@ -141,18 +140,13 @@ public sealed class MiraPluginManager
|
||||
_registeredPlugins.Add(pluginInfo.Metadata.GUID, info);
|
||||
|
||||
info.SavePublicCollections();
|
||||
|
||||
PresetManager.CreateDefaultPreset(info);
|
||||
PresetManager.LoadPresets(info);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
internal static bool IsAutoPropertyBackingField(FieldInfo field)
|
||||
{
|
||||
return field.IsDefined<CompilerGeneratedAttribute>(false) &&
|
||||
field.Name.Contains(">k__BackingField", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static void ProcessAssemblyTypes(Assembly assembly, MiraPluginInfo info, BasePlugin basePlugin, IMiraPlugin plugin, List<Type> roles, bool isMira)
|
||||
{
|
||||
if (plugin.ForceRegisterEvents)
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.GameModes;
|
||||
@@ -916,4 +917,15 @@ public static class Extensions
|
||||
attribute = member.GetCustomAttribute<T>();
|
||||
return attribute != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a field is auto-generated by the compiler.
|
||||
/// </summary>
|
||||
/// <param name="field">The <see cref="FieldInfo"/> to check.</param>
|
||||
/// <returns>true if the field was auto-generated; otherwise false.</returns>
|
||||
public static bool IsAutoPropertyBackingField(this FieldInfo field)
|
||||
{
|
||||
return field.IsDefined<CompilerGeneratedAttribute>(false) &&
|
||||
field.Name.Contains(">k__BackingField", StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user