2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-20 16:30:27 +08:00
|
|
|
|
|
2019-04-09 14:05:03 +08:00
|
|
|
|
using System.Linq;
|
2018-08-02 18:47:50 +08:00
|
|
|
|
using System.Threading;
|
2019-04-09 12:50:54 +08:00
|
|
|
|
using NUnit.Framework;
|
2018-04-20 16:30:27 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-12 18:53:08 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-01-23 19:52:00 +08:00
|
|
|
|
using osu.Framework.Screens;
|
2019-04-09 14:05:03 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2019-04-19 18:45:17 +08:00
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2019-04-09 14:05:03 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2019-04-25 18:56:57 +08:00
|
|
|
|
using osu.Game.Scoring;
|
2019-02-25 21:05:49 +08:00
|
|
|
|
using osu.Game.Screens;
|
2018-04-20 16:30:27 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
2019-04-19 18:45:17 +08:00
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
2018-04-20 16:30:27 +08:00
|
|
|
|
|
2019-03-25 00:02:36 +08:00
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2018-04-20 16:30:27 +08:00
|
|
|
|
{
|
2018-08-02 18:47:50 +08:00
|
|
|
|
public class TestCasePlayerLoader : ManualInputManagerTestCase
|
2018-04-20 16:30:27 +08:00
|
|
|
|
{
|
2018-08-02 18:47:50 +08:00
|
|
|
|
private PlayerLoader loader;
|
2019-04-19 18:45:17 +08:00
|
|
|
|
private OsuScreenStack stack;
|
2019-02-25 21:05:49 +08:00
|
|
|
|
|
2019-04-19 18:45:17 +08:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup() => Schedule(() =>
|
2019-02-25 21:05:49 +08:00
|
|
|
|
{
|
2019-04-19 18:45:17 +08:00
|
|
|
|
InputManager.Child = stack = new OsuScreenStack { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
Beatmap.Value = new TestWorkingBeatmap(new TestBeatmap(new OsuRuleset().RulesetInfo), Clock);
|
|
|
|
|
});
|
2019-02-25 21:05:49 +08:00
|
|
|
|
|
2019-04-09 12:50:54 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestLoadContinuation()
|
2018-04-20 16:30:27 +08:00
|
|
|
|
{
|
2019-05-10 14:39:25 +08:00
|
|
|
|
AddStep("load dummy beatmap", () => stack.Push(loader = new PlayerLoader(() => new TestPlayer(false, false))));
|
2019-03-19 16:24:26 +08:00
|
|
|
|
AddUntilStep("wait for current", () => loader.IsCurrentScreen());
|
2018-08-02 18:47:50 +08:00
|
|
|
|
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
|
2019-03-19 16:24:26 +08:00
|
|
|
|
AddUntilStep("wait for no longer current", () => !loader.IsCurrentScreen());
|
2018-08-02 18:47:50 +08:00
|
|
|
|
AddStep("load slow dummy beatmap", () =>
|
|
|
|
|
{
|
2018-12-26 21:16:35 +08:00
|
|
|
|
SlowLoadPlayer slow = null;
|
2018-08-02 18:47:50 +08:00
|
|
|
|
|
2019-03-26 15:53:44 +08:00
|
|
|
|
stack.Push(loader = new PlayerLoader(() => slow = new SlowLoadPlayer(false, false)));
|
2018-08-02 18:47:50 +08:00
|
|
|
|
|
|
|
|
|
Scheduler.AddDelayed(() => slow.Ready = true, 5000);
|
|
|
|
|
});
|
|
|
|
|
|
2019-03-19 16:24:26 +08:00
|
|
|
|
AddUntilStep("wait for no longer current", () => !loader.IsCurrentScreen());
|
2018-08-02 18:47:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-09 14:05:03 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestModReinstantiation()
|
|
|
|
|
{
|
|
|
|
|
TestPlayer player = null;
|
|
|
|
|
TestMod gameMod = null;
|
|
|
|
|
TestMod playerMod1 = null;
|
|
|
|
|
TestMod playerMod2 = null;
|
|
|
|
|
|
|
|
|
|
AddStep("load player", () =>
|
|
|
|
|
{
|
2019-04-17 15:11:59 +08:00
|
|
|
|
Mods.Value = new[] { gameMod = new TestMod() };
|
2019-04-19 18:45:17 +08:00
|
|
|
|
stack.Push(loader = new PlayerLoader(() => player = new TestPlayer()));
|
2019-04-09 14:05:03 +08:00
|
|
|
|
});
|
|
|
|
|
|
2019-04-19 18:45:17 +08:00
|
|
|
|
AddUntilStep("wait for loader to become current", () => loader.IsCurrentScreen());
|
|
|
|
|
AddStep("mouse in centre", () => InputManager.MoveMouseTo(loader.ScreenSpaceDrawQuad.Centre));
|
|
|
|
|
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
|
|
|
|
AddStep("retrieve mods", () => playerMod1 = (TestMod)player.Mods.Value.Single());
|
2019-04-09 14:05:03 +08:00
|
|
|
|
AddAssert("game mods not applied", () => gameMod.Applied == false);
|
|
|
|
|
AddAssert("player mods applied", () => playerMod1.Applied);
|
|
|
|
|
|
|
|
|
|
AddStep("restart player", () =>
|
|
|
|
|
{
|
2019-04-19 18:45:17 +08:00
|
|
|
|
var lastPlayer = player;
|
2019-04-09 14:05:03 +08:00
|
|
|
|
player = null;
|
2019-04-19 18:45:17 +08:00
|
|
|
|
lastPlayer.Restart();
|
2019-04-09 14:05:03 +08:00
|
|
|
|
});
|
|
|
|
|
|
2019-04-19 18:45:17 +08:00
|
|
|
|
AddUntilStep("wait for player to be current", () => player.IsCurrentScreen());
|
|
|
|
|
AddStep("retrieve mods", () => playerMod2 = (TestMod)player.Mods.Value.Single());
|
2019-04-09 14:05:03 +08:00
|
|
|
|
AddAssert("game mods not applied", () => gameMod.Applied == false);
|
|
|
|
|
AddAssert("player has different mods", () => playerMod1 != playerMod2);
|
|
|
|
|
AddAssert("player mods applied", () => playerMod2.Applied);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestMod : Mod, IApplicableToScoreProcessor
|
|
|
|
|
{
|
|
|
|
|
public override string Name => string.Empty;
|
|
|
|
|
public override string Acronym => string.Empty;
|
|
|
|
|
public override double ScoreMultiplier => 1;
|
|
|
|
|
|
|
|
|
|
public bool Applied { get; private set; }
|
|
|
|
|
|
|
|
|
|
public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
|
|
|
|
|
{
|
|
|
|
|
Applied = true;
|
|
|
|
|
}
|
2019-04-25 18:56:57 +08:00
|
|
|
|
|
|
|
|
|
public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank;
|
2019-04-09 14:05:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-10 14:39:25 +08:00
|
|
|
|
protected class SlowLoadPlayer : TestPlayer
|
2018-08-02 18:47:50 +08:00
|
|
|
|
{
|
|
|
|
|
public bool Ready;
|
|
|
|
|
|
2019-03-26 15:53:44 +08:00
|
|
|
|
public SlowLoadPlayer(bool allowPause = true, bool showResults = true)
|
|
|
|
|
: base(allowPause, showResults)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-02 18:47:50 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
while (!Ready)
|
|
|
|
|
Thread.Sleep(1);
|
|
|
|
|
}
|
2018-04-20 16:30:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|