mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 21:02:54 +08:00
Merge pull request #1575 from peppy/fix-player-testcases
Fix TestCasePlayer not working as expected
This commit is contained in:
commit
b3279082e2
@ -1 +1 @@
|
|||||||
Subproject commit d87dab204b3df50f62e6070b1970c135ea647d78
|
Subproject commit fe49ccb3c8f8661d653752d225ae1dc183944bb4
|
@ -46,6 +46,8 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
public bool HasFailed { get; private set; }
|
public bool HasFailed { get; private set; }
|
||||||
|
|
||||||
|
public bool AllowPause { get; set; } = true;
|
||||||
|
|
||||||
public int RestartCount;
|
public int RestartCount;
|
||||||
|
|
||||||
private IAdjustableClock adjustableSourceClock;
|
private IAdjustableClock adjustableSourceClock;
|
||||||
@ -158,7 +160,7 @@ namespace osu.Game.Screens.Play
|
|||||||
FramedClock = offsetClock,
|
FramedClock = offsetClock,
|
||||||
OnRetry = Restart,
|
OnRetry = Restart,
|
||||||
OnQuit = Exit,
|
OnQuit = Exit,
|
||||||
CheckCanPause = () => ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded,
|
CheckCanPause = () => AllowPause && ValidForResume && !HasFailed && !RulesetContainer.HasReplayLoaded,
|
||||||
Retries = RestartCount,
|
Retries = RestartCount,
|
||||||
OnPause = () => {
|
OnPause = () => {
|
||||||
hudOverlay.KeyCounter.IsCounting = pauseContainer.IsPaused;
|
hudOverlay.KeyCounter.IsCounting = pauseContainer.IsPaused;
|
||||||
@ -355,7 +357,7 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
protected override bool OnExiting(Screen next)
|
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.
|
// In the case of replays, we may have changed the playback rate.
|
||||||
applyRateFromMods();
|
applyRateFromMods();
|
||||||
|
48
osu.Game/Tests/Visual/ScreenTestCase.cs
Normal file
48
osu.Game/Tests/Visual/ScreenTestCase.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
// 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
|
||||||
|
{
|
||||||
|
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
|
namespace osu.Game.Tests.Visual
|
||||||
{
|
{
|
||||||
public abstract class TestCasePlayer : OsuTestCase
|
public abstract class TestCasePlayer : ScreenTestCase
|
||||||
{
|
{
|
||||||
private readonly Type ruleset;
|
private readonly Type ruleset;
|
||||||
|
|
||||||
@ -44,6 +44,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Framework.Graphics.Axes.Both,
|
RelativeSizeAxes = Framework.Graphics.Axes.Both,
|
||||||
Colour = Color4.Black,
|
Colour = Color4.Black,
|
||||||
|
Depth = int.MaxValue
|
||||||
});
|
});
|
||||||
|
|
||||||
string instantiation = ruleset?.AssemblyQualifiedName;
|
string instantiation = ruleset?.AssemblyQualifiedName;
|
||||||
@ -77,19 +78,17 @@ namespace osu.Game.Tests.Visual
|
|||||||
if (Player != null)
|
if (Player != null)
|
||||||
Remove(Player);
|
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,
|
||||||
{
|
AllowPause = false
|
||||||
InitialBeatmap = beatmap
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
private const string test_beatmap_data =
|
private const string test_beatmap_data =
|
||||||
@"osu file format v14
|
@"osu file format v14
|
||||||
|
|
||||||
[General]
|
[General]
|
||||||
AudioLeadIn: 500
|
AudioLeadIn: 500
|
||||||
|
@ -784,6 +784,7 @@
|
|||||||
<Compile Include="Tests\Beatmaps\TestWorkingBeatmap.cs" />
|
<Compile Include="Tests\Beatmaps\TestWorkingBeatmap.cs" />
|
||||||
<Compile Include="Tests\Platform\TestStorage.cs" />
|
<Compile Include="Tests\Platform\TestStorage.cs" />
|
||||||
<Compile Include="Tests\Visual\OsuTestCase.cs" />
|
<Compile Include="Tests\Visual\OsuTestCase.cs" />
|
||||||
|
<Compile Include="Tests\Visual\ScreenTestCase.cs" />
|
||||||
<Compile Include="Tests\Visual\TestCasePlayer.cs" />
|
<Compile Include="Tests\Visual\TestCasePlayer.cs" />
|
||||||
<Compile Include="Users\Avatar.cs" />
|
<Compile Include="Users\Avatar.cs" />
|
||||||
<Compile Include="Users\Country.cs" />
|
<Compile Include="Users\Country.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user