diff --git a/.editorconfig b/.editorconfig index af9feb4..2f48813 100644 --- a/.editorconfig +++ b/.editorconfig @@ -86,3 +86,15 @@ dotnet_diagnostic.SA1133.severity = none # IDE0001: Simplify Names dotnet_diagnostic.IDE0001.severity = warning + +# IDE0079: Remove unnecessary suppression +dotnet_diagnostic.IDE0079.severity = none + +# S3903: Types should be defined in named namespaces +dotnet_diagnostic.S3903.severity = none + +# IDE0045: Convert to conditional expression +dotnet_diagnostic.IDE0045.severity = none + +# IDE0046: Convert to conditional expression +dotnet_diagnostic.IDE0046.severity = none diff --git a/MiraAPI.Example/.editorconfig b/MiraAPI.Example/.editorconfig new file mode 100644 index 0000000..171e612 --- /dev/null +++ b/MiraAPI.Example/.editorconfig @@ -0,0 +1,4 @@ +[*.{cs,vb}] + +# SA1602: Enumeration items should be documented. +dotnet_diagnostic.SA1602.severity = none diff --git a/MiraAPI.Example/Resources/Locale/en_US.xml b/MiraAPI.Example/Resources/Locale/en_US.xml index e370dc3..56f74c8 100644 --- a/MiraAPI.Example/Resources/Locale/en_US.xml +++ b/MiraAPI.Example/Resources/Locale/en_US.xml @@ -16,11 +16,11 @@ Your votes have double the power. You get one extra vote in the meeting! The Mayor is a Crewmate role that gets two votes in the meeting, instead of the singular vote other Crewmates get. - Chamelon - Become one with the environment. - Fade out of everyone's vision by not moving. - Stay invisible while not moving. - The Chamelon is a Crewmate role that slowly becomes invisible while standing still. + Chameleon + Become one with the environment. + Fade out of everyone's vision by not moving. + Stay invisible while not moving. + The Chameleon is a Crewmate role that slowly becomes invisible while standing still. Outcast Killer Kill everyone else. Be the last outcast standing. @@ -73,7 +73,7 @@ Eliminate every other faction. Example Bool 2 Slider Example Number - Example Multplier + Example Multiplier Example Enum Example Button Outcast Killer Wins! diff --git a/MiraAPI/GameModes/HideAndSeekMode.cs b/MiraAPI/GameModes/HideAndSeekMode.cs index 316c3cf..ec99ce9 100644 --- a/MiraAPI/GameModes/HideAndSeekMode.cs +++ b/MiraAPI/GameModes/HideAndSeekMode.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Linq; using AmongUs.Data; @@ -462,7 +461,6 @@ public class HideAndSeekMode : AbstractGameMode } /// - [SuppressMessage("Style", "IDE0046:Convert to conditional expression", Justification = "Warning cascades into forcing the entire tree to be ternary operators.")] public override PlayerBodyTypes GetBodyType(PlayerControl player) { if (player == null || player.Data == null || player.Data.Role == null) diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs index 646de56..40cf0f8 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs @@ -43,7 +43,7 @@ public class ModdedPlayerOption : ModdedOption data.Title = StringName; data.Type = global::OptionTypes.Player; - Values = new(); + Values = []; AllowNone = allowNone; Value = DefaultValue; } diff --git a/MiraAPI/Hud/CustomPaginableMenu.cs b/MiraAPI/Hud/CustomPaginableMenu.cs index 27f7819..f24ccee 100644 --- a/MiraAPI/Hud/CustomPaginableMenu.cs +++ b/MiraAPI/Hud/CustomPaginableMenu.cs @@ -100,7 +100,6 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu GetFilteredEntries() { var query = NormalizeForSearch(searchText); diff --git a/MiraAPI/MiraApiPlugin.cs b/MiraAPI/MiraApiPlugin.cs index 4da8968..a07c36d 100644 --- a/MiraAPI/MiraApiPlugin.cs +++ b/MiraAPI/MiraApiPlugin.cs @@ -64,11 +64,9 @@ public partial class MiraApiPlugin : BasePlugin, IMiraPlugin private static MiraPluginManager? PluginManager { get; set; } internal Harmony Harmony { get; } = new(Id); - public static ConfigEntry WikiSortingGroup { get; private set; } - - public static ConfigEntry WikiSortingMethod { get; private set; } - - public static ConfigEntry WikiSortingFilter { get; private set; } + internal static ConfigEntry WikiSortingGroup { get; private set; } + internal static ConfigEntry WikiSortingMethod { get; private set; } + internal static ConfigEntry WikiSortingFilter { get; private set; } /// public override void Load() diff --git a/MiraAPI/Patches/.editorconfig b/MiraAPI/Patches/.editorconfig index 2622fc7..a019ed9 100644 --- a/MiraAPI/Patches/.editorconfig +++ b/MiraAPI/Patches/.editorconfig @@ -12,5 +12,5 @@ dotnet_diagnostic.SA1611.severity = none # SA1615: Element return value should be documented. dotnet_diagnostic.SA1615.severity = none -# S125: Sections of code should not be commented out. -dotnet_diagnostic.S125.severity = none \ No newline at end of file +# SA1602: Enumeration items should be documented. +dotnet_diagnostic.SA1602.severity = none \ No newline at end of file diff --git a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs index e65f4c3..7e2b312 100644 --- a/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs +++ b/MiraAPI/Patches/Options/GameOptionsMenuPatch.cs @@ -25,9 +25,9 @@ namespace MiraAPI.Patches.Options; [HarmonyPatch(typeof(GameOptionsMenu))] internal static class GameOptionsMenuPatch { - private static readonly List VanillaHeaders = new(); - private static readonly List VanillaOptions = new(); - private static readonly List MainOptions = new(); + private static readonly List VanillaHeaders = []; + private static readonly List VanillaOptions = []; + private static readonly List MainOptions = []; private static readonly Dictionary> GameModeGroups = []; private static readonly Dictionary> GameModeOptions = []; private static readonly Dictionary> GameModeHeaders = []; diff --git a/MiraAPI/Patches/Options/SettingPatches.cs b/MiraAPI/Patches/Options/SettingPatches.cs index 8fd6581..59b956c 100644 --- a/MiraAPI/Patches/Options/SettingPatches.cs +++ b/MiraAPI/Patches/Options/SettingPatches.cs @@ -1,5 +1,4 @@ -using System.Diagnostics.CodeAnalysis; -using System.Globalization; +using System.Globalization; using System.Linq; using HarmonyLib; using MiraAPI.GameOptions; @@ -24,7 +23,6 @@ public static class SettingPatches /// to skip original method. [HarmonyPrefix] [HarmonyPatch(typeof(FloatGameSetting), nameof(FloatGameSetting.GetValueString))] - [SuppressMessage("Style", "IDE0045:Convert to conditional expression", Justification = "Warning cascades into forcing the entire tree to be ternary operators.")] public static bool ValueStringPatch( FloatGameSetting __instance, ref string __result, diff --git a/MiraAPI/Patches/RoleGuidePatches.cs b/MiraAPI/Patches/RoleGuidePatches.cs index 92080e8..508b3f7 100644 --- a/MiraAPI/Patches/RoleGuidePatches.cs +++ b/MiraAPI/Patches/RoleGuidePatches.cs @@ -33,20 +33,13 @@ public static class RoleGuidePatches private static readonly List RoleEntries = []; private static readonly List ModifierEntries = []; - public static GameObject SearchComponentContainer; - public static PassiveButton SearchIconButton; + private static GameObject searchComponentContainer; private static SpriteRenderer _searchIconIdle; private static SpriteRenderer _searchIconHover; - public static TextMeshPro OrderSortingTmp; - public static PassiveButton SearchSortingOrderButton; private static SpriteRenderer _searchSortingOrderIdle; private static SpriteRenderer _searchSortingOrderHover; - public static TextMeshPro GroupSortingTmp; - public static PassiveButton SearchSortingGroupButton; private static SpriteRenderer _searchSortingGroupIdle; private static SpriteRenderer _searchSortingGroupHover; - public static TextMeshPro FilterSortingTmp; - public static PassiveButton SearchSortingFilterButton; private static SpriteRenderer _searchSortingFilterIdle; private static SpriteRenderer _searchSortingFilterHover; private static Scroller _rolesScroller; @@ -153,10 +146,6 @@ public static class RoleGuidePatches _advancedInfoTabScroller = null!; _currentAdvancedTabObject = null!; _loadingSpinner = null; - SearchIconButton = null!; - SearchSortingOrderButton = null!; - SearchSortingGroupButton = null!; - SearchSortingFilterButton = null!; _searchIconIdle = null!; _searchIconHover = null!; _searchSortingOrderIdle = null!; @@ -260,6 +249,7 @@ public static class RoleGuidePatches _titleText.transform.GetComponent().Destroy(); } } + if (!_titleIcon) { var titleIconObj = new GameObject("TitleIcon"); @@ -369,18 +359,18 @@ public static class RoleGuidePatches _guide = instance; _loading = false; - SearchComponentContainer = new GameObject(); - SearchComponentContainer.transform.SetParent(instance.MatchInfoParent.transform); - SearchComponentContainer.transform.localPosition = Vector3.zero; - instance.MatchInfoParent.transform.GetChild(1).transform.SetParent(SearchComponentContainer.transform); + searchComponentContainer = new GameObject(); + searchComponentContainer.transform.SetParent(instance.MatchInfoParent.transform); + searchComponentContainer.transform.localPosition = Vector3.zero; + instance.MatchInfoParent.transform.GetChild(1).transform.SetParent(searchComponentContainer.transform); var sortingOrderButton = Object.Instantiate( HudManager.Instance.SettingsButton, - SearchComponentContainer.transform); + searchComponentContainer.transform); sortingOrderButton.gameObject.SetActive(true); - SearchSortingOrderButton = sortingOrderButton.GetComponent(); + var searchSortingOrderButton = sortingOrderButton.GetComponent(); SetupSearchButton( - SearchSortingOrderButton, + searchSortingOrderButton, "SearchSortingOrderButton", SwitchMethod, GetSortMethodSprite(_sortMethod, false), @@ -391,11 +381,11 @@ public static class RoleGuidePatches var sortingGroupButton = Object.Instantiate( sortingOrderButton, - SearchComponentContainer.transform); + searchComponentContainer.transform); sortingGroupButton.gameObject.SetActive(true); - SearchSortingGroupButton = sortingGroupButton.GetComponent(); + var searchSortingGroupButton = sortingGroupButton.GetComponent(); SetupSearchButton( - SearchSortingGroupButton, + searchSortingGroupButton, "SearchSortingGroupButton", SwitchGrouping, GetSortGroupSprite(_sortGrouping, false), @@ -406,11 +396,11 @@ public static class RoleGuidePatches var sortingFilterButton = Object.Instantiate( sortingOrderButton, - SearchComponentContainer.transform); + searchComponentContainer.transform); sortingFilterButton.gameObject.SetActive(true); - SearchSortingFilterButton = sortingFilterButton.GetComponent(); + var searchSortingFilterButton = sortingFilterButton.GetComponent(); SetupSearchButton( - SearchSortingFilterButton, + searchSortingFilterButton, "SearchSortingFilterButton", SwitchFilter, GetSortFilterSprite(_sortFilter, false), @@ -463,9 +453,8 @@ public static class RoleGuidePatches sortingOrderButton, sortingOrderButton.transform.parent); searchIconButton.gameObject.SetActive(true); - SearchIconButton = searchIconButton.GetComponent(); SetupSearchButton( - SearchIconButton, + searchIconButton.GetComponent(), "SearchIconButton", ClearSearchText, MiraAssets.SearchIconIdleSprite, @@ -476,7 +465,7 @@ public static class RoleGuidePatches var searchBox = Object.Instantiate( instance.TabButtons[2].gameObject, - SearchComponentContainer.transform); + searchComponentContainer.transform); var searchButton = searchBox.GetComponent(); var tmpText = searchButton.transform.GetChild(0).GetComponent(); tmpText.GetComponent().Destroy(); @@ -621,26 +610,26 @@ public static class RoleGuidePatches modifiersButton.OnClick.AddListener((Action)(() => OpenModifiersTab())); instance.TabButtons.Add(modifiersButton); - OrderSortingTmp = Object.Instantiate( + var orderSortingTmp = Object.Instantiate( _titleText, sortingOrderButton.transform); - OrderSortingTmp.text = MiraLocaleManager.Get("MiraApi.Wiki.OrderLabel"); - OrderSortingTmp.fontSize = OrderSortingTmp.fontSizeMax = 3f; - OrderSortingTmp.alignment = TextAlignmentOptions.Center; - OrderSortingTmp.horizontalAlignment = HorizontalAlignmentOptions.Center; - OrderSortingTmp.transform.localPosition = new Vector3(-0.65f, 0.4f, 0); + orderSortingTmp.text = MiraLocaleManager.Get("MiraApi.Wiki.OrderLabel"); + orderSortingTmp.fontSize = orderSortingTmp.fontSizeMax = 3f; + orderSortingTmp.alignment = TextAlignmentOptions.Center; + orderSortingTmp.horizontalAlignment = HorizontalAlignmentOptions.Center; + orderSortingTmp.transform.localPosition = new Vector3(-0.65f, 0.4f, 0); - GroupSortingTmp = Object.Instantiate( - OrderSortingTmp, + var groupSortingTmp = Object.Instantiate( + orderSortingTmp, sortingGroupButton.transform); - OrderSortingTmp.text = MiraLocaleManager.Get("MiraApi.Wiki.GroupingLabel"); - GroupSortingTmp.transform.localPosition = new Vector3(-0.65f, 0.4f, 0); + orderSortingTmp.text = MiraLocaleManager.Get("MiraApi.Wiki.GroupingLabel"); + groupSortingTmp.transform.localPosition = new Vector3(-0.65f, 0.4f, 0); - FilterSortingTmp = Object.Instantiate( - OrderSortingTmp, + var filterSortingTmp = Object.Instantiate( + orderSortingTmp, sortingFilterButton.transform); - FilterSortingTmp.text = MiraLocaleManager.Get("MiraApi.Wiki.FilterLabel"); - FilterSortingTmp.transform.localPosition = new Vector3(-0.65f, 0.4f, 0); + filterSortingTmp.text = MiraLocaleManager.Get("MiraApi.Wiki.FilterLabel"); + filterSortingTmp.transform.localPosition = new Vector3(-0.65f, 0.4f, 0); playerButton.transform.localPosition = new Vector3(-3.6f, 0.656f, -0.2f); settingButton.transform.localPosition = new Vector3(-3.6f, 0.056f, -0.2f); @@ -731,11 +720,17 @@ public static class RoleGuidePatches } } - public static void OpenModifiersTab() => OpenTab(ModifiersTabIndex); + public static void OpenModifiersTab() + { + OpenTab(ModifiersTabIndex); + } - public static void OpenRolesTab() => OpenTab(RolesTabIndex); + public static void OpenRolesTab() + { + OpenTab(RolesTabIndex); + } - public sealed class DetailedPanel(string title, string category, string modId, RoleBehaviour? role, GameModifier? modifier) + private sealed class DetailedPanel(string title, string category, string modId, RoleBehaviour? role, GameModifier? modifier) { public MatchInfoRolePanel? Panel { get; set; } public string Title { get; } = title; @@ -803,14 +798,7 @@ public static class RoleGuidePatches private static IEnumerator CoPopulate(float delay) { - if (delay > 0f) - { - yield return new WaitForSeconds(delay); - } - else - { - yield return null; - } + yield return delay > 0f ? new WaitForSeconds(delay) : null; if (!_guide) { @@ -1048,14 +1036,8 @@ public static class RoleGuidePatches public static void SwitchFilter() { var stepUp = (SortingFilter)((int)_sortFilter + 1); - if (Enum.IsDefined(stepUp)) - { - _sortFilter = stepUp; - } - else - { - _sortFilter = SortingFilter.EnabledOnly; - } + + _sortFilter = Enum.IsDefined(stepUp) ? stepUp : SortingFilter.EnabledOnly; MiraApiPlugin.WikiSortingFilter.Value = _sortFilter; @@ -1094,14 +1076,8 @@ public static class RoleGuidePatches public static void SwitchMethod() { var stepUp = (SortingMethod)((int)_sortMethod + 1); - if (Enum.IsDefined(stepUp)) - { - _sortMethod = stepUp; - } - else - { - _sortMethod = SortingMethod.Alphabetical; - } + + _sortMethod = Enum.IsDefined(stepUp) ? stepUp : SortingMethod.Alphabetical; MiraApiPlugin.WikiSortingMethod.Value = _sortMethod; @@ -1288,7 +1264,7 @@ public static class RoleGuidePatches } _advancedInfoTabScroller?.gameObject.SetActive(false); - SearchComponentContainer?.SetActive(true); + searchComponentContainer?.SetActive(true); UpdateSpinner(); } @@ -1341,9 +1317,9 @@ public static class RoleGuidePatches _currentAdvancedTabObject.Destroy(); } - if (SearchComponentContainer) + if (searchComponentContainer) { - SearchComponentContainer.SetActive(false); + searchComponentContainer.SetActive(false); } if (_advancedInfoTabScroller == null) @@ -1543,20 +1519,20 @@ public static class RoleGuidePatches } } -public enum SortingGroups +internal enum SortingGroups { Ungrouped, Faction, AmountChance, } -public enum SortingMethod +internal enum SortingMethod { Alphabetical, AlphabeticalDescending, } -public enum SortingFilter +internal enum SortingFilter { EnabledOnly, DisabledOnly, diff --git a/MiraAPI/Patches/Stubs/RoleBehaviourStubs.cs b/MiraAPI/Patches/Stubs/RoleBehaviourStubs.cs index f047fd3..b856d22 100644 --- a/MiraAPI/Patches/Stubs/RoleBehaviourStubs.cs +++ b/MiraAPI/Patches/Stubs/RoleBehaviourStubs.cs @@ -39,10 +39,10 @@ public static class RoleBehaviourStubs } /// - /// Stub method for . + /// Stub method for . /// /// The object. - /// The to append the task hint to. + /// The to append the task hint to. [HarmonyReversePatch] [HarmonyPatch(typeof(RoleBehaviour), nameof(RoleBehaviour.AppendTaskHint), typeof(Il2CppSystem.Text.StringBuilder))] [MethodImpl(MethodImplOptions.NoInlining)] diff --git a/MiraAPI/Presets/SavePresetPopup.cs b/MiraAPI/Presets/SavePresetPopup.cs index b9932ff..9405e83 100644 --- a/MiraAPI/Presets/SavePresetPopup.cs +++ b/MiraAPI/Presets/SavePresetPopup.cs @@ -16,6 +16,7 @@ namespace MiraAPI.Presets; [RegisterInIl2Cpp] [SuppressMessage("Style", "IDE0051:Remove unused private members", Justification = "Unity convention.")] +[SuppressMessage("Design", "CA1050:Declare types in namespaces", Justification = "Unity script.")] #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member (Justification: Unity fields; ignore.) public class SavePresetPopup(nint cppPtr) : Minigame(cppPtr) { diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index 4d5e247..88b1f85 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -345,7 +345,14 @@ public interface ICustomRole : IOptionable /// Gets the list of abilities or other similar information to display below the text of a role's wiki page. /// [HideFromIl2Cpp] - public List WikiAbilities => []; + List WikiAbilities => []; } +/// +/// A data holder of an ability's wiki entry. +/// +/// The name of the ability. +/// The type of the ability. +/// The description of the ability. +/// The icon sprite of the ability. public record struct AdvancedWikiAbilityDescription(string Name, string AbilityType, string Description, LoadableAsset Icon); diff --git a/MiraAPI/Translation/MiraLocaleManager.cs b/MiraAPI/Translation/MiraLocaleManager.cs index d26f422..0bce8ca 100644 --- a/MiraAPI/Translation/MiraLocaleManager.cs +++ b/MiraAPI/Translation/MiraLocaleManager.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Reflection; @@ -162,7 +161,6 @@ public static class MiraLocaleManager /// The string id to find. /// Fallback string to use if no translation is found. /// A based on the key provided. - [SuppressMessage("Style", "IDE0046:Convert to conditional expression", Justification = "Warning cascades into forcing the entire tree to be ternary operators.")] public static string Get(MiraLanguage language, string key, string fallback = "") { if (Locale.TryGetValue(language, out var translations) && diff --git a/MiraAPI/Utilities/ControllableComparer.cs b/MiraAPI/Utilities/ControllableComparer.cs index 49c4b0e..5e7ac70 100644 --- a/MiraAPI/Utilities/ControllableComparer.cs +++ b/MiraAPI/Utilities/ControllableComparer.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.Linq; namespace MiraAPI.Utilities; @@ -9,7 +8,6 @@ internal sealed class ControllableComparer(T[] forcedToBottom, T[] forcedToTo where T : IComparable { /// - [SuppressMessage("Style", "IDE0046:Convert to conditional expression", Justification = "Warning cascades into forcing the entire tree to be ternary operators.")] public int Compare(T? x, T? y) { if ((forcedToBottom.Contains(x) && forcedToBottom.Contains(y)) || (forcedToTop.Contains(x) && forcedToTop.Contains(y))) diff --git a/MiraAPI/Utilities/Helpers.cs b/MiraAPI/Utilities/Helpers.cs index 773a4ae..413fb59 100644 --- a/MiraAPI/Utilities/Helpers.cs +++ b/MiraAPI/Utilities/Helpers.cs @@ -32,6 +32,11 @@ public static class Helpers { private static readonly Regex TrailingZeroRegex = new(@"\.0+(?!\d)", RegexOptions.Compiled, TimeSpan.FromMilliseconds(100)); + /// + /// Gets all of the options stored within the provided type. + /// + /// The type to get the options of. + /// A readonly list of options from the provided type. public static ReadOnlyCollection? GetModdedOptionsForType(Type classType) { var group = ModdedOptionsManager.Groups.FirstOrDefault(x => x.OptionableType == classType); @@ -39,6 +44,11 @@ public static class Helpers return group?.Children; } + /// + /// Gets the option text of the provided type. + /// + /// The type to get the text for. + /// The options text of the provided type. public static string GetOptionsText(Type classType) { var group = ModdedOptionsManager.Groups.FirstOrDefault(x => x.OptionableType == classType); @@ -836,7 +846,7 @@ public static class Helpers obj.transform.SetParent(parent.Inner.transform); obj.transform.localPosition = new Vector3(0f, 0.5f, 0f); var scrollHeight = variableTextSizing - ? (desc.textBounds.size.y - 2.5f) + maxTextSize + 0.475f + ? desc.textBounds.size.y - 2.5f + maxTextSize + 0.475f : desc.textBounds.size.y - 2.5f + Mathf.Ceil(num / 2f) * 1.45f; parent.SetYBoundsMax(Mathf.Clamp(scrollHeight, 0f, 999f)); return obj; @@ -857,6 +867,7 @@ public static class Helpers panel.roleDescription.fontSizeMin = 1.5f; panel.roleDescription.ForceMeshUpdate(); } + panel.roleIcon.sprite = ability.Icon.LoadAsset(); panel.roleIcon.SetSizeLimit(0.13f);