mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 04:02:59 +08:00
Add guard against using the wrong hit result
This commit is contained in:
parent
c45b5690cf
commit
6264a01ecc
@ -475,6 +475,21 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
||||
if (!Result.HasResult)
|
||||
throw new InvalidOperationException($"{GetType().ReadableName()} applied a {nameof(JudgementResult)} but did not update {nameof(JudgementResult.Type)}.");
|
||||
|
||||
// Some (especially older) rulesets use scorable judgements instead of the newer ignorehit/ignoremiss judgements.
|
||||
if (Result.Judgement.MaxResult == HitResult.IgnoreHit)
|
||||
{
|
||||
if (Result.Type == HitResult.Miss)
|
||||
Result.Type = HitResult.IgnoreMiss;
|
||||
else if (Result.Type >= HitResult.Meh && Result.Type <= HitResult.Perfect)
|
||||
Result.Type = HitResult.IgnoreHit;
|
||||
}
|
||||
|
||||
if (!Result.Type.IsValidHitResult(Result.Judgement.MinResult, Result.Judgement.MaxResult))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"{GetType().ReadableName()} applied an invalid hit result (was: {Result.Type}, expected: [{Result.Judgement.MinResult} ... {Result.Judgement.MaxResult}]).");
|
||||
}
|
||||
|
||||
// Ensure that the judgement is given a valid time offset, because this may not get set by the caller
|
||||
var endTime = HitObject.GetEndTime();
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using osu.Game.Utils;
|
||||
|
||||
namespace osu.Game.Rulesets.Scoring
|
||||
@ -175,5 +176,24 @@ namespace osu.Game.Rulesets.Scoring
|
||||
/// Whether a <see cref="HitResult"/> is scorable.
|
||||
/// </summary>
|
||||
public static bool IsScorable(this HitResult result) => result >= HitResult.Miss && result < HitResult.IgnoreMiss;
|
||||
|
||||
/// <summary>
|
||||
/// Whether a <see cref="HitResult"/> is valid within a given <see cref="HitResult"/> range.
|
||||
/// </summary>
|
||||
/// <param name="result">The <see cref="HitResult"/> to check.</param>
|
||||
/// <param name="minResult">The minimum <see cref="HitResult"/>.</param>
|
||||
/// <param name="maxResult">The maximum <see cref="HitResult"/>.</param>
|
||||
/// <returns>Whether <see cref="HitResult"/> falls between <paramref name="minResult"/> and <paramref name="maxResult"/>.</returns>
|
||||
public static bool IsValidHitResult(this HitResult result, HitResult minResult, HitResult maxResult)
|
||||
{
|
||||
if (result == HitResult.None)
|
||||
return false;
|
||||
|
||||
if (result == minResult || result == maxResult)
|
||||
return true;
|
||||
|
||||
Debug.Assert(minResult <= maxResult);
|
||||
return result > minResult && result < maxResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user