mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 23:52:57 +08:00
Fix TestCasePlayer not working as expected
This commit is contained in:
parent
69a6905c84
commit
9565a9c352
@ -46,6 +46,8 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
public bool HasFailed { get; private set; }
|
||||
|
||||
public bool AllowPause { get; set; } = true;
|
||||
|
||||
public int RestartCount;
|
||||
|
||||
private IAdjustableClock adjustableSourceClock;
|
||||
@ -158,7 +160,7 @@ namespace osu.Game.Screens.Play
|
||||
FramedClock = offsetClock,
|
||||
OnRetry = Restart,
|
||||
OnQuit = Exit,
|
||||
CheckCanPause = () => ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded,
|
||||
CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded,
|
||||
Retries = RestartCount,
|
||||
OnPause = () => {
|
||||
hudOverlay.KeyCounter.IsCounting = pauseContainer.IsPaused;
|
||||
@ -355,7 +357,7 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
protected override bool OnExiting(Screen next)
|
||||
{
|
||||
if (HasFailed || !ValidForResume || pauseContainer?.AllowExit != false || RulesetContainer?.HasReplayLoaded != false)
|
||||
if (!AllowPause || HasFailed || !ValidForResume || pauseContainer?.AllowExit != false || RulesetContainer?.HasReplayLoaded != false)
|
||||
{
|
||||
// In the case of replays, we may have changed the playback rate.
|
||||
applyRateFromMods();
|
||||
|
52
osu.Game/Tests/Visual/ScreenTestCase.cs
Normal file
52
osu.Game/Tests/Visual/ScreenTestCase.cs
Normal file
@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Screens;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
/// <summary>
|
||||
/// A test case which can be used to test a screen (that relies on OnEntering being called to execute startup instructions).
|
||||
/// </summary>
|
||||
public abstract class ScreenTestCase : OsuTestCase
|
||||
{
|
||||
private readonly TestOsuScreen baseScreen;
|
||||
|
||||
protected ScreenTestCase()
|
||||
{
|
||||
Add(baseScreen = new TestOsuScreen());
|
||||
}
|
||||
|
||||
protected void LoadScreen(OsuScreen screen) => baseScreen.LoadScreen(screen);
|
||||
|
||||
public class TestOsuScreen : OsuScreen
|
||||
{
|
||||
public TestOsuScreen()
|
||||
{
|
||||
}
|
||||
|
||||
private OsuScreen nextScreen;
|
||||
|
||||
public void LoadScreen(OsuScreen screen) => Schedule(() =>
|
||||
{
|
||||
nextScreen = screen;
|
||||
|
||||
if (IsCurrentScreen)
|
||||
{
|
||||
Push(screen);
|
||||
nextScreen = null;
|
||||
}
|
||||
else
|
||||
MakeCurrent();
|
||||
});
|
||||
|
||||
protected override void OnResuming(Screen last)
|
||||
{
|
||||
base.OnResuming(last);
|
||||
if (nextScreen != null)
|
||||
LoadScreen(nextScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public abstract class TestCasePlayer : OsuTestCase
|
||||
public abstract class TestCasePlayer : ScreenTestCase
|
||||
{
|
||||
private readonly Type ruleset;
|
||||
|
||||
@ -44,6 +44,7 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
RelativeSizeAxes = Framework.Graphics.Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
Depth = int.MaxValue
|
||||
});
|
||||
|
||||
string instantiation = ruleset?.AssemblyQualifiedName;
|
||||
@ -77,19 +78,17 @@ namespace osu.Game.Tests.Visual
|
||||
if (Player != null)
|
||||
Remove(Player);
|
||||
|
||||
Add(Player = CreatePlayer(working, instance));
|
||||
LoadScreen(CreatePlayer(working, instance));
|
||||
}
|
||||
|
||||
protected virtual Player CreatePlayer(WorkingBeatmap beatmap, Ruleset ruleset)
|
||||
protected virtual Player CreatePlayer(WorkingBeatmap beatmap, Ruleset ruleset) => new Player
|
||||
{
|
||||
return new Player
|
||||
{
|
||||
InitialBeatmap = beatmap
|
||||
};
|
||||
}
|
||||
InitialBeatmap = beatmap,
|
||||
AllowPause = false
|
||||
};
|
||||
|
||||
private const string test_beatmap_data =
|
||||
@"osu file format v14
|
||||
@"osu file format v14
|
||||
|
||||
[General]
|
||||
AudioLeadIn: 500
|
||||
|
@ -784,6 +784,7 @@
|
||||
<Compile Include="Tests\Beatmaps\TestWorkingBeatmap.cs" />
|
||||
<Compile Include="Tests\Platform\TestStorage.cs" />
|
||||
<Compile Include="Tests\Visual\OsuTestCase.cs" />
|
||||
<Compile Include="Tests\Visual\ScreenTestCase.cs" />
|
||||
<Compile Include="Tests\Visual\TestCasePlayer.cs" />
|
||||
<Compile Include="Users\Avatar.cs" />
|
||||
<Compile Include="Users\Country.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user