From 1d405adb557f2e6d018c220d83f59bed78730027 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 28 Dec 2022 00:32:20 +0800 Subject: [PATCH 1/3] Can use generic type instead. --- .../Screens/Edit/Beatmap/TestSceneLyricEditorScreen.cs | 2 +- .../Screens/Edit/Import/TestSceneLyricImporter.cs | 2 +- osu.Game.Rulesets.Karaoke/Skinning/KaraokeBeatmapSkin.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestSceneLyricEditorScreen.cs b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestSceneLyricEditorScreen.cs index eb038e724..d438d295e 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestSceneLyricEditorScreen.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestSceneLyricEditorScreen.cs @@ -109,7 +109,7 @@ public void TestSingerMode() private void switchToMode(LyricEditorMode mode) { - AddStep($"switch to mode {Enum.GetName(typeof(LyricEditorMode), mode)}", () => + AddStep($"switch to mode {Enum.GetName(mode)}", () => { bindableLyricEditorMode.Value = mode; }); diff --git a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Import/TestSceneLyricImporter.cs b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Import/TestSceneLyricImporter.cs index 52cf09aed..1baeec6a8 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Import/TestSceneLyricImporter.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Import/TestSceneLyricImporter.cs @@ -63,7 +63,7 @@ public void TestGoToStep() foreach (var step in steps) { - AddStep($"go to step {Enum.GetName(typeof(LyricImporterStep), step)}", () => { Screen.GoToStep(step); }); + AddStep($"go to step {Enum.GetName(step)}", () => { Screen.GoToStep(step); }); } } diff --git a/osu.Game.Rulesets.Karaoke/Skinning/KaraokeBeatmapSkin.cs b/osu.Game.Rulesets.Karaoke/Skinning/KaraokeBeatmapSkin.cs index a04a048b9..daa898ae3 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/KaraokeBeatmapSkin.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/KaraokeBeatmapSkin.cs @@ -37,7 +37,7 @@ public KaraokeBeatmapSkin(SkinInfo skin, IStorageResourceProvider? resources, IR var globalSetting = SkinJsonSerializableExtensions.CreateSkinElementGlobalSettings(); // we may want to move this to some kind of async operation in the future. - foreach (ElementType skinnableTarget in Enum.GetValues(typeof(ElementType))) + foreach (ElementType skinnableTarget in Enum.GetValues()) { string filename = $"{getFileNameByType(skinnableTarget)}.json"; From 8e628ac5f8420130c12285b29232a5d39b080ec8 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 28 Dec 2022 00:39:11 +0800 Subject: [PATCH 2/3] Stop using the "EnumUtils.GetValues()" Can use the "Enum.GetValues()" instead. --- .../Editor/Utils/HitObjectWritableUtilsTest.cs | 7 +++---- .../Graphics/TestSceneRightTriangle.cs | 4 ++-- .../Overlays/TestSceneOverlayColourProvider.cs | 5 ++--- .../Components/TestSceneLyricEditorColourProvider.cs | 3 +-- .../Screens/Edit/Beatmap/TestSceneLyricEditorScreen.cs | 7 +++---- .../Screens/Edit/Import/TestSceneLyricImporter.cs | 5 ++--- .../Skinning/TestSceneDrawableJudgement.cs | 4 ++-- .../Edit/Components/ContextMenu/LyricLockContextMenu.cs | 6 ++---- .../Edit/Components/Menus/EnumMenu.cs | 5 +---- .../Screens/Edit/Beatmaps/Lyrics/Compose/LyricComposer.cs | 3 +-- .../Beatmaps/Lyrics/Settings/LyricEditorEditModeSection.cs | 5 ++--- .../Lyrics/Settings/RubyRomaji/TextTagEditModeSection.cs | 2 +- .../Settings/TimeTags/TimeTagCreateConfigSubsection.cs | 3 +-- osu.Game.Rulesets.Karaoke/Screens/Edit/EditModeSection.cs | 5 ++--- osu.Game.Rulesets.Karaoke/Screens/Edit/IssueSection.cs | 3 +-- 15 files changed, 26 insertions(+), 41 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Utils/HitObjectWritableUtilsTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Utils/HitObjectWritableUtilsTest.cs index 2f958111e..abaf83ef0 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Utils/HitObjectWritableUtilsTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Utils/HitObjectWritableUtilsTest.cs @@ -9,7 +9,6 @@ using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Objects.Properties; using osu.Game.Rulesets.Karaoke.Objects.Types; -using osu.Game.Rulesets.Karaoke.Utils; namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Utils { @@ -24,7 +23,7 @@ public void TestIsRemoveLyricLocked() test(new Lyric()); // test lock state. - foreach (var lockState in EnumUtils.GetValues()) + foreach (var lockState in Enum.GetValues()) { test(new Lyric { @@ -61,7 +60,7 @@ public void TestIsWriteLyricPropertyLocked() test(new Lyric()); // test lock state. - foreach (var lockState in EnumUtils.GetValues()) + foreach (var lockState in Enum.GetValues()) { test(new Lyric { @@ -101,7 +100,7 @@ public void TestIsCreateOrRemoveNoteLocked() test(new Lyric()); // test lock state. - foreach (var lockState in EnumUtils.GetValues()) + foreach (var lockState in Enum.GetValues()) { test(new Lyric { diff --git a/osu.Game.Rulesets.Karaoke.Tests/Graphics/TestSceneRightTriangle.cs b/osu.Game.Rulesets.Karaoke.Tests/Graphics/TestSceneRightTriangle.cs index c733af726..b05f6d0d9 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Graphics/TestSceneRightTriangle.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Graphics/TestSceneRightTriangle.cs @@ -1,6 +1,7 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. +using System; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; @@ -8,7 +9,6 @@ using osu.Framework.Graphics.Shapes; using osu.Game.Graphics; using osu.Game.Rulesets.Karaoke.Graphics.Shapes; -using osu.Game.Rulesets.Karaoke.Utils; using osu.Game.Tests.Visual; using osuTK; @@ -45,7 +45,7 @@ private void load(OsuColour colours) [Test] public void TestRightAngleDirections() { - foreach (var direction in EnumUtils.GetValues()) + foreach (var direction in Enum.GetValues()) { AddStep($"Test direction {direction}", () => { diff --git a/osu.Game.Rulesets.Karaoke.Tests/Overlays/TestSceneOverlayColourProvider.cs b/osu.Game.Rulesets.Karaoke.Tests/Overlays/TestSceneOverlayColourProvider.cs index 056e357ed..9b24f282c 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Overlays/TestSceneOverlayColourProvider.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Overlays/TestSceneOverlayColourProvider.cs @@ -16,7 +16,6 @@ using osu.Game.Graphics.Sprites; using osu.Game.Overlays; using osu.Game.Rulesets.Karaoke.Extensions; -using osu.Game.Rulesets.Karaoke.Utils; using osu.Game.Tests.Visual; using osuTK.Graphics; @@ -28,8 +27,8 @@ public partial class TestSceneOverlayColourProvider : OsuTestScene [Test] public void ShowWithNoFetch() { - var providers = EnumUtils.GetValues() - .Select(x => new OverlayColourProvider(x)); + var providers = Enum.GetValues() + .Select(x => new OverlayColourProvider(x)); string[] colourName = { "Colour1", diff --git a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Lyrics/Components/TestSceneLyricEditorColourProvider.cs b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Lyrics/Components/TestSceneLyricEditorColourProvider.cs index cc5a383c6..68816fc4d 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Lyrics/Components/TestSceneLyricEditorColourProvider.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Lyrics/Components/TestSceneLyricEditorColourProvider.cs @@ -16,7 +16,6 @@ using osu.Game.Graphics.Sprites; using osu.Game.Rulesets.Karaoke.Extensions; using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics; -using osu.Game.Rulesets.Karaoke.Utils; using osu.Game.Tests.Visual; using osuTK.Graphics; @@ -28,7 +27,7 @@ public partial class TestSceneLyricEditorColourProvider : OsuTestScene public void ShowWithNoFetch() { var provider = new LyricEditorColourProvider(); - var types = EnumUtils.GetValues(); + var types = Enum.GetValues(); string[] colourName = { diff --git a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestSceneLyricEditorScreen.cs b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestSceneLyricEditorScreen.cs index d438d295e..aa48a6c63 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestSceneLyricEditorScreen.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestSceneLyricEditorScreen.cs @@ -15,7 +15,6 @@ using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics; using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings; using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States.Modes; -using osu.Game.Rulesets.Karaoke.Utils; namespace osu.Game.Rulesets.Karaoke.Tests.Screens.Edit.Beatmap { @@ -116,15 +115,15 @@ private void switchToMode(LyricEditorMode mode) AddWaitStep("wait for switch to new mode", 5); } - private void clickEditModeButtons() where T : Enum + private void clickEditModeButtons() where T : struct, Enum { - foreach (var editMode in EnumUtils.GetValues()) + foreach (var editMode in Enum.GetValues()) { clickTargetEditModeButton(editMode); } } - private void clickTargetEditModeButton(T editMode) where T : Enum + private void clickTargetEditModeButton(T editMode) where T : struct, Enum { AddStep("Click the button", () => { diff --git a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Import/TestSceneLyricImporter.cs b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Import/TestSceneLyricImporter.cs index 1baeec6a8..3781917dd 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Import/TestSceneLyricImporter.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Import/TestSceneLyricImporter.cs @@ -14,7 +14,6 @@ using osu.Game.Rulesets.Karaoke.Screens.Edit.Import.Lyrics; using osu.Game.Rulesets.Karaoke.Screens.Edit.Import.Lyrics.DragFile; using osu.Game.Rulesets.Karaoke.Tests.Resources; -using osu.Game.Rulesets.Karaoke.Utils; using osu.Game.Screens.Edit; namespace osu.Game.Rulesets.Karaoke.Tests.Screens.Edit.Import @@ -59,7 +58,7 @@ private void load() [Test] public void TestGoToStep() { - var steps = EnumUtils.GetValues(); + var steps = Enum.GetValues(); foreach (var step in steps) { @@ -88,7 +87,7 @@ public void GoToStep(LyricImporterStep step) if (step <= lyricSubScreen.Step) return; - var totalSteps = EnumUtils.GetValues().Where(x => x > lyricSubScreen.Step && x <= step); + var totalSteps = Enum.GetValues().Where(x => x > lyricSubScreen.Step && x <= step); foreach (var gotoStep in totalSteps) { diff --git a/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneDrawableJudgement.cs b/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneDrawableJudgement.cs index 13f9976f4..00e2023b4 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneDrawableJudgement.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneDrawableJudgement.cs @@ -1,12 +1,12 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Linq; using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Karaoke.UI; -using osu.Game.Rulesets.Karaoke.Utils; using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Scoring; @@ -16,7 +16,7 @@ public partial class TestSceneDrawableJudgement : KaraokeSkinnableTestScene { public TestSceneDrawableJudgement() { - foreach (var result in EnumUtils.GetValues().Skip(1)) + foreach (var result in Enum.GetValues().Skip(1)) { AddStep("Show " + result.GetDescription(), () => SetContents(_ => new DrawableNoteJudgement(new JudgementResult(new HitObject(), new Judgement()) { Type = result }, null) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Components/ContextMenu/LyricLockContextMenu.cs b/osu.Game.Rulesets.Karaoke/Edit/Components/ContextMenu/LyricLockContextMenu.cs index 367de038b..000ad89db 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Components/ContextMenu/LyricLockContextMenu.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Components/ContextMenu/LyricLockContextMenu.cs @@ -1,15 +1,13 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - +using System; using System.Collections.Generic; using System.Linq; using osu.Game.Graphics.UserInterface; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Objects.Types; -using osu.Game.Rulesets.Karaoke.Utils; namespace osu.Game.Rulesets.Karaoke.Edit.Components.ContextMenu { @@ -23,7 +21,7 @@ public LyricLockContextMenu(ILockChangeHandler lockChangeHandler, Lyric lyric, s public LyricLockContextMenu(ILockChangeHandler lockChangeHandler, List lyrics, string name) : base(name) { - Items = EnumUtils.GetValues().Select(l => new OsuMenuItem(l.ToString(), anyLyricInLockState(l) ? MenuItemType.Highlighted : MenuItemType.Standard, () => + Items = Enum.GetValues().Select(l => new OsuMenuItem(l.ToString(), anyLyricInLockState(l) ? MenuItemType.Highlighted : MenuItemType.Standard, () => { // todo: how to make lyric as selected? lockChangeHandler.Lock(l); diff --git a/osu.Game.Rulesets.Karaoke/Edit/Components/Menus/EnumMenu.cs b/osu.Game.Rulesets.Karaoke/Edit/Components/Menus/EnumMenu.cs index fcab4fc6c..7b8114915 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Components/Menus/EnumMenu.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Components/Menus/EnumMenu.cs @@ -1,8 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using System.Collections.Generic; using System.Linq; @@ -11,7 +9,6 @@ using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.UserInterface; -using osu.Game.Rulesets.Karaoke.Utils; namespace osu.Game.Rulesets.Karaoke.Edit.Components.Menus { @@ -46,7 +43,7 @@ private ToggleMenuItem[] createMenuItems() }).ToArray(); } - protected virtual IEnumerable ValidEnums => EnumUtils.GetValues(); + protected virtual IEnumerable ValidEnums => Enum.GetValues(); protected string GetName(T selection) => selection.GetDescription(); diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Compose/LyricComposer.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Compose/LyricComposer.cs index 292f6445e..20a910324 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Compose/LyricComposer.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Compose/LyricComposer.cs @@ -18,7 +18,6 @@ using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Compose.BottomEditor; using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Compose.Panels; using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States.Modes; -using osu.Game.Rulesets.Karaoke.Utils; namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Compose { @@ -175,7 +174,7 @@ protected override bool OnInvalidate(Invalidation invalidation, InvalidationSour private void initializePanel() { - foreach (var panelType in EnumUtils.GetValues()) + foreach (var panelType in Enum.GetValues()) { var instance = getInstance(panelType); diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/LyricEditorEditModeSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/LyricEditorEditModeSection.cs index aca804e8a..16776f197 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/LyricEditorEditModeSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/LyricEditorEditModeSection.cs @@ -5,7 +5,6 @@ using System; using osu.Framework.Allocation; -using osu.Framework.Localisation; using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.Components.Markdown; using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States; using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States.Modes; @@ -14,7 +13,7 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings { public abstract partial class LyricEditorEditModeSection : LyricEditorEditModeSection - where TEditModeState : IHasEditModeState where TEditMode : Enum + where TEditModeState : IHasEditModeState where TEditMode : struct, Enum { [Resolved] private TEditModeState tEditModeState { get; set; } @@ -30,7 +29,7 @@ internal sealed override void UpdateEditMode(TEditMode mode) } public abstract partial class LyricEditorEditModeSection : EditModeSection - where TEditMode : Enum + where TEditMode : struct, Enum { [Resolved] private ILyricSelectionState lyricSelectionState { get; set; } diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagEditModeSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagEditModeSection.cs index fe8bd894a..251c40f81 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagEditModeSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagEditModeSection.cs @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.RubyRo { public abstract partial class TextTagEditModeSection : LyricEditorEditModeSection where TEditModeState : IHasEditModeState - where TEditMode : Enum + where TEditMode : struct, Enum { protected override OverlayColourScheme CreateColourScheme() => OverlayColourScheme.Pink; diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/TimeTags/TimeTagCreateConfigSubsection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/TimeTags/TimeTagCreateConfigSubsection.cs index 8e012b25d..53a1f6967 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/TimeTags/TimeTagCreateConfigSubsection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/TimeTags/TimeTagCreateConfigSubsection.cs @@ -17,7 +17,6 @@ using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.Components.Markdown; using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.States; using osu.Game.Rulesets.Karaoke.Screens.Edit.Components.Markdown; -using osu.Game.Rulesets.Karaoke.Utils; using osuTK; using osuTK.Graphics; @@ -75,7 +74,7 @@ public TimeTagCreateConfigSubsection() }, Content = new[] { - buttons = EnumUtils.GetValues().Select(x => new EditModeButton(x) + buttons = Enum.GetValues().Select(x => new EditModeButton(x) { Text = getButtonTitle(x), Margin = new MarginPadding { Vertical = button_vertical_margin }, diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/EditModeSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/EditModeSection.cs index 757e65a99..397238203 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/EditModeSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/EditModeSection.cs @@ -18,12 +18,11 @@ using osu.Game.Overlays.Toolbar; using osu.Game.Rulesets.Edit.Checks.Components; using osu.Game.Rulesets.Karaoke.Screens.Edit.Components.Markdown; -using osu.Game.Rulesets.Karaoke.Utils; using osuTK.Graphics; namespace osu.Game.Rulesets.Karaoke.Screens.Edit; -public abstract partial class EditModeSection : EditorSection where TEditMode : Enum +public abstract partial class EditModeSection : EditorSection where TEditMode : struct, Enum { private const int horizontal_padding = 20; @@ -73,7 +72,7 @@ protected EditModeSection() } private Selection[] createSelections() - => EnumUtils.GetValues().Select(mode => + => Enum.GetValues().Select(mode => { var selection = CreateSelection(mode); selection.Mode = mode; diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/IssueSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/IssueSection.cs index 1705ddd31..fdf1cb57e 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/IssueSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/IssueSection.cs @@ -20,7 +20,6 @@ using osu.Game.Overlays; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit.Checks.Components; -using osu.Game.Rulesets.Karaoke.Utils; using osuTK; namespace osu.Game.Rulesets.Karaoke.Screens.Edit; @@ -217,7 +216,7 @@ protected IssueNavigator() } private IssueCategory[] createCategory() - => EnumUtils.GetValues().Select(type => new IssueCategory + => Enum.GetValues().Select(type => new IssueCategory { Type = type, Text = getTextByIssueType(type), From 36d2304e39fb78ba059f637246816d57a58c1422 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 28 Dec 2022 00:39:32 +0800 Subject: [PATCH 3/3] Remove the un-need utils. --- .../Utils/EnumUtilsTest.cs | 13 ------------- osu.Game.Rulesets.Karaoke/Utils/EnumUtils.cs | 11 ++++------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Utils/EnumUtilsTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Utils/EnumUtilsTest.cs index fe5578d77..8d201806e 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Utils/EnumUtilsTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Utils/EnumUtilsTest.cs @@ -10,19 +10,6 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Utils [TestFixture] public class EnumUtilsTest { - [Test] - public void TestGetValues() - { - var expected = new[] - { - TestEnum.Enum1, - TestEnum.Enum2, - TestEnum.Enum3 - }; - var actual = EnumUtils.GetValues(); - Assert.AreEqual(expected, actual); - } - [TestCase(TestEnum.Enum1, TestEnum.Enum3)] [TestCase(TestEnum.Enum2, TestEnum.Enum1)] [TestCase(TestEnum.Enum3, TestEnum.Enum2)] diff --git a/osu.Game.Rulesets.Karaoke/Utils/EnumUtils.cs b/osu.Game.Rulesets.Karaoke/Utils/EnumUtils.cs index 88cb50959..374ef1b1f 100644 --- a/osu.Game.Rulesets.Karaoke/Utils/EnumUtils.cs +++ b/osu.Game.Rulesets.Karaoke/Utils/EnumUtils.cs @@ -9,14 +9,11 @@ namespace osu.Game.Rulesets.Karaoke.Utils { public static class EnumUtils { - public static T[] GetValues() where T : Enum - => (T[])Enum.GetValues(typeof(T)); + public static T GetPreviousValue(T v) where T : struct, Enum + => Enum.GetValues().Concat(new[] { default(T)! }).Reverse().SkipWhile(e => !EqualityComparer.Default.Equals(v, e)).Skip(1).First(); - public static T GetPreviousValue(T v) where T : Enum - => GetValues().Concat(new[] { default(T)! }).Reverse().SkipWhile(e => !EqualityComparer.Default.Equals(v, e)).Skip(1).First(); - - public static T GetNextValue(T v) where T : Enum - => GetValues().Concat(new[] { default(T)! }).SkipWhile(e => !EqualityComparer.Default.Equals(v, e)).Skip(1).First(); + public static T GetNextValue(T v) where T : struct, Enum + => Enum.GetValues().Concat(new[] { default(T)! }).SkipWhile(e => !EqualityComparer.Default.Equals(v, e)).Skip(1).First(); public static T Casting(Enum mode) => (T)(object)mode;