1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 13:27:25 +08:00

Replace all judged event logic with HasCompleted bindable

This commit is contained in:
Salman Ahmed 2020-04-19 05:36:04 +03:00
parent 149efec985
commit fc6c245de5
7 changed files with 15 additions and 32 deletions

View File

@ -27,7 +27,6 @@ namespace osu.Game.Rulesets.Mania.Tests
private const double time_after_tail = 5250;
private List<JudgementResult> judgementResults;
private bool allJudgedFired;
/// <summary>
/// -----[ ]-----
@ -283,20 +282,15 @@ namespace osu.Game.Rulesets.Mania.Tests
{
if (currentPlayer == p) judgementResults.Add(result);
};
p.ScoreProcessor.AllJudged += () =>
{
if (currentPlayer == p) allJudgedFired = true;
};
};
LoadScreen(currentPlayer = p);
allJudgedFired = false;
judgementResults = new List<JudgementResult>();
});
AddUntilStep("Beatmap at 0", () => Beatmap.Value.Track.CurrentTime == 0);
AddUntilStep("Wait until player is loaded", () => currentPlayer.IsCurrentScreen());
AddUntilStep("Wait for all judged", () => allJudgedFired);
AddUntilStep("Wait for completion", () => currentPlayer.ScoreProcessor.HasCompleted.Value);
}
private class ScoreAccessibleReplayPlayer : ReplayPlayer

View File

@ -316,7 +316,6 @@ namespace osu.Game.Rulesets.Osu.Tests
private ScoreAccessibleReplayPlayer currentPlayer;
private List<JudgementResult> judgementResults;
private bool allJudgedFired;
private void performTest(List<OsuHitObject> hitObjects, List<ReplayFrame> frames)
{
@ -342,20 +341,15 @@ namespace osu.Game.Rulesets.Osu.Tests
{
if (currentPlayer == p) judgementResults.Add(result);
};
p.ScoreProcessor.AllJudged += () =>
{
if (currentPlayer == p) allJudgedFired = true;
};
};
LoadScreen(currentPlayer = p);
allJudgedFired = false;
judgementResults = new List<JudgementResult>();
});
AddUntilStep("Beatmap at 0", () => Beatmap.Value.Track.CurrentTime == 0);
AddUntilStep("Wait until player is loaded", () => currentPlayer.IsCurrentScreen());
AddUntilStep("Wait for all judged", () => allJudgedFired);
AddUntilStep("Wait for completion", () => currentPlayer.ScoreProcessor.HasCompleted.Value);
}
private class TestHitCircle : HitCircle

View File

@ -47,7 +47,6 @@ namespace osu.Game.Rulesets.Osu.Tests
private const double time_slider_end = 4000;
private List<JudgementResult> judgementResults;
private bool allJudgedFired;
/// <summary>
/// Scenario:
@ -375,20 +374,15 @@ namespace osu.Game.Rulesets.Osu.Tests
{
if (currentPlayer == p) judgementResults.Add(result);
};
p.ScoreProcessor.AllJudged += () =>
{
if (currentPlayer == p) allJudgedFired = true;
};
};
LoadScreen(currentPlayer = p);
allJudgedFired = false;
judgementResults = new List<JudgementResult>();
});
AddUntilStep("Beatmap at 0", () => Beatmap.Value.Track.CurrentTime == 0);
AddUntilStep("Wait until player is loaded", () => currentPlayer.IsCurrentScreen());
AddUntilStep("Wait for all judged", () => allJudgedFired);
AddUntilStep("Wait for completion", () => currentPlayer.ScoreProcessor.HasCompleted.Value);
}
private class ScoreAccessibleReplayPlayer : ReplayPlayer

View File

@ -19,7 +19,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
[Test]
public void TestZeroTickTimeOffsets()
{
AddUntilStep("gameplay finished", () => Player.ScoreProcessor.HasCompleted);
AddUntilStep("gameplay finished", () => Player.ScoreProcessor.HasCompleted.Value);
AddAssert("all tick offsets are 0", () => Player.Results.Where(r => r.HitObject is SwellTick).All(r => r.TimeOffset == 0));
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
@ -12,11 +13,6 @@ namespace osu.Game.Rulesets.Scoring
{
public abstract class JudgementProcessor : Component
{
/// <summary>
/// Invoked when all <see cref="HitObject"/>s have been judged by this <see cref="JudgementProcessor"/>.
/// </summary>
public event Action AllJudged;
/// <summary>
/// Invoked when a new judgement has occurred. This occurs after the judgement has been processed by this <see cref="JudgementProcessor"/>.
/// </summary>
@ -32,10 +28,12 @@ namespace osu.Game.Rulesets.Scoring
/// </summary>
public int JudgedHits { get; private set; }
private readonly BindableBool hasCompleted = new BindableBool();
/// <summary>
/// Whether all <see cref="Judgement"/>s have been processed.
/// </summary>
public bool HasCompleted => JudgedHits == MaxHits;
public IBindable<bool> HasCompleted => hasCompleted;
/// <summary>
/// Applies a <see cref="IBeatmap"/> to this <see cref="ScoreProcessor"/>.
@ -60,8 +58,8 @@ namespace osu.Game.Rulesets.Scoring
NewJudgement?.Invoke(result);
if (HasCompleted)
AllJudged?.Invoke();
if (JudgedHits == MaxHits)
hasCompleted.Value = true;
}
/// <summary>
@ -72,6 +70,9 @@ namespace osu.Game.Rulesets.Scoring
{
JudgedHits--;
if (JudgedHits < MaxHits)
hasCompleted.Value = false;
RevertResultInternal(result);
}

View File

@ -51,7 +51,7 @@ namespace osu.Game.Screens.Play
isBreakTime.Value = getCurrentBreak()?.HasEffect == true
|| Clock.CurrentTime < gameplayStartTime
|| scoreProcessor?.HasCompleted == true;
|| scoreProcessor?.HasCompleted.Value == true;
}
private BreakPeriod getCurrentBreak()

View File

@ -46,7 +46,7 @@ namespace osu.Game.Tests.Visual
public bool CheckFailed(bool failed)
{
if (!failed)
return ScoreProcessor.HasCompleted && !HealthProcessor.HasFailed;
return ScoreProcessor.HasCompleted.Value && !HealthProcessor.HasFailed;
return HealthProcessor.HasFailed;
}