Extract duplicated conditionals

This commit is contained in:
Henry Lin 2022-03-03 10:43:04 +08:00
parent 55737226a3
commit ff7f65de27
1 changed files with 12 additions and 8 deletions

View File

@ -12,6 +12,7 @@
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring;
@ -124,10 +125,7 @@ public void ApplyToDrawableHitObject(DrawableHitObject drawable)
drawable.OnNewResult += (o, result) =>
{
if (dequeuedRates.ContainsKey(result.HitObject)) return;
if (!result.IsHit) return;
if (!result.Type.AffectsAccuracy()) return;
if (!previousEndTimes.ContainsKey(result.HitObject)) return;
if (!shouldProcessResult(result)) return;
double prevEndTime = previousEndTimes[result.HitObject];
@ -141,10 +139,7 @@ public void ApplyToDrawableHitObject(DrawableHitObject drawable)
drawable.OnRevertResult += (o, result) =>
{
if (!dequeuedRates.ContainsKey(result.HitObject)) return;
if (!result.IsHit) return;
if (!result.Type.AffectsAccuracy()) return;
if (!previousEndTimes.ContainsKey(result.HitObject)) return;
if (!shouldProcessResult(result)) return;
recentRates.Insert(0, dequeuedRates[result.HitObject]);
recentRates.RemoveAt(recentRates.Count - 1);
@ -179,5 +174,14 @@ private IEnumerable<HitObject> getAllApplicableHitObjects(IEnumerable<HitObject>
yield return nested;
}
}
private bool shouldProcessResult(JudgementResult result)
{
if (!result.IsHit) return false;
if (!result.Type.AffectsAccuracy()) return false;
if (!previousEndTimes.ContainsKey(result.HitObject)) return false;
return true;
}
}
}