From 74c63e15bef6d50aa8e4a43a44a7f8a449d0984c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 1 Jul 2021 17:38:28 +0900 Subject: [PATCH] Mark score failed on fail and exit --- .../TestScenePlayerScoreSubmission.cs | 38 ++++++++++++++----- osu.Game/Screens/Play/Player.cs | 5 +++ osu.Game/Screens/Play/SubmittingPlayer.cs | 4 +- osu.Game/Tests/Visual/TestPlayer.cs | 5 ++- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs index 4088fc855d..ada50fbcf4 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestScenePlayerScoreSubmission.cs @@ -23,9 +23,14 @@ namespace osu.Game.Tests.Visual.Gameplay protected override bool HasCustomSteps => true; + private bool allowFail; + protected override TestPlayer CreatePlayer(Ruleset ruleset) { - SelectedMods.Value = new[] { ruleset.GetAllMods().OfType().First() }; + SelectedMods.Value = !allowFail + ? new[] { ruleset.GetAllMods().OfType().First() } + : Array.Empty(); + return new TestPlayer(false); } @@ -34,7 +39,7 @@ namespace osu.Game.Tests.Visual.Gameplay { prepareTokenResponse(false); - CreateTest(() => { }); + CreateTest(() => allowFail = false); AddUntilStep("wait for token request", () => Player.TokenCreationRequested); @@ -43,7 +48,7 @@ namespace osu.Game.Tests.Visual.Gameplay AddUntilStep("results displayed", () => Player.GetChildScreen() is ResultsScreen); - AddAssert("ensure no submission", () => !Player.SubmissionRequested); + AddAssert("ensure no submission", () => Player.SubmittedScore == null); } [Test] @@ -51,7 +56,7 @@ namespace osu.Game.Tests.Visual.Gameplay { prepareTokenResponse(true); - CreateTest(() => { }); + CreateTest(() => allowFail = false); AddUntilStep("wait for token request", () => Player.TokenCreationRequested); @@ -59,8 +64,7 @@ namespace osu.Game.Tests.Visual.Gameplay AddStep("seek to completion", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.Objects.Last().GetEndTime())); AddUntilStep("results displayed", () => Player.GetChildScreen() is ResultsScreen); - - AddAssert("ensure submission", () => Player.SubmissionRequested); + AddAssert("ensure passing submission", () => Player.SubmittedScore?.ScoreInfo.Passed == true); } [Test] @@ -68,12 +72,26 @@ namespace osu.Game.Tests.Visual.Gameplay { prepareTokenResponse(false); - CreateTest(() => { }); + CreateTest(() => allowFail = false); AddUntilStep("wait for token request", () => Player.TokenCreationRequested); + + AddStep("exit", () => Player.Exit()); + AddAssert("ensure no submission", () => Player.SubmittedScore == null); + } + + [Test] + public void TestSubmissionOnFail() + { + prepareTokenResponse(true); + + CreateTest(() => allowFail = true); + + AddUntilStep("wait for token request", () => Player.TokenCreationRequested); + AddUntilStep("wait for fail", () => Player.HasFailed); AddStep("exit", () => Player.Exit()); - AddAssert("ensure no submission", () => !Player.SubmissionRequested); + AddAssert("ensure failing submission", () => Player.SubmittedScore?.ScoreInfo.Passed == false); } [Test] @@ -81,11 +99,11 @@ namespace osu.Game.Tests.Visual.Gameplay { prepareTokenResponse(true); - CreateTest(() => { }); + CreateTest(() => allowFail = false); AddUntilStep("wait for token request", () => Player.TokenCreationRequested); AddStep("exit", () => Player.Exit()); - AddUntilStep("wait for submission", () => Player.SubmissionRequested); + AddAssert("ensure failing submission", () => Player.SubmittedScore?.ScoreInfo.Passed == false); } private void prepareTokenResponse(bool validToken) diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 58f60d14cf..97854ee12f 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -768,6 +768,7 @@ namespace osu.Game.Screens.Play return false; HasFailed = true; + Score.ScoreInfo.Passed = false; // There is a chance that we could be in a paused state as the ruleset's internal clock (see FrameStabilityContainer) // could process an extra frame after the GameplayClock is stopped. @@ -950,6 +951,10 @@ namespace osu.Game.Screens.Play { screenSuspension?.Expire(); + // if arriving here and the results screen preparation task hasn't run, it's safe to say the user has not completed the beatmap. + if (prepareScoreForDisplayTask == null) + Score.ScoreInfo.Passed = false; + // EndPlaying() is typically called from ReplayRecorder.Dispose(). Disposal is currently asynchronous. // To resolve test failures, forcefully end playing synchronously when this screen exits. // Todo: Replace this with a more permanent solution once osu-framework has a synchronous cleanup method. diff --git a/osu.Game/Screens/Play/SubmittingPlayer.cs b/osu.Game/Screens/Play/SubmittingPlayer.cs index bbb6a21f39..7c5a06707d 100644 --- a/osu.Game/Screens/Play/SubmittingPlayer.cs +++ b/osu.Game/Screens/Play/SubmittingPlayer.cs @@ -113,9 +113,11 @@ namespace osu.Game.Screens.Play public override bool OnExiting(IScreen next) { + var exiting = base.OnExiting(next); + submitScore(Score); - return base.OnExiting(next); + return exiting; } /// diff --git a/osu.Game/Tests/Visual/TestPlayer.cs b/osu.Game/Tests/Visual/TestPlayer.cs index 52eb06bdc6..5e5f20b307 100644 --- a/osu.Game/Tests/Visual/TestPlayer.cs +++ b/osu.Game/Tests/Visual/TestPlayer.cs @@ -40,7 +40,8 @@ namespace osu.Game.Tests.Visual public new HealthProcessor HealthProcessor => base.HealthProcessor; public bool TokenCreationRequested { get; private set; } - public bool SubmissionRequested { get; private set; } + + public Score SubmittedScore { get; private set; } public new bool PauseCooldownActive => base.PauseCooldownActive; @@ -66,7 +67,7 @@ namespace osu.Game.Tests.Visual protected override APIRequest CreateSubmissionRequest(Score score, long token) { - SubmissionRequested = true; + SubmittedScore = score; return base.CreateSubmissionRequest(score, token); }