mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 10:33:07 +08:00
Add basic pause tests
This commit is contained in:
parent
465c95e952
commit
bcaff9f7b4
47
osu.Game.Tests/Visual/TestCasePause.cs
Normal file
47
osu.Game.Tests/Visual/TestCasePause.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ using osu.Game.Rulesets.Mods;
|
||||
namespace osu.Game.Screens.Play
|
||||
{
|
||||
/// <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>
|
||||
public class GameplayClockContainer : Container
|
||||
{
|
||||
@ -48,7 +48,7 @@ namespace osu.Game.Screens.Play
|
||||
/// The final clock which is exposed to underlying components.
|
||||
/// </summary>
|
||||
[Cached]
|
||||
private readonly GameplayClock gameplayClock;
|
||||
public readonly GameplayClock GameplayClock;
|
||||
|
||||
private Bindable<double> userAudioOffset;
|
||||
|
||||
@ -78,7 +78,7 @@ namespace osu.Game.Screens.Play
|
||||
offsetClock = new FramedOffsetClock(platformOffsetClock);
|
||||
|
||||
// the clock to be exposed via DI to children.
|
||||
gameplayClock = new GameplayClock(offsetClock);
|
||||
GameplayClock = new GameplayClock(offsetClock);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -82,7 +82,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
public bool LoadedBeatmapSuccessfully => RulesetContainer?.Objects.Any() == true;
|
||||
|
||||
private GameplayClockContainer gameplayClockContainer;
|
||||
protected GameplayClockContainer GameplayClockContainer { get; private set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio, IAPIProvider api, OsuConfigManager config)
|
||||
@ -102,9 +102,9 @@ namespace osu.Game.Screens.Play
|
||||
if (!ScoreProcessor.Mode.Disabled)
|
||||
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
|
||||
{
|
||||
@ -113,11 +113,11 @@ namespace osu.Game.Screens.Play
|
||||
OnQuit = performUserRequestedExit,
|
||||
RequestResume = completion =>
|
||||
{
|
||||
gameplayClockContainer.Start();
|
||||
GameplayClockContainer.Start();
|
||||
completion();
|
||||
},
|
||||
RequestPause = gameplayClockContainer.Stop,
|
||||
IsPaused = { BindTarget = gameplayClockContainer.IsPaused },
|
||||
RequestPause = GameplayClockContainer.Stop,
|
||||
IsPaused = { BindTarget = GameplayClockContainer.IsPaused },
|
||||
CheckCanPause = () => CanPause,
|
||||
Children = new[]
|
||||
{
|
||||
@ -141,15 +141,15 @@ namespace osu.Game.Screens.Play
|
||||
HUDOverlay = new HUDOverlay(ScoreProcessor, RulesetContainer, working)
|
||||
{
|
||||
HoldToQuit = { Action = performUserRequestedExit },
|
||||
PlayerSettingsOverlay = { PlaybackSettings = { UserPlaybackRate = { BindTarget = gameplayClockContainer.UserPlaybackRate } } },
|
||||
PlayerSettingsOverlay = { PlaybackSettings = { UserPlaybackRate = { BindTarget = GameplayClockContainer.UserPlaybackRate } } },
|
||||
KeyCounter = { Visible = { BindTarget = RulesetContainer.HasReplayLoaded } },
|
||||
RequestSeek = gameplayClockContainer.Seek,
|
||||
RequestSeek = GameplayClockContainer.Seek,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
},
|
||||
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
|
||||
RulesetContainer.IsPaused.BindTo(gameplayClockContainer.IsPaused);
|
||||
RulesetContainer.IsPaused.BindTo(GameplayClockContainer.IsPaused);
|
||||
|
||||
if (ShowStoryboard.Value)
|
||||
initializeStoryboard(false);
|
||||
@ -295,7 +295,7 @@ namespace osu.Game.Screens.Play
|
||||
if (Beatmap.Value.Mods.Value.OfType<IApplicableFailOverride>().Any(m => !m.AllowFail))
|
||||
return false;
|
||||
|
||||
gameplayClockContainer.Stop();
|
||||
GameplayClockContainer.Stop();
|
||||
|
||||
HasFailed = true;
|
||||
failOverlay.Retries = RestartCount;
|
||||
@ -329,7 +329,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
storyboardReplacesBackground.Value = Beatmap.Value.Storyboard.ReplacesBackground && Beatmap.Value.Storyboard.HasDrawable;
|
||||
|
||||
gameplayClockContainer.Restart();
|
||||
GameplayClockContainer.Restart();
|
||||
|
||||
PausableGameplayContainer.Alpha = 0;
|
||||
PausableGameplayContainer.FadeIn(750, Easing.OutQuint);
|
||||
@ -359,7 +359,7 @@ namespace osu.Game.Screens.Play
|
||||
return true;
|
||||
}
|
||||
|
||||
gameplayClockContainer.ResetLocalAdjustments();
|
||||
GameplayClockContainer.ResetLocalAdjustments();
|
||||
|
||||
fadeOut();
|
||||
return base.OnExiting(next);
|
||||
|
Loading…
Reference in New Issue
Block a user