mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 16:43:00 +08:00
Allow rulesets to specify valid HitResult types (and display names for them)
This commit is contained in:
parent
d6d0bd90a3
commit
3363c3399e
@ -23,8 +23,10 @@ using osu.Game.Scoring;
|
|||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Screens.Ranking.Statistics;
|
using osu.Game.Screens.Ranking.Statistics;
|
||||||
|
using osu.Game.Utils;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets
|
namespace osu.Game.Rulesets
|
||||||
{
|
{
|
||||||
@ -220,5 +222,52 @@ namespace osu.Game.Rulesets
|
|||||||
/// <returns>The <see cref="StatisticRow"/>s to display. Each <see cref="StatisticRow"/> may contain 0 or more <see cref="StatisticItem"/>.</returns>
|
/// <returns>The <see cref="StatisticRow"/>s to display. Each <see cref="StatisticRow"/> may contain 0 or more <see cref="StatisticItem"/>.</returns>
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public virtual StatisticRow[] CreateStatisticsForScore(ScoreInfo score, IBeatmap playableBeatmap) => Array.Empty<StatisticRow>();
|
public virtual StatisticRow[] CreateStatisticsForScore(ScoreInfo score, IBeatmap playableBeatmap) => Array.Empty<StatisticRow>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all valid <see cref="HitResult"/>s for this ruleset.
|
||||||
|
/// Generally used for results display purposes, where it can't be determined if zero-count means the user has not achieved any or the type is not used by this ruleset.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// All valid <see cref="HitResult"/>s along with a display-friendly name.
|
||||||
|
/// </returns>
|
||||||
|
public IEnumerable<(HitResult result, string displayName)> GetHitResults()
|
||||||
|
{
|
||||||
|
var validResults = GetValidHitResults();
|
||||||
|
|
||||||
|
// enumerate over ordered list to guarantee return order is stable.
|
||||||
|
foreach (var result in OrderAttributeUtils.GetValuesInOrder<HitResult>())
|
||||||
|
{
|
||||||
|
switch (result)
|
||||||
|
{
|
||||||
|
// hard blocked types, should never be displayed even if the ruleset tells us to.
|
||||||
|
case HitResult.None:
|
||||||
|
case HitResult.IgnoreHit:
|
||||||
|
case HitResult.IgnoreMiss:
|
||||||
|
// display is handled as a completion count with corresponding "hit" type.
|
||||||
|
case HitResult.LargeTickMiss:
|
||||||
|
case HitResult.SmallTickMiss:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == HitResult.Miss || validResults.Contains(result))
|
||||||
|
yield return (result, GetDisplayNameForHitResult(result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get all valid <see cref="HitResult"/>s for this ruleset.
|
||||||
|
/// Generally used for results display purposes, where it can't be determined if zero-count means the user has not achieved any or the type is not used by this ruleset.
|
||||||
|
/// </summary>
|
||||||
|
/// <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>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a display friendly name for the specified result type.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="result">The result type to get the name for.</param>
|
||||||
|
/// <returns>The display name.</returns>
|
||||||
|
public virtual string GetDisplayNameForHitResult(HitResult result) => result.GetDescription();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user