1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:17:23 +08:00

Remove game-local enum [Order] attribute

In favour of the newly-added framework one.
This commit is contained in:
Bartłomiej Dach 2021-01-27 22:01:56 +01:00
parent 15e455231e
commit 2c08ce05fa
6 changed files with 9 additions and 61 deletions

View File

@ -12,7 +12,7 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osuTK;
using Humanizer;
using osu.Game.Utils;
using osu.Framework.Extensions.EnumExtensions;
namespace osu.Game.Overlays.BeatmapListing
{
@ -80,7 +80,7 @@ namespace osu.Game.Overlays.BeatmapListing
if (typeof(T).IsEnum)
{
foreach (var val in OrderAttributeUtils.GetValuesInOrder<T>())
foreach (var val in EnumExtensions.GetValuesInOrder<T>())
AddItem(val);
}
}

View File

@ -1,7 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Utils;
using osu.Framework.Utils;
namespace osu.Game.Overlays.BeatmapListing
{

View File

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Extensions.EnumExtensions;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
@ -15,7 +16,6 @@ using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Users.Drawables;
using osu.Game.Utils;
using osuTK;
using osuTK.Graphics;
@ -105,7 +105,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
var ruleset = scores.First().Ruleset.CreateInstance();
foreach (var result in OrderAttributeUtils.GetValuesInOrder<HitResult>())
foreach (var result in EnumExtensions.GetValuesInOrder<HitResult>())
{
if (!allScoreStatistics.Contains(result))
continue;

View File

@ -24,9 +24,9 @@ using osu.Game.Skinning;
using osu.Game.Users;
using JetBrains.Annotations;
using osu.Framework.Extensions;
using osu.Framework.Extensions.EnumExtensions;
using osu.Framework.Testing;
using osu.Game.Screens.Ranking.Statistics;
using osu.Game.Utils;
namespace osu.Game.Rulesets
{
@ -272,7 +272,7 @@ namespace osu.Game.Rulesets
var validResults = GetValidHitResults();
// enumerate over ordered list to guarantee return order is stable.
foreach (var result in OrderAttributeUtils.GetValuesInOrder<HitResult>())
foreach (var result in EnumExtensions.GetValuesInOrder<HitResult>())
{
switch (result)
{
@ -298,7 +298,7 @@ namespace osu.Game.Rulesets
/// <remarks>
/// <see cref="HitResult.Miss"/> is implicitly included. Special types like <see cref="HitResult.IgnoreHit"/> are ignored even when specified.
/// </remarks>
protected virtual IEnumerable<HitResult> GetValidHitResults() => OrderAttributeUtils.GetValuesInOrder<HitResult>();
protected virtual IEnumerable<HitResult> GetValidHitResults() => EnumExtensions.GetValuesInOrder<HitResult>();
/// <summary>
/// Get a display friendly name for the specified result type.

View File

@ -3,7 +3,7 @@
using System.ComponentModel;
using System.Diagnostics;
using osu.Game.Utils;
using osu.Framework.Utils;
namespace osu.Game.Rulesets.Scoring
{

View File

@ -1,52 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
namespace osu.Game.Utils
{
public static class OrderAttributeUtils
{
/// <summary>
/// Get values of an enum in order. Supports custom ordering via <see cref="OrderAttribute"/>.
/// </summary>
public static IEnumerable<T> GetValuesInOrder<T>()
{
var type = typeof(T);
if (!type.IsEnum)
throw new InvalidOperationException("T must be an enum");
IEnumerable<T> items = (T[])Enum.GetValues(type);
if (Attribute.GetCustomAttribute(type, typeof(HasOrderedElementsAttribute)) == null)
return items;
return items.OrderBy(i =>
{
if (type.GetField(i.ToString()).GetCustomAttributes(typeof(OrderAttribute), false).FirstOrDefault() is OrderAttribute attr)
return attr.Order;
throw new ArgumentException($"Not all values of {nameof(T)} have {nameof(OrderAttribute)} specified.");
});
}
}
[AttributeUsage(AttributeTargets.Field)]
public class OrderAttribute : Attribute
{
public readonly int Order;
public OrderAttribute(int order)
{
Order = order;
}
}
[AttributeUsage(AttributeTargets.Enum)]
public class HasOrderedElementsAttribute : Attribute
{
}
}