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

Move HasPassed/HasFailed into GameplayState

This commit is contained in:
Dan Balasescu 2022-01-26 01:45:11 +09:00
parent 502e6af008
commit 781cb9f18d
10 changed files with 30 additions and 27 deletions

View File

@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
Player.ScoreProcessor.NewJudgement += b => judged = true; Player.ScoreProcessor.NewJudgement += b => judged = true;
}); });
AddUntilStep("swell judged", () => judged); AddUntilStep("swell judged", () => judged);
AddAssert("failed", () => Player.HasFailed); AddAssert("failed", () => Player.GameplayState.HasFailed);
} }
} }
} }

View File

@ -29,7 +29,7 @@ namespace osu.Game.Tests.Visual.Gameplay
protected override void AddCheckSteps() protected override void AddCheckSteps()
{ {
AddUntilStep("wait for fail", () => Player.HasFailed); AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddUntilStep("wait for fail overlay", () => ((FailPlayer)Player).FailOverlay.State.Value == Visibility.Visible); AddUntilStep("wait for fail overlay", () => ((FailPlayer)Player).FailOverlay.State.Value == Visibility.Visible);
// The pause screen and fail animation both ramp frequency. // The pause screen and fail animation both ramp frequency.

View File

@ -21,7 +21,7 @@ namespace osu.Game.Tests.Visual.Gameplay
protected override void AddCheckSteps() protected override void AddCheckSteps()
{ {
AddUntilStep("wait for fail", () => Player.HasFailed); AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddUntilStep("wait for multiple judgements", () => ((FailPlayer)Player).ScoreProcessor.JudgedHits > 1); AddUntilStep("wait for multiple judgements", () => ((FailPlayer)Player).ScoreProcessor.JudgedHits > 1);
AddAssert("total number of results == 1", () => AddAssert("total number of results == 1", () =>
{ {

View File

@ -185,7 +185,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test] [Test]
public void TestPauseAfterFail() public void TestPauseAfterFail()
{ {
AddUntilStep("wait for fail", () => Player.HasFailed); AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddUntilStep("fail overlay shown", () => Player.FailOverlayVisible); AddUntilStep("fail overlay shown", () => Player.FailOverlayVisible);
confirmClockRunning(false); confirmClockRunning(false);
@ -201,7 +201,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test] [Test]
public void TestExitFromFailedGameplayAfterFailAnimation() public void TestExitFromFailedGameplayAfterFailAnimation()
{ {
AddUntilStep("wait for fail", () => Player.HasFailed); AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddUntilStep("wait for fail overlay shown", () => Player.FailOverlayVisible); AddUntilStep("wait for fail overlay shown", () => Player.FailOverlayVisible);
confirmClockRunning(false); confirmClockRunning(false);
@ -213,7 +213,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test] [Test]
public void TestExitFromFailedGameplayDuringFailAnimation() public void TestExitFromFailedGameplayDuringFailAnimation()
{ {
AddUntilStep("wait for fail", () => Player.HasFailed); AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
// will finish the fail animation and show the fail/pause screen. // will finish the fail animation and show the fail/pause screen.
AddStep("attempt exit via pause key", () => Player.ExitViaPause()); AddStep("attempt exit via pause key", () => Player.ExitViaPause());
@ -227,7 +227,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test] [Test]
public void TestQuickRetryFromFailedGameplay() public void TestQuickRetryFromFailedGameplay()
{ {
AddUntilStep("wait for fail", () => Player.HasFailed); AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddStep("quick retry", () => Player.GameplayClockContainer.ChildrenOfType<HotkeyRetryOverlay>().First().Action?.Invoke()); AddStep("quick retry", () => Player.GameplayClockContainer.ChildrenOfType<HotkeyRetryOverlay>().First().Action?.Invoke());
confirmExited(); confirmExited();
@ -236,7 +236,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test] [Test]
public void TestQuickExitFromFailedGameplay() public void TestQuickExitFromFailedGameplay()
{ {
AddUntilStep("wait for fail", () => Player.HasFailed); AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddStep("quick exit", () => Player.GameplayClockContainer.ChildrenOfType<HotkeyExitOverlay>().First().Action?.Invoke()); AddStep("quick exit", () => Player.GameplayClockContainer.ChildrenOfType<HotkeyExitOverlay>().First().Action?.Invoke());
confirmExited(); confirmExited();
@ -341,7 +341,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
confirmClockRunning(false); confirmClockRunning(false);
confirmNotExited(); confirmNotExited();
AddAssert("player not failed", () => !Player.HasFailed); AddAssert("player not failed", () => !Player.GameplayState.HasFailed);
AddAssert("pause overlay shown", () => Player.PauseOverlayVisible); AddAssert("pause overlay shown", () => Player.PauseOverlayVisible);
} }

View File

@ -159,7 +159,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddUntilStep("wait for token request", () => Player.TokenCreationRequested); AddUntilStep("wait for token request", () => Player.TokenCreationRequested);
AddUntilStep("wait for fail", () => Player.HasFailed); AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddStep("exit", () => Player.Exit()); AddStep("exit", () => Player.Exit());
AddAssert("ensure no submission", () => Player.SubmittedScore == null); AddAssert("ensure no submission", () => Player.SubmittedScore == null);
@ -176,7 +176,7 @@ namespace osu.Game.Tests.Visual.Gameplay
addFakeHit(); addFakeHit();
AddUntilStep("wait for fail", () => Player.HasFailed); AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddStep("exit", () => Player.Exit()); AddStep("exit", () => Player.Exit());
AddAssert("ensure failing submission", () => Player.SubmittedScore?.ScoreInfo.Passed == false); AddAssert("ensure failing submission", () => Player.SubmittedScore?.ScoreInfo.Passed == false);

View File

@ -96,7 +96,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("set storyboard duration to 0.6s", () => currentStoryboardDuration = 600); AddStep("set storyboard duration to 0.6s", () => currentStoryboardDuration = 600);
}); });
AddUntilStep("wait for fail", () => Player.HasFailed); AddUntilStep("wait for fail", () => Player.GameplayState.HasFailed);
AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.GameplayClock.CurrentTime >= currentStoryboardDuration); AddUntilStep("storyboard ends", () => Player.GameplayClockContainer.GameplayClock.CurrentTime >= currentStoryboardDuration);
AddUntilStep("wait for fail overlay", () => Player.FailOverlay.State.Value == Visibility.Visible); AddUntilStep("wait for fail overlay", () => Player.FailOverlay.State.Value == Visibility.Visible);
} }

View File

@ -209,7 +209,7 @@ namespace osu.Game.Tests.Visual.Navigation
return (player = Game.ScreenStack.CurrentScreen as Player) != null; return (player = Game.ScreenStack.CurrentScreen as Player) != null;
}); });
AddUntilStep("wait for fail", () => player.HasFailed); AddUntilStep("wait for fail", () => player.GameplayState.HasFailed);
AddUntilStep("wait for track stop", () => !Game.MusicController.IsPlaying); AddUntilStep("wait for track stop", () => !Game.MusicController.IsPlaying);
AddAssert("Ensure time before preview point", () => Game.MusicController.CurrentTrack.CurrentTime < beatmap().BeatmapInfo.Metadata.PreviewTime); AddAssert("Ensure time before preview point", () => Game.MusicController.CurrentTrack.CurrentTime < beatmap().BeatmapInfo.Metadata.PreviewTime);

