Skip to content

Commit

Permalink
Stop using the "EnumUtils.GetValues<T>()"
Browse files Browse the repository at this point in the history
Can use the  "Enum.GetValues<T>()" instead.
  • Loading branch information
andy840119 committed Dec 27, 2022
1 parent 1d405ad commit 8e628ac
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -24,7 +23,7 @@ public void TestIsRemoveLyricLocked()
test(new Lyric());

// test lock state.
foreach (var lockState in EnumUtils.GetValues<LockState>())
foreach (var lockState in Enum.GetValues<LockState>())
{
test(new Lyric
{
Expand Down Expand Up @@ -61,7 +60,7 @@ public void TestIsWriteLyricPropertyLocked()
test(new Lyric());

// test lock state.
foreach (var lockState in EnumUtils.GetValues<LockState>())
foreach (var lockState in Enum.GetValues<LockState>())
{
test(new Lyric
{
Expand Down Expand Up @@ -101,7 +100,7 @@ public void TestIsCreateOrRemoveNoteLocked()
test(new Lyric());

// test lock state.
foreach (var lockState in EnumUtils.GetValues<LockState>())
foreach (var lockState in Enum.GetValues<LockState>())
{
test(new Lyric
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) andy840119 <[email protected]>. 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;
using osu.Framework.Graphics.Containers;
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;

Expand Down Expand Up @@ -45,7 +45,7 @@ private void load(OsuColour colours)
[Test]
public void TestRightAngleDirections()
{
foreach (var direction in EnumUtils.GetValues<TriangleRightAngleDirection>())
foreach (var direction in Enum.GetValues<TriangleRightAngleDirection>())
{
AddStep($"Test direction {direction}", () =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -28,8 +27,8 @@ public partial class TestSceneOverlayColourProvider : OsuTestScene
[Test]
public void ShowWithNoFetch()
{
var providers = EnumUtils.GetValues<OverlayColourScheme>()
.Select(x => new OverlayColourProvider(x));
var providers = Enum.GetValues<OverlayColourScheme>()
.Select(x => new OverlayColourProvider(x));
string[] colourName =
{
"Colour1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -28,7 +27,7 @@ public partial class TestSceneLyricEditorColourProvider : OsuTestScene
public void ShowWithNoFetch()
{
var provider = new LyricEditorColourProvider();
var types = EnumUtils.GetValues<LyricEditorMode>();
var types = Enum.GetValues<LyricEditorMode>();

string[] colourName =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -116,15 +115,15 @@ private void switchToMode(LyricEditorMode mode)
AddWaitStep("wait for switch to new mode", 5);
}

private void clickEditModeButtons<T>() where T : Enum
private void clickEditModeButtons<T>() where T : struct, Enum
{
foreach (var editMode in EnumUtils.GetValues<T>())
foreach (var editMode in Enum.GetValues<T>())
{
clickTargetEditModeButton(editMode);
}
}

private void clickTargetEditModeButton<T>(T editMode) where T : Enum
private void clickTargetEditModeButton<T>(T editMode) where T : struct, Enum
{
AddStep("Click the button", () =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,7 +58,7 @@ private void load()
[Test]
public void TestGoToStep()
{
var steps = EnumUtils.GetValues<LyricImporterStep>();
var steps = Enum.GetValues<LyricImporterStep>();

foreach (var step in steps)
{
Expand Down Expand Up @@ -88,7 +87,7 @@ public void GoToStep(LyricImporterStep step)
if (step <= lyricSubScreen.Step)
return;

var totalSteps = EnumUtils.GetValues<LyricImporterStep>().Where(x => x > lyricSubScreen.Step && x <= step);
var totalSteps = Enum.GetValues<LyricImporterStep>().Where(x => x > lyricSubScreen.Step && x <= step);

foreach (var gotoStep in totalSteps)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) andy840119 <[email protected]>. 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;

Expand All @@ -16,7 +16,7 @@ public partial class TestSceneDrawableJudgement : KaraokeSkinnableTestScene
{
public TestSceneDrawableJudgement()
{
foreach (var result in EnumUtils.GetValues<HitResult>().Skip(1))
foreach (var result in Enum.GetValues<HitResult>().Skip(1))
{
AddStep("Show " + result.GetDescription(), () => SetContents(_ =>
new DrawableNoteJudgement(new JudgementResult(new HitObject(), new Judgement()) { Type = result }, null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Copyright (c) andy840119 <[email protected]>. 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
{
Expand All @@ -23,7 +21,7 @@ public LyricLockContextMenu(ILockChangeHandler lockChangeHandler, Lyric lyric, s
public LyricLockContextMenu(ILockChangeHandler lockChangeHandler, List<Lyric> lyrics, string name)
: base(name)
{
Items = EnumUtils.GetValues<LockState>().Select(l => new OsuMenuItem(l.ToString(), anyLyricInLockState(l) ? MenuItemType.Highlighted : MenuItemType.Standard, () =>
Items = Enum.GetValues<LockState>().Select(l => new OsuMenuItem(l.ToString(), anyLyricInLockState(l) ? MenuItemType.Highlighted : MenuItemType.Standard, () =>
{
// todo: how to make lyric as selected?
lockChangeHandler.Lock(l);
Expand Down
5 changes: 1 addition & 4 deletions osu.Game.Rulesets.Karaoke/Edit/Components/Menus/EnumMenu.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) andy840119 <[email protected]>. 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;
Expand All @@ -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
{
Expand Down Expand Up @@ -46,7 +43,7 @@ private ToggleMenuItem[] createMenuItems()
}).ToArray();
}

protected virtual IEnumerable<T> ValidEnums => EnumUtils.GetValues<T>();
protected virtual IEnumerable<T> ValidEnums => Enum.GetValues<T>();

protected string GetName(T selection)
=> selection.GetDescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -175,7 +174,7 @@ protected override bool OnInvalidate(Invalidation invalidation, InvalidationSour

private void initializePanel()
{
foreach (var panelType in EnumUtils.GetValues<PanelType>())
foreach (var panelType in Enum.GetValues<PanelType>())
{
var instance = getInstance(panelType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +13,7 @@
namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings
{
public abstract partial class LyricEditorEditModeSection<TEditModeState, TEditMode> : LyricEditorEditModeSection<TEditMode>
where TEditModeState : IHasEditModeState<TEditMode> where TEditMode : Enum
where TEditModeState : IHasEditModeState<TEditMode> where TEditMode : struct, Enum
{
[Resolved]
private TEditModeState tEditModeState { get; set; }
Expand All @@ -30,7 +29,7 @@ internal sealed override void UpdateEditMode(TEditMode mode)
}

public abstract partial class LyricEditorEditModeSection<TEditMode> : EditModeSection<TEditMode>
where TEditMode : Enum
where TEditMode : struct, Enum
{
[Resolved]
private ILyricSelectionState lyricSelectionState { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.RubyRo
{
public abstract partial class TextTagEditModeSection<TEditModeState, TEditMode> : LyricEditorEditModeSection<TEditModeState, TEditMode>
where TEditModeState : IHasEditModeState<TEditMode>
where TEditMode : Enum
where TEditMode : struct, Enum
{
protected override OverlayColourScheme CreateColourScheme()
=> OverlayColourScheme.Pink;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -75,7 +74,7 @@ public TimeTagCreateConfigSubsection()
},
Content = new[]
{
buttons = EnumUtils.GetValues<CreateTimeTagEditMode>().Select(x => new EditModeButton(x)
buttons = Enum.GetValues<CreateTimeTagEditMode>().Select(x => new EditModeButton(x)
{
Text = getButtonTitle(x),
Margin = new MarginPadding { Vertical = button_vertical_margin },
Expand Down
5 changes: 2 additions & 3 deletions osu.Game.Rulesets.Karaoke/Screens/Edit/EditModeSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TEditMode> : EditorSection where TEditMode : Enum
public abstract partial class EditModeSection<TEditMode> : EditorSection where TEditMode : struct, Enum
{
private const int horizontal_padding = 20;

Expand Down Expand Up @@ -73,7 +72,7 @@ protected EditModeSection()
}

private Selection[] createSelections()
=> EnumUtils.GetValues<TEditMode>().Select(mode =>
=> Enum.GetValues<TEditMode>().Select(mode =>
{
var selection = CreateSelection(mode);
selection.Mode = mode;
Expand Down
3 changes: 1 addition & 2 deletions osu.Game.Rulesets.Karaoke/Screens/Edit/IssueSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -217,7 +216,7 @@ protected IssueNavigator()
}

private IssueCategory[] createCategory()
=> EnumUtils.GetValues<IssueType>().Select(type => new IssueCategory
=> Enum.GetValues<IssueType>().Select(type => new IssueCategory
{
Type = type,
Text = getTextByIssueType(type),
Expand Down

0 comments on commit 8e628ac

Please sign in to comment.