Add basic pause tests

This commit is contained in:
Dean Herbert 2019-03-18 00:46:15 +09:00
parent 465c95e952
commit bcaff9f7b4
3 changed files with 63 additions and 16 deletions

View File

@ -0,0 +1,47 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual
{
public class TestCasePause : TestCasePlayer
{
public TestCasePause()
: base(new OsuRuleset())
{
}
protected override Player CreatePlayer(Ruleset ruleset) => new PausePlayer();
protected override void AddCheckSteps(Func<Player> player)
{
PausePlayer pausable() => (PausePlayer)player();
base.AddCheckSteps(player);
//AddUntilStep(() => pausable().ScoreProcessor.TotalScore.Value > 0, "score above zero");
AddStep("pause", () => pausable().PausableGameplayContainer.Pause());
AddAssert("clock stopped", () => !pausable().GameplayClockContainer.GameplayClock.IsRunning);
AddStep("resume", () => pausable().PausableGameplayContainer.Resume());
AddUntilStep(() => pausable().GameplayClockContainer.GameplayClock.IsRunning, "clock started");
AddStep("pause too soon", () => pausable().PausableGameplayContainer.Pause());
AddAssert("clock not stopped", () => pausable().GameplayClockContainer.GameplayClock.IsRunning);
}
private class PausePlayer : Player
{
public new PausableGameplayContainer PausableGameplayContainer => base.PausableGameplayContainer;
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
}
}
}

View File

