diff --git a/MiraAPI/Colors/ColorSpaces/CmykColor.cs b/MiraAPI/Colors/ColorSpaces/CmykColor.cs index 11ec563f..e505421e 100644 --- a/MiraAPI/Colors/ColorSpaces/CmykColor.cs +++ b/MiraAPI/Colors/ColorSpaces/CmykColor.cs @@ -15,6 +15,7 @@ namespace MiraAPI.Colors.ColorSpaces; /// The alpha component. [Serializable] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "Unity parity.")] +// ReSharper disable InconsistentNaming (Justification: Read above.) public record struct CmykColor(float c, float m, float y, float k, float a = 1f) { /// diff --git a/MiraAPI/Colors/ColorSpaces/HsbColor.cs b/MiraAPI/Colors/ColorSpaces/HsbColor.cs index b566333e..8a8b0a2a 100644 --- a/MiraAPI/Colors/ColorSpaces/HsbColor.cs +++ b/MiraAPI/Colors/ColorSpaces/HsbColor.cs @@ -14,6 +14,7 @@ namespace MiraAPI.Colors.ColorSpaces; /// The alpha component. [Serializable] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "Unity parity.")] +// ReSharper disable InconsistentNaming (Justification: Read above.) public record struct HsbColor(float h, float s, float b, float a = 1f) { /// diff --git a/MiraAPI/Colors/ColorSpaces/HslColor.cs b/MiraAPI/Colors/ColorSpaces/HslColor.cs index 466f1597..61134f5d 100644 --- a/MiraAPI/Colors/ColorSpaces/HslColor.cs +++ b/MiraAPI/Colors/ColorSpaces/HslColor.cs @@ -14,6 +14,7 @@ namespace MiraAPI.Colors.ColorSpaces; /// The alpha component. [Serializable] [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:Element should begin with upper-case letter", Justification = "Unity parity.")] +// ReSharper disable InconsistentNaming (Justification: Read above.) public record struct HslColor(float h, float s, float l, float a = 1f) { /// diff --git a/MiraAPI/Colors/RegisterCustomColorsAttribute.cs b/MiraAPI/Colors/RegisterCustomColorsAttribute.cs index eecba2b5..d6c9cb0f 100644 --- a/MiraAPI/Colors/RegisterCustomColorsAttribute.cs +++ b/MiraAPI/Colors/RegisterCustomColorsAttribute.cs @@ -10,7 +10,7 @@ namespace MiraAPI.Colors; public class RegisterCustomColorsAttribute(string idPrefix) : Attribute { /// - /// Gets the translation ID prefix for all of the colors within the container type. + /// Gets the translation ID prefix for all colors within the container type. /// public string IdPrefix => idPrefix; diff --git a/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionMemberAttribute.cs b/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionMemberAttribute.cs index cb44875d..10096462 100644 --- a/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionMemberAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionMemberAttribute.cs @@ -273,7 +273,7 @@ public abstract class ModdedOptionMemberAttribute(string? memberName, Type? hold /// The static getter used to push the target instance onto the evaluation stack for instance methods, /// or if is static. /// - /// The return of the generated delegate (or for actions). + /// The return of the generated delegate (or for actions). /// The parameter types accepted by the generated delegate. /// The concrete delegate to create (e.g., or ). /// A descriptive suffix appended to the generated name for debugging and stack traces. @@ -346,7 +346,7 @@ public abstract class ModdedOptionMemberAttribute(string? memberName, Type? hold /// The static getter used to push the target instance onto the evaluation stack for instance methods, /// or if is static. /// - /// The return of the generated delegate (or for actions). + /// The return of the generated delegate (or for actions). /// The parameter types accepted by the generated delegate. /// The concrete delegate to create. /// A descriptive suffix appended to the generated name for debugging and stack traces. diff --git a/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionVisibilityAttribute.cs b/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionVisibilityAttribute.cs index 232ffee4..284a53b6 100644 --- a/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionVisibilityAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/Delegate/ModdedOptionVisibilityAttribute.cs @@ -20,7 +20,7 @@ public sealed class ModdedOptionVisibilityAttribute(string? memberName = null, T internal Func? GetVisibility(AbstractOptionGroup group, PropertyInfo property) { - if (ResolveMember(group, property, out Type type, out var instanceGetter, out var notFound) is not { } member) + if (ResolveMember(group, property, out var type, out var instanceGetter, out var notFound) is not { } member) { if (notFound) Error($"Member {MemberName} does not exist in {type.FullName}"); diff --git a/MiraAPI/GameOptions/Attributes/Delegate/SearchAttributes.cs b/MiraAPI/GameOptions/Attributes/Delegate/SearchAttributes.cs index c6d4261b..f4bbec48 100644 --- a/MiraAPI/GameOptions/Attributes/Delegate/SearchAttributes.cs +++ b/MiraAPI/GameOptions/Attributes/Delegate/SearchAttributes.cs @@ -6,10 +6,12 @@ namespace MiraAPI.GameOptions.Attributes; /// An attribute used to mark a method or property as one that returns an instance of the class it's declared in. /// [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)] +// ReSharper disable once ClassNeverInstantiated.Global (Justification: Used by dependant code.) public sealed class InstanceGetterAttribute : Attribute; /// /// An attribute used to mark a class as one whose reflection search should include private members. /// [AttributeUsage(AttributeTargets.Class)] +// ReSharper disable once ClassNeverInstantiated.Global (Justification: Used by dependant code.) public sealed class SearchPrivateAttribute : Attribute; diff --git a/MiraAPI/GameOptions/Attributes/ModdedPlayerOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedPlayerOptionAttribute.cs index 610d0c81..3748c19a 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedPlayerOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedPlayerOptionAttribute.cs @@ -15,7 +15,7 @@ public class ModdedPlayerOptionAttribute( bool allowNone = true) : ModdedOptionAttribute(title) { - internal override IModdedOption? CreateOption(object? value, PropertyInfo property) + internal override IModdedOption CreateOption(object? value, PropertyInfo property) { var option = new ModdedPlayerOption(Title, allowNone); return option; diff --git a/MiraAPI/GameOptions/Attributes/ModdedStringOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedStringOptionAttribute.cs index 9086b1f1..029cd2d1 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedStringOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedStringOptionAttribute.cs @@ -15,7 +15,7 @@ public class ModdedStringOptionAttribute( string[] values) : ModdedOptionAttribute(title) { - internal override IModdedOption? CreateOption(object? value, PropertyInfo property) + internal override IModdedOption CreateOption(object? value, PropertyInfo property) { var option = new ModdedStringOption(Title, (string)(value ?? string.Empty), values); return option; diff --git a/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs b/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs index 042c1f39..d59ef228 100644 --- a/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/ModdedToggleOptionAttribute.cs @@ -22,6 +22,7 @@ public class ModdedToggleOptionAttribute( /// /// The option title. public ModdedToggleOptionAttribute(string title) + // ReSharper disable once IntroduceOptionalParameters.Global (Justification: Kept for backwards compatibility.) : this(title, "On", "Off") { } diff --git a/MiraAPI/GameOptions/Attributes/OptionList/ModdedPlayerOptionListAttribute.cs b/MiraAPI/GameOptions/Attributes/OptionList/ModdedPlayerOptionListAttribute.cs index 533492bb..a8fdd502 100644 --- a/MiraAPI/GameOptions/Attributes/OptionList/ModdedPlayerOptionListAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/OptionList/ModdedPlayerOptionListAttribute.cs @@ -18,10 +18,7 @@ public class ModdedPlayerOptionListAttribute( { internal override IModdedOptionList CreateOptionList(IList value, PropertyInfo property) { - return new ModdedOptionList(value.Count, idx => - { - return new(GetFormattedTitle(idx), allowNone); - }); + return new ModdedOptionList(value.Count, idx => new(GetFormattedTitle(idx), allowNone)); } /// @@ -35,7 +32,7 @@ public class ModdedPlayerOptionListAttribute( NetworkedPlayerInfo info => info ? opt.Values.IndexOf(info) : (allowNone ? -1 : 0), _ => (int)value, }; - opt?.SetValue(final); + opt.SetValue(final); } /// diff --git a/MiraAPI/GameOptions/Attributes/OptionList/ModdedStringOptionListAttribute.cs b/MiraAPI/GameOptions/Attributes/OptionList/ModdedStringOptionListAttribute.cs index 78c4b66d..c8b9063d 100644 --- a/MiraAPI/GameOptions/Attributes/OptionList/ModdedStringOptionListAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/OptionList/ModdedStringOptionListAttribute.cs @@ -20,9 +20,7 @@ public class ModdedStringOptionListAttribute( internal override IModdedOptionList CreateOptionList(IList value, PropertyInfo property) { return new ModdedOptionList(value.Count, idx => - { - return new ModdedStringOption(Title.Translate(), (string)(value[idx] ?? string.Empty), values); - }); + new ModdedStringOption(Title.Translate(), (string)(value[idx] ?? string.Empty), values)); } /// diff --git a/MiraAPI/GameOptions/Attributes/OptionList/ModdedToggleOptionListAttribute.cs b/MiraAPI/GameOptions/Attributes/OptionList/ModdedToggleOptionListAttribute.cs index 9dab9a43..b79b4a6d 100644 --- a/MiraAPI/GameOptions/Attributes/OptionList/ModdedToggleOptionListAttribute.cs +++ b/MiraAPI/GameOptions/Attributes/OptionList/ModdedToggleOptionListAttribute.cs @@ -23,6 +23,7 @@ public class ModdedToggleOptionListAttribute( /// /// The option's title. public ModdedToggleOptionListAttribute(string title) + // ReSharper disable once IntroduceOptionalParameters.Global (Justification: Kept for backwards compatibility.) : this(title, "On", "Off") { } diff --git a/MiraAPI/GameOptions/ModdedArray.cs b/MiraAPI/GameOptions/ModdedArray.cs index 65f60efd..b3e86c7e 100644 --- a/MiraAPI/GameOptions/ModdedArray.cs +++ b/MiraAPI/GameOptions/ModdedArray.cs @@ -284,7 +284,7 @@ public static class ModdedArrayBuilder /// /// Creates a new from a span of values. /// - /// The the type of the values. + /// The type of the values. /// The values to initialise with. /// The instance initialised with the provided values. public static ModdedArray Create(ReadOnlySpan values) diff --git a/MiraAPI/GameOptions/ModdedOptionsManager.cs b/MiraAPI/GameOptions/ModdedOptionsManager.cs index e3c1446f..2a7cbede 100644 --- a/MiraAPI/GameOptions/ModdedOptionsManager.cs +++ b/MiraAPI/GameOptions/ModdedOptionsManager.cs @@ -435,7 +435,7 @@ public static class ModdedOptionsManager attribute.SetValue(value); - if (attribute is ModdedOptionListAttribute listAttribute && value != null) + if (attribute is ModdedOptionListAttribute listAttribute && value != null!) ListInstanceCache.AddOrUpdate(value, listAttribute); } diff --git a/MiraAPI/GameOptions/ModifierOptionGroup.cs b/MiraAPI/GameOptions/ModifierOptionGroup.cs deleted file mode 100644 index 19b1a20c..00000000 --- a/MiraAPI/GameOptions/ModifierOptionGroup.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Linq; -using MiraAPI.PluginLoading; - -namespace MiraAPI.GameOptions; - -[MiraIgnore] -internal sealed class ModifierOptionGroup : AbstractOptionGroup -{ - public override string GroupName { get; } - - public ModifierOptionGroup(string name, IModdedOption[] options, params AbstractOptionGroup[] groups) - { - GroupName = name; - Options.AddRange(options); - Options.AddRange(groups.SelectMany(x => x.Options)); - } -} diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index 622006c4..9d53d770 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -47,10 +47,7 @@ public abstract class ModdedOption : IModdedOption /// public T Value { - get - { - return Getter != null ? Getter(_value) : _value; - } + get => Getter != null ? Getter(_value) : _value; protected set { if (Setter != null) diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs index 6e9e9ad3..a7a8549e 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs @@ -40,8 +40,8 @@ public class ModdedOptionList : IModdedOptionList /// The options list. public ModdedOptionList(IEnumerable options) { - Count = options.Count(); Options = [.. options]; + Count = Options.Count; } /// diff --git a/MiraAPI/HnsReimplemented/HnsDangerMeter.cs b/MiraAPI/HnsReimplemented/HnsDangerMeter.cs index 0309e16e..45de15f8 100644 --- a/MiraAPI/HnsReimplemented/HnsDangerMeter.cs +++ b/MiraAPI/HnsReimplemented/HnsDangerMeter.cs @@ -103,14 +103,14 @@ public sealed class HnsDangerMeter(nint cppPtr) : MonoBehaviour(cppPtr) private void UpdateDangerMusic() { var localPlayer = PlayerControl.LocalPlayer; - if (localPlayer != null && localPlayer.Data != null && localPlayer.Data.IsDead) + if (localPlayer == null || localPlayer.Data == null || !localPlayer.Data.IsDead) { - HnsMusicHandler.Instance.SetTaskState(false); - HnsMusicHandler.Instance.ResetMusic(); + HnsMusicHandler.Instance.SetMusicValues(dangerLevel1, dangerLevel2); return; } - HnsMusicHandler.Instance.SetMusicValues(dangerLevel1, dangerLevel2); + HnsMusicHandler.Instance.SetTaskState(false); + HnsMusicHandler.Instance.ResetMusic(); } private void UpdateDangerMeter() diff --git a/MiraAPI/Hud/CustomMultiSelectMenu.cs b/MiraAPI/Hud/CustomMultiSelectMenu.cs index 057b7205..e1c90433 100644 --- a/MiraAPI/Hud/CustomMultiSelectMenu.cs +++ b/MiraAPI/Hud/CustomMultiSelectMenu.cs @@ -83,7 +83,7 @@ public abstract class CustomMultiSelectMenu : CustomPhoneMenu - /// Setup the given once created, given its index, entry, and onClick action. + /// Set up the given once created, given its index, entry, and onClick action. /// /// The panel to configure. /// The 's index. @@ -96,18 +96,18 @@ public abstract class CustomMultiSelectMenu : CustomPhoneMenu /// All entries to give the custom menu. /// Function called when all selections are made/confirmed. - /// The number of selections required. - /// Whether the entire selection should be confirmed manually. - /// If the same entry can be selected multiple times, else unselect entry on click. - protected void Begin(IEnumerable entries, Action?> onClick, int totalSelections, bool shouldConfirm, bool canRepeat = false) + /// The number of selections required. + /// Whether the entire selection should be confirmed manually. + /// If the same entry can be selected multiple times, else unselect entry on click. + protected void Begin(IEnumerable entries, Action?> onClick, int totSelections, bool confirm, bool repeat = false) { MinigameStubs.Begin(Component, null); MeetingVoteAreaVisibility.HideNameplates(Component); - this.totalSelections = totalSelections; - this.shouldConfirm = shouldConfirm; - this.canRepeat = canRepeat; - this.onSelection = onClick; + totalSelections = totSelections; + shouldConfirm = confirm; + canRepeat = repeat; + onSelection = onClick; var back = backButton.GetComponent(); back.OnClick.AddListener((UnityAction)(() => @@ -138,10 +138,10 @@ public abstract class CustomMultiSelectMenu : CustomPhoneMenu /// All entries to give the custom menu. /// Function called when the selection is made. - /// Whether the set of both selections should be confirmed manually. - protected void Begin(IEnumerable entries, Action onClick, bool shouldConfirm) + /// Whether the set of both selections should be confirmed manually. + protected void Begin(IEnumerable entries, Action onClick, bool confirm) { - Begin(entries, list => onClick(list?[0]), 1, shouldConfirm); + Begin(entries, list => onClick(list?[0]), 1, confirm); } /// @@ -149,11 +149,11 @@ public abstract class CustomMultiSelectMenu : CustomPhoneMenu /// All entries to give the custom menu. /// Function called when both selections are made. - /// Whether the set of both selections should be confirmed manually. - /// If the same entry can be selected both times, else unselect entry on click. - protected void Begin(IEnumerable entries, Action onClick, bool shouldConfirm, bool canRepeat = false) + /// Whether the set of both selections should be confirmed manually. + /// If the same entry can be selected both times, else unselect entry on click. + protected void Begin(IEnumerable entries, Action onClick, bool confirm, bool repeat = false) { - Begin(entries, list => onClick(list?[0], list?[1]), 2, shouldConfirm, canRepeat); + Begin(entries, list => onClick(list?[0], list?[1]), 2, confirm, repeat); } private void OnEntryClick(TEntry entry) diff --git a/MiraAPI/Hud/CustomPaginableMenu.cs b/MiraAPI/Hud/CustomPaginableMenu.cs index c8ef1cef..1a13429d 100644 --- a/MiraAPI/Hud/CustomPaginableMenu.cs +++ b/MiraAPI/Hud/CustomPaginableMenu.cs @@ -65,7 +65,7 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu(PanelButtonOnMouse? onMouseOut = null, PanelButtonOnMouse? onMouseOver = null) where TMenu : CustomPaginableMenu, new() { - TMenu customMenu = CustomPhoneMenu.Create(onMouseOut, onMouseOver); + var customMenu = CustomPhoneMenu.Create(onMouseOut, onMouseOver); var nextButton = Object.Instantiate(customMenu.backButton, customMenu.transform).gameObject; nextButton.transform.localPosition = new Vector3(1.85f, -2.185f, customMenu.MenuDepth); diff --git a/MiraAPI/Hud/CustomPhoneMenu.cs b/MiraAPI/Hud/CustomPhoneMenu.cs index 55af740f..d300ccb5 100644 --- a/MiraAPI/Hud/CustomPhoneMenu.cs +++ b/MiraAPI/Hud/CustomPhoneMenu.cs @@ -135,7 +135,7 @@ public abstract class CustomPhoneMenu : ICustomMenu /// public List EntryPanels => [.. MenuEntries.Select(e => e.Panel)]; -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member (Justification: Unity convention.) +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member (Justification: Unity fields.) #pragma warning disable S1104 // Fields should not have public accessibility (Justification: Read above.) #pragma warning disable SA1300 // Element should begin with upper-case letter (Justification: Read above.) public Transform transform => Component.transform; diff --git a/MiraAPI/Keybinds/KeybindManager.cs b/MiraAPI/Keybinds/KeybindManager.cs index 1d71254a..2f0287d2 100644 --- a/MiraAPI/Keybinds/KeybindManager.cs +++ b/MiraAPI/Keybinds/KeybindManager.cs @@ -152,7 +152,7 @@ public static class KeybindManager public static List GetControllerConflicts(bool enabledOnly = false) { var conflicts = new List(); - var actions = Keybinds.Where(x => x.Exclusive && x.RewiredInputAction != null && (!enabledOnly || KeybindUtils.IsControllerActionActive(x.RewiredInputAction.id))).Select(x => x.RewiredInputAction!.id).ToHashSet(); + var actions = Keybinds.Where(x => x is { Exclusive: true, RewiredInputAction: not null } && (!enabledOnly || KeybindUtils.IsControllerActionActive(x.RewiredInputAction.id))).Select(x => x.RewiredInputAction!.id).ToHashSet(); var player = ReInput.players.GetPlayer(0); for (var i = 0; i < player.controllers.joystickCount; i++) { diff --git a/MiraAPI/LocalSettings/Attributes/LocalEnumSettingAttribute.cs b/MiraAPI/LocalSettings/Attributes/LocalEnumSettingAttribute.cs index 6932f4fe..af96fef2 100644 --- a/MiraAPI/LocalSettings/Attributes/LocalEnumSettingAttribute.cs +++ b/MiraAPI/LocalSettings/Attributes/LocalEnumSettingAttribute.cs @@ -21,7 +21,7 @@ public class LocalEnumSettingAttribute( private readonly string? _description = description; /// - public override LocalEnumSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase) + public override ILocalSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase) { return new LocalEnumSetting(tab, configEntryBase, configEntryBase.SettingType, _name, _description, names); } diff --git a/MiraAPI/LocalSettings/Attributes/LocalNumberSettingAttribute.cs b/MiraAPI/LocalSettings/Attributes/LocalNumberSettingAttribute.cs index 56c0f8c5..56c267c7 100644 --- a/MiraAPI/LocalSettings/Attributes/LocalNumberSettingAttribute.cs +++ b/MiraAPI/LocalSettings/Attributes/LocalNumberSettingAttribute.cs @@ -31,7 +31,7 @@ public class LocalNumberSettingAttribute( private readonly string? _description = description; /// - public override LocalNumberSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase) + public override ILocalSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase) { return new LocalNumberSetting(tab, configEntryBase, _name, _description, new FloatRange(min, max), increment, suffixType, formatString); } diff --git a/MiraAPI/LocalSettings/Attributes/LocalSliderSettingAttribute.cs b/MiraAPI/LocalSettings/Attributes/LocalSliderSettingAttribute.cs index d63334df..987dd8ea 100644 --- a/MiraAPI/LocalSettings/Attributes/LocalSliderSettingAttribute.cs +++ b/MiraAPI/LocalSettings/Attributes/LocalSliderSettingAttribute.cs @@ -33,7 +33,7 @@ public class LocalSliderSettingAttribute( private readonly string? _description = description; /// - public override LocalSliderSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase) + public override ILocalSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase) { return new LocalSliderSetting(tab, configEntryBase, _name, _description, new FloatRange(min, max), displayValue, suffixType, formatString, roundValue); } diff --git a/MiraAPI/LocalSettings/Attributes/LocalToggleSettingAttribute.cs b/MiraAPI/LocalSettings/Attributes/LocalToggleSettingAttribute.cs index 8b7abe8b..aad7edd5 100644 --- a/MiraAPI/LocalSettings/Attributes/LocalToggleSettingAttribute.cs +++ b/MiraAPI/LocalSettings/Attributes/LocalToggleSettingAttribute.cs @@ -19,7 +19,7 @@ public class LocalToggleSettingAttribute( private readonly string? _description = description; /// - public override LocalToggleSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase) + public override ILocalSetting CreateSetting(Type tab, ConfigEntryBase configEntryBase) { return new LocalToggleSetting(tab, configEntryBase, _name, _description); } diff --git a/MiraAPI/LocalSettings/SettingTypes/LocalSliderSetting.cs b/MiraAPI/LocalSettings/SettingTypes/LocalSliderSetting.cs index 2c813bbe..75909a28 100644 --- a/MiraAPI/LocalSettings/SettingTypes/LocalSliderSetting.cs +++ b/MiraAPI/LocalSettings/SettingTypes/LocalSliderSetting.cs @@ -108,14 +108,12 @@ public class LocalSliderSetting( /// protected override string GetValueText() { - if (DisplayValue) - { - var value = GetValue(); - var formatted = Helpers.FormatValue(value, SuffixType, FormatString); - var maxFormatted = Helpers.FormatValue(SliderRange.max, SuffixType, FormatString); - return $"{Name.Translate()}: {formatted} / {maxFormatted}"; - } + if (!DisplayValue) + return $"{Name.Translate()}"; - return $"{Name.Translate()}"; + var value = GetValue(); + var formatted = Helpers.FormatValue(value, SuffixType, FormatString); + var maxFormatted = Helpers.FormatValue(SliderRange.max, SuffixType, FormatString); + return $"{Name.Translate()}: {formatted} / {maxFormatted}"; } } diff --git a/MiraAPI/MeetingAbilities/MultiTargetMeetingButton.cs b/MiraAPI/MeetingAbilities/MultiTargetMeetingButton.cs index 6fb4bca6..21f70a17 100644 --- a/MiraAPI/MeetingAbilities/MultiTargetMeetingButton.cs +++ b/MiraAPI/MeetingAbilities/MultiTargetMeetingButton.cs @@ -56,7 +56,7 @@ public abstract class MultiTargetMeetingButton : TargetedMeetingButton } Timer = Cooldown; - UsesLeft -= 1; + UsesLeft--; OnFinish(); Targets = []; } diff --git a/MiraAPI/MiraApiSettings.cs b/MiraAPI/MiraApiSettings.cs index ad0b3c73..c6dcb0b3 100644 --- a/MiraAPI/MiraApiSettings.cs +++ b/MiraAPI/MiraApiSettings.cs @@ -195,68 +195,68 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config) /// Gets the scale of the ability buttons. /// [LocalSliderSetting(min: 0.5f, max: 1.5f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)] - public ConfigEntry ButtonUIFactorSlider { get; private set; } = config.Bind("MiraApi.VisualsUi", "MiraApi.ButtonScaleFactor", 0.75f); + public ConfigEntry ButtonUIFactorSlider { get; } = config.Bind("MiraApi.VisualsUi", "MiraApi.ButtonScaleFactor", 0.75f); /// /// Gets the scale of the UI buttons. /// [LocalSliderSetting(min: 0.3f, max: 2f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)] - public ConfigEntry TopRightButtonsFactorSlider { get; private set; } = config.Bind("MiraApi.VisualsUi", "MiraApi.TopRightButtonScaleFactor", 1f); + public ConfigEntry TopRightButtonsFactorSlider { get; } = config.Bind("MiraApi.VisualsUi", "MiraApi.TopRightButtonScaleFactor", 1f); /// /// Gets the fps specified by the player. /// [LocalSliderSetting(min: 60f, max: 240f, suffixType: MiraNumberSuffixes.None, formatString: "0", displayValue: true, roundValue: true)] - public ConfigEntry SetFpsSlider { get; private set; } = config.Bind("MiraApi.VisualsUi", "Max FPS", 120f); + public ConfigEntry SetFpsSlider { get; } = config.Bind("MiraApi.VisualsUi", "Max FPS", 120f); /// /// Gets whether the modifiers hud should be on the left side of the screen (under roles/task tab). Recommended for streamers. /// [LocalToggleSetting] - public ConfigEntry ModifiersHudLeftSide { get; private set; } = config.Bind("MiraApi.VisualsUi", "MiraApi.ShowModifiersHudOnLeftSide", false); + public ConfigEntry ModifiersHudLeftSide { get; } = config.Bind("MiraApi.VisualsUi", "MiraApi.ShowModifiersHudOnLeftSide", false); /// /// Gets whether to show keybinds on buttons. /// [LocalToggleSetting] - public ConfigEntry ShowKeybinds { get; private set; } = config.Bind("MiraApi.VisualsUi", "MiraApi.ShowKeybindsOnButtons", true); + public ConfigEntry ShowKeybinds { get; } = config.Bind("MiraApi.VisualsUi", "MiraApi.ShowKeybindsOnButtons", true); /// /// Gets the scale of the match info guide. /// [LocalSliderSetting(min: 0.5f, max: 1f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)] - public ConfigEntry MatchInfoGuideScaleFactor { get; private set; } = config.Bind("MiraApi.MatchInfoGuide", "MiraApi.MatchInfoGuideScaleFactor", 1f); + public ConfigEntry MatchInfoGuideScaleFactor { get; } = config.Bind("MiraApi.MatchInfoGuide", "MiraApi.MatchInfoGuideScaleFactor", 1f); /// /// Gets the flag indicating whether the wiki is on the bottom row. /// [LocalToggleSetting] - public ConfigEntry WikiOnBottomRow { get; private set; } = config.Bind("MiraApi.MatchInfoGuide", "MiraApi.WikiOnBottomRow", true); + public ConfigEntry WikiOnBottomRow { get; } = config.Bind("MiraApi.MatchInfoGuide", "MiraApi.WikiOnBottomRow", true); /// /// Gets the flag indicating the position for the wiki's tabs. /// [LocalEnumSetting(names: ["MiraApi.WikiTabPosition.LeftSide", "MiraApi.WikiTabPosition.RightSide", "MiraApi.WikiTabPosition.Below"])] - public ConfigEntry WikiTabPosition { get; private set; } = + public ConfigEntry WikiTabPosition { get; } = config.Bind("MiraApi.MatchInfoGuide", "MiraApi.WikiTabPosition", MiraApiPlugin.IsMobile ? MatchInfoTabPos.RightSide : MatchInfoTabPos.LeftSide); /// /// Gets whether to show the red flash from sabotages. /// [LocalToggleSetting] - public ConfigEntry EnableSabotageFlashes { get; private set; } = config.Bind("MiraApi.Accessibility", "MiraApi.EnableSabotageFlashes", true); + public ConfigEntry EnableSabotageFlashes { get; } = config.Bind("MiraApi.Accessibility", "MiraApi.EnableSabotageFlashes", true); /// /// Gets whether to enable the sabotage sound effects or not. /// [LocalToggleSetting] - public ConfigEntry EnableSabotageBlares { get; private set; } = config.Bind("MiraApi.Accessibility", "MiraApi.EnableSabotageBlare", true); + public ConfigEntry EnableSabotageBlares { get; } = config.Bind("MiraApi.Accessibility", "MiraApi.EnableSabotageBlare", true); /// /// Gets whether variable colors will remain static or not. /// [LocalToggleSetting] - public ConfigEntry EnableVariableColors { get; private set; } = config.Bind("MiraApi.Accessibility", "MiraApi.EnableVariableColors", true); + public ConfigEntry EnableVariableColors { get; } = config.Bind("MiraApi.Accessibility", "MiraApi.EnableVariableColors", true); } /// diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs index 45254c81..f7a28caf 100644 --- a/MiraAPI/Patches/RoleGuidePatches.cs +++ b/MiraAPI/Patches/RoleGuidePatches.cs @@ -1224,25 +1224,25 @@ public static class RoleGuidePatches public static IEnumerable GetActiveRoles() { - IEnumerable comparisons = []; + var player = PlayerControl.LocalPlayer; + var data = player != null ? player.Data : null; - var curRole = PlayerControl.LocalPlayer.Data.Role; + if (player == null || data == null) + yield break; - comparisons = comparisons.AddItem(curRole); + var curRole = data.Role; + yield return curRole; - if (PlayerControl.LocalPlayer && PlayerControl.LocalPlayer.Data && PlayerControl.LocalPlayer.Data.IsDead && - !comparisons.Any(x => x.Role == PlayerControl.LocalPlayer.Data.RoleWhenAlive.Value)) + if (data.IsDead && curRole.Role != data.RoleWhenAlive.Value) { - comparisons = comparisons.AddItem(RoleManager.Instance.GetRole(PlayerControl.LocalPlayer.Data.RoleWhenAlive.Value)); + yield return RoleManager.Instance.GetRole(data.RoleWhenAlive.Value); } - - return comparisons; } public static List GetActiveIds() { var activeModifiers = GetActiveModifiers(); - List comparisons = activeModifiers.Select(x => x.TypeId).ToList(); + var comparisons = activeModifiers.Select(x => x.TypeId).ToList(); comparisons.AddRange(GetActiveRoles().Select(x => (uint)x.Role)); return comparisons; @@ -1251,9 +1251,9 @@ public static class RoleGuidePatches private static List SortEntries(List entries, string searchText) { var activeModifiers = PlayerControl.LocalPlayer.GetModifiers().Select(x => x.TypeId); - var roles = GetActiveRoles().Select(x => (uint)x.Role).ToList(); - List comparisons = activeModifiers.ToList(); - comparisons.AddRange(roles); + var roles = GetActiveRoles().Select(x => (uint)x.Role).ToHashSet(); + var comparisons = activeModifiers.ToHashSet(); + comparisons.UnionWith(roles); var comparer = new BasicGuideComparer(comparisons); @@ -1262,7 +1262,7 @@ public static class RoleGuidePatches .ThenByDescending(p => p.Title.Contains(searchText, StringComparison.OrdinalIgnoreCase) || p.Category.Contains(searchText, StringComparison.OrdinalIgnoreCase)) - .ThenBy(x => x.Modifier != null ? x.Modifier.TypeId : (uint)x.Role!.Role, comparer); + .ThenBy(x => x.Modifier?.TypeId ?? (uint)x.Role!.Role, comparer); return [ .. _sortMethod is SortingMethod.Alphabetical diff --git a/MiraAPI/Presets/OptionPreset.cs b/MiraAPI/Presets/OptionPreset.cs index 90eb3894..290f6e1d 100644 --- a/MiraAPI/Presets/OptionPreset.cs +++ b/MiraAPI/Presets/OptionPreset.cs @@ -87,6 +87,6 @@ public class OptionPreset(string name, MiraPluginInfo plugin, ConfigFile presetC public bool IsOptionInPreset(OptionBehaviour baseOption) { var selectedOpt = Plugin.InternalOptions.FirstOrDefault(x => x.OptionBehaviour == baseOption); - return selectedOpt != null && selectedOpt.ConfigDefinition != null && PresetConfig.ContainsKey(selectedOpt.ConfigDefinition); + return selectedOpt?.ConfigDefinition != null && PresetConfig.ContainsKey(selectedOpt.ConfigDefinition); } } diff --git a/MiraAPI/Utilities/Assets/MiraAssets.cs b/MiraAPI/Utilities/Assets/MiraAssets.cs index 66386aa2..f1fa012f 100644 --- a/MiraAPI/Utilities/Assets/MiraAssets.cs +++ b/MiraAPI/Utilities/Assets/MiraAssets.cs @@ -9,13 +9,13 @@ namespace MiraAPI.Utilities.Assets; /// public static class MiraAssets { - private static readonly Assembly _assembly = typeof(MiraAssets).Assembly; + private static readonly Assembly Assembly = typeof(MiraAssets).Assembly; static MiraAssets() { var boxTex = SpriteTools.LoadTextureFromResourcePath( "MiraAPI.Resources.RoundedBox.png", - _assembly); + Assembly); var boxSprite = Sprite.Create( boxTex, new Rect(0, 0, boxTex.width, boxTex.height), @@ -36,7 +36,7 @@ public static class MiraAssets /// /// Gets the Mira API . /// - public static AssetBundle MiraAssetBundle { get; } = AssetBundleManager.Load("mirabundle"); + public static AssetBundle MiraAssetBundle { get; } = AssetBundleManager.Load(Assembly, "mirabundle"); /// /// Gets the ModifierDisplay prefab. @@ -61,7 +61,7 @@ public static class MiraAssets /// /// Gets the empty asset. /// - public static LoadableResourceAsset Empty { get; } = new("MiraAPI.Resources.Empty.png", _assembly); + public static LoadableResourceAsset Empty { get; } = new("MiraAPI.Resources.Empty.png", Assembly); /// /// Gets the RoundedBox , which is a rounded rectangle used for UI elements. @@ -71,312 +71,312 @@ public static class MiraAssets /// /// Gets the Next Button sprite. /// - public static LoadableResourceAsset NextButton { get; } = new("MiraAPI.Resources.NextButton.png", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + 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", _assembly); + public static LoadableResourceAsset TabButtonContainer { get; } = new("MiraAPI.Resources.Wiki.TabButtonContainer.png", Assembly); - internal static LoadableResourceAsset BlankSprite { get; } = new("MiraAPI.Resources.BlankSprite.png", _assembly); + internal static LoadableResourceAsset BlankSprite { get; } = new("MiraAPI.Resources.BlankSprite.png", Assembly); } diff --git a/MiraAPI/Utilities/BasicGuideComparer.cs b/MiraAPI/Utilities/BasicGuideComparer.cs index 15cef202..c9d7f64b 100644 --- a/MiraAPI/Utilities/BasicGuideComparer.cs +++ b/MiraAPI/Utilities/BasicGuideComparer.cs @@ -1,6 +1,4 @@ -using System; using System.Collections.Generic; -using System.Linq; namespace MiraAPI.Utilities; @@ -10,22 +8,13 @@ namespace MiraAPI.Utilities; /// The collection of currently active IDs. public class BasicGuideComparer(IEnumerable activeIds) : IComparer { + private readonly HashSet _activeIds = activeIds as HashSet ?? [.. activeIds]; + /// public int Compare(uint x, uint y) { - var xActive = activeIds.Contains(x); - var yActive = activeIds.Contains(y); - - if (xActive && !yActive) - { - return -1; - } - - if (!xActive && yActive) - { - return 1; - } - - return 0; + var xActive = _activeIds.Contains(x); + var yActive = _activeIds.Contains(y); + return yActive.CompareTo(xActive); } } diff --git a/MiraAPI/Utilities/Helpers.cs b/MiraAPI/Utilities/Helpers.cs index f5d7d25d..d08a4a00 100644 --- a/MiraAPI/Utilities/Helpers.cs +++ b/MiraAPI/Utilities/Helpers.cs @@ -897,9 +897,8 @@ public static class Helpers return; } - var cachedPrefab = Object.Instantiate(rowPrefab!.gameObject); + var cachedPrefab = Object.Instantiate(rowPrefab!.gameObject, null, false); cachedPrefab.name = "MiraAPIAdvancedSettingsRowPrefab"; - cachedPrefab.transform.SetParent(null, false); cachedPrefab.transform.localPosition = Vector3.zero; cachedPrefab.transform.localRotation = Quaternion.identity; cachedPrefab.SetActive(false); @@ -919,9 +918,7 @@ public static class Helpers { return CreateAdvancedSettingsPage( parent, - [.. settings.Select(setting => new AdvancedSettingsRow(setting.Key, setting.Value, null))], - 2, - false); + [.. settings.Select(setting => new AdvancedSettingsRow(setting.Key, setting.Value, null))]); } internal static GameObject CreateAdvancedSettingsPage( diff --git a/MiraAPI/Utilities/StateMachineWrapper.cs b/MiraAPI/Utilities/StateMachineWrapper.cs index cfe5d8a1..298feb19 100644 --- a/MiraAPI/Utilities/StateMachineWrapper.cs +++ b/MiraAPI/Utilities/StateMachineWrapper.cs @@ -23,12 +23,10 @@ public class StateMachineWrapper private readonly Dictionary _propertyCache; private readonly Type _type; - private T? _parentInstance; - /// /// Gets the instance of the . /// - public T Instance => _parentInstance ??= (T)_thisProperty.GetValue(_stateMachine)!; + public T Instance => field ??= (T)_thisProperty.GetValue(_stateMachine)!; /// /// Initializes a new instance of the class. diff --git a/MiraAPI/Voting/PlayerVoteData.cs b/MiraAPI/Voting/PlayerVoteData.cs index ad07aeb1..a1cce380 100644 --- a/MiraAPI/Voting/PlayerVoteData.cs +++ b/MiraAPI/Voting/PlayerVoteData.cs @@ -30,11 +30,10 @@ public class PlayerVoteData(nint cppPtr) : MonoBehaviour(cppPtr) /// public int VotesRemaining { - get => _votesRemaining; - set => _votesRemaining = Math.Max(0, value); + get; + set => field = Math.Max(0, value); } - - private int _votesRemaining = 1; + = 1; [SuppressMessage("Style", "IDE0051:Remove unused private members", Justification = "Unity convention.")] private void Awake()