mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:57:36 +08:00
Merge pull request #11613 from bdach/order-attribute-move
Remove game-local enum `[Order]` attribute
This commit is contained in:
commit
34f8e4b672
@ -52,6 +52,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.1202.0" />
|
||||
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.127.0" />
|
||||
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.128.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using osu.Game.Utils;
|
||||
using osu.Framework.Utils;
|
||||
|
||||
namespace osu.Game.Rulesets.Scoring
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.NETCore.Targets" Version="3.1.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2021.127.0" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2021.128.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.1202.0" />
|
||||
<PackageReference Include="Sentry" Version="2.1.8" />
|
||||
<PackageReference Include="SharpCompress" Version="0.26.0" />
|
||||
|
@ -70,7 +70,7 @@
|
||||
<Reference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Package References">
|
||||
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.127.0" />
|
||||
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.128.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2020.1202.0" />
|
||||
</ItemGroup>
|
||||
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
|
||||
@ -88,7 +88,7 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2021.127.0" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2021.128.0" />
|
||||
<PackageReference Include="SharpCompress" Version="0.26.0" />
|
||||
<PackageReference Include="NUnit" Version="3.12.0" />
|
||||
<PackageReference Include="SharpRaven" Version="2.4.0" />
|
||||
|
Loading…
Reference in New Issue
Block a user