@ -18,7 +18,7 @@ using osu.Game.Rulesets.Mods;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
/// <summary> /// <summary>
/// Encapsulates gameplay timing logic and provides a <see cref="GameplayClock"/> for children. /// Encapsulates gameplay timing logic and provides a <see cref="Play.GameplayClock"/> for children.
/// </summary> /// </summary>
public class GameplayClockContainer : Container public class GameplayClockContainer : Container
{ {
@ -48,7 +48,7 @@ namespace osu.Game.Screens.Play
/// The final clock which is exposed to underlying components. /// The final clock which is exposed to underlying components.
/// </summary> /// </summary>
[Cached] [Cached]
private readonly GameplayClock gameplayClock; public readonly GameplayClock GameplayClock;
private Bindable<double> userAudioOffset; private Bindable<double> userAudioOffset;
@ -78,7 +78,7 @@ namespace osu.Game.Screens.Play
offsetClock = new FramedOffsetClock(platformOffsetClock); offsetClock = new FramedOffsetClock(platformOffsetClock);
// the clock to be exposed via DI to children. // the clock to be exposed via DI to children.
gameplayClock = new GameplayClock(offsetClock); GameplayClock = new GameplayClock(offsetClock);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -82,7 +82,7 @@ namespace osu.Game.Screens.Play
public bool LoadedBeatmapSuccessfully => RulesetContainer?.Objects.Any() == true; public bool LoadedBeatmapSuccessfully => RulesetContainer?.Objects.Any() == true;
private GameplayClockContainer gameplayClockContainer; protected GameplayClockContainer GameplayClockContainer { get; private set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio, IAPIProvider api, OsuConfigManager config) private void load(AudioManager audio, IAPIProvider api, OsuConfigManager config)
@ -102,9 +102,9 @@ namespace osu.Game.Screens.Play
if (!ScoreProcessor.Mode.Disabled) if (!ScoreProcessor.Mode.Disabled)
config.BindWith(OsuSetting.ScoreDisplayMode, ScoreProcessor.Mode); config.BindWith(OsuSetting.ScoreDisplayMode, ScoreProcessor.Mode);
InternalChild = gameplayClockContainer = new GameplayClockContainer(working, AllowLeadIn, RulesetContainer.GameplayStartTime); InternalChild = GameplayClockContainer = new GameplayClockContainer(working, AllowLeadIn, RulesetContainer.GameplayStartTime);
gameplayClockContainer.Children = new Drawable[] GameplayClockContainer.Children = new Drawable[]
{ {
PausableGameplayContainer = new PausableGameplayContainer PausableGameplayContainer = new PausableGameplayContainer
{ {
@ -113,11 +113,11 @@ namespace osu.Game.Screens.Play
OnQuit = performUserRequestedExit, OnQuit = performUserRequestedExit,
RequestResume = completion => RequestResume = completion =>
{ {
gameplayClockContainer.Start(); GameplayClockContainer.Start();
completion(); completion();
}, },
RequestPause = gameplayClockContainer.Stop, RequestPause = GameplayClockContainer.Stop,
IsPaused = { BindTarget = gameplayClockContainer.IsPaused }, IsPaused = { BindTarget = GameplayClockContainer.IsPaused },
CheckCanPause = () => CanPause, CheckCanPause = () => CanPause,
Children = new[] Children = new[]
{ {
@ -141,15 +141,15 @@ namespace osu.Game.Screens.Play
HUDOverlay = new HUDOverlay(ScoreProcessor, RulesetContainer, working) HUDOverlay = new HUDOverlay(ScoreProcessor, RulesetContainer, working)
{ {
HoldToQuit = { Action = performUserRequestedExit }, HoldToQuit = { Action = performUserRequestedExit },
PlayerSettingsOverlay = { PlaybackSettings = { UserPlaybackRate = { BindTarget = gameplayClockContainer.UserPlaybackRate } } }, PlayerSettingsOverlay = { PlaybackSettings = { UserPlaybackRate = { BindTarget = GameplayClockContainer.UserPlaybackRate } } },
KeyCounter = { Visible = { BindTarget = RulesetContainer.HasReplayLoaded } }, KeyCounter = { Visible = { BindTarget = RulesetContainer.HasReplayLoaded } },
RequestSeek = gameplayClockContainer.Seek, RequestSeek = GameplayClockContainer.Seek,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre Origin = Anchor.Centre
}, },
new SkipOverlay(RulesetContainer.GameplayStartTime) new SkipOverlay(RulesetContainer.GameplayStartTime)
{ {
RequestSeek = gameplayClockContainer.Seek RequestSeek = GameplayClockContainer.Seek
}, },
} }
}, },
@ -171,7 +171,7 @@ namespace osu.Game.Screens.Play
}; };
// bind clock into components that require it // bind clock into components that require it
RulesetContainer.IsPaused.BindTo(gameplayClockContainer.IsPaused); RulesetContainer.IsPaused.BindTo(GameplayClockContainer.IsPaused);
if (ShowStoryboard.Value) if (ShowStoryboard.Value)
initializeStoryboard(false); initializeStoryboard(false);
@ -295,7 +295,7 @@ namespace osu.Game.Screens.Play
if (Beatmap.Value.Mods.Value.OfType<IApplicableFailOverride>().Any(m => !m.AllowFail)) if (Beatmap.Value.Mods.Value.OfType<IApplicableFailOverride>().Any(m => !m.AllowFail))
return false; return false;
gameplayClockContainer.Stop(); GameplayClockContainer.Stop();
HasFailed = true; HasFailed = true;
failOverlay.Retries = RestartCount; failOverlay.Retries = RestartCount;
@ -329,7 +329,7 @@ namespace osu.Game.Screens.Play
storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable; storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable;
gameplayClockContainer.Restart(); GameplayClockContainer.Restart();
PausableGameplayContainer.Alpha = 0; PausableGameplayContainer.Alpha = 0;
PausableGameplayContainer.FadeIn(750, Easing.OutQuint); PausableGameplayContainer.FadeIn(750, Easing.OutQuint);
@ -359,7 +359,7 @@ namespace osu.Game.Screens.Play
return true; return true;
} }
gameplayClockContainer.ResetLocalAdjustments(); GameplayClockContainer.ResetLocalAdjustments();
fadeOut(); fadeOut();
return base.OnExiting(next); return base.OnExiting(next);