View File

@ -9,7 +9,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
{ {
public class MultiplayerPlayerLoader : PlayerLoader public class MultiplayerPlayerLoader : PlayerLoader
{ {
public bool GameplayPassed => player?.GameplayPassed == true; public bool GameplayPassed => player?.GameplayState.HasPassed == true;
private Player player; private Player player;

View File

@ -39,6 +39,16 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
public readonly Score Score; public readonly Score Score;
/// <summary>
/// Whether gameplay completed without the user failing.
/// </summary>
public bool HasPassed { get; set; }
/// <summary>
/// Whether the user failed during gameplay.
/// </summary>
public bool HasFailed { get; set; }
/// <summary> /// <summary>
/// A bindable tracking the last judgement result applied to any hit object. /// A bindable tracking the last judgement result applied to any hit object.
/// </summary> /// </summary>

View File

@ -72,15 +72,8 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
protected virtual bool PauseOnFocusLost => true; protected virtual bool PauseOnFocusLost => true;
/// <summary>
/// Whether gameplay has completed without the user having failed.
/// </summary>
public bool GameplayPassed { get; private set; }
public Action RestartRequested; public Action RestartRequested;
public bool HasFailed { get; private set; }
private Bindable<bool> mouseWheelDisabled; private Bindable<bool> mouseWheelDisabled;
private readonly Bindable<bool> storyboardReplacesBackground = new Bindable<bool>(); private readonly Bindable<bool> storyboardReplacesBackground = new Bindable<bool>();
@ -559,7 +552,7 @@ namespace osu.Game.Screens.Play
if (showDialogFirst && !pauseOrFailDialogVisible) if (showDialogFirst && !pauseOrFailDialogVisible)
{ {
// if the fail animation is currently in progress, accelerate it (it will show the pause dialog on completion). // if the fail animation is currently in progress, accelerate it (it will show the pause dialog on completion).
if (ValidForResume && HasFailed) if (ValidForResume && GameplayState.HasFailed)
{ {
failAnimationLayer.FinishTransforms(true); failAnimationLayer.FinishTransforms(true);
return; return;
@ -678,7 +671,7 @@ namespace osu.Game.Screens.Play
resultsDisplayDelegate?.Cancel(); resultsDisplayDelegate?.Cancel();
resultsDisplayDelegate = null; resultsDisplayDelegate = null;
GameplayPassed = false; GameplayState.HasPassed = false;
ValidForResume = true; ValidForResume = true;
skipOutroOverlay.Hide(); skipOutroOverlay.Hide();
return; return;
@ -688,7 +681,7 @@ namespace osu.Game.Screens.Play
if (HealthProcessor.HasFailed) if (HealthProcessor.HasFailed)
return; return;
GameplayPassed = true; GameplayState.HasPassed = true;
// Setting this early in the process means that even if something were to go wrong in the order of events following, there // Setting this early in the process means that even if something were to go wrong in the order of events following, there
// is no chance that a user could return to the (already completed) Player instance from a child screen. // is no chance that a user could return to the (already completed) Player instance from a child screen.
@ -804,7 +797,7 @@ namespace osu.Game.Screens.Play
if (!CheckModsAllowFailure()) if (!CheckModsAllowFailure())
return false; return false;
HasFailed = true; GameplayState.HasFailed = true;
Score.ScoreInfo.Passed = false; Score.ScoreInfo.Passed = false;
// There is a chance that we could be in a paused state as the ruleset's internal clock (see FrameStabilityContainer) // There is a chance that we could be in a paused state as the ruleset's internal clock (see FrameStabilityContainer)
@ -859,13 +852,13 @@ namespace osu.Game.Screens.Play
// replays cannot be paused and exit immediately // replays cannot be paused and exit immediately
&& !DrawableRuleset.HasReplayLoaded.Value && !DrawableRuleset.HasReplayLoaded.Value
// cannot pause if we are already in a fail state // cannot pause if we are already in a fail state
&& !HasFailed; && !GameplayState.HasFailed;
private bool canResume => private bool canResume =>
// cannot resume from a non-paused state // cannot resume from a non-paused state
GameplayClockContainer.IsPaused.Value GameplayClockContainer.IsPaused.Value
// cannot resume if we are already in a fail state // cannot resume if we are already in a fail state
&& !HasFailed && !GameplayState.HasFailed
// already resuming // already resuming
&& !IsResuming; && !IsResuming;