2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-09-18 21:32:49 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
2017-11-23 19:42:07 +08:00
|
|
|
|
public abstract class TestCasePlayer : ScreenTestCase
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2018-01-10 15:58:10 +08:00
|
|
|
|
private readonly Ruleset ruleset;
|
2017-10-02 17:38:48 +08:00
|
|
|
|
|
2017-09-18 21:32:49 +08:00
|
|
|
|
protected Player Player;
|
|
|
|
|
|
2017-12-26 14:02:01 +08:00
|
|
|
|
private TestWorkingBeatmap working;
|
|
|
|
|
|
2018-01-10 15:58:10 +08:00
|
|
|
|
protected TestCasePlayer(Ruleset ruleset)
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2017-10-02 17:38:48 +08:00
|
|
|
|
this.ruleset = ruleset;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-23 18:29:47 +08:00
|
|
|
|
protected TestCasePlayer()
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2017-10-02 17:38:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(RulesetStore rulesets)
|
|
|
|
|
{
|
2017-09-18 21:32:49 +08:00
|
|
|
|
Add(new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Framework.Graphics.Axes.Both,
|
|
|
|
|
Colour = Color4.Black,
|
2017-11-23 19:42:07 +08:00
|
|
|
|
Depth = int.MaxValue
|
2017-09-18 21:32:49 +08:00
|
|
|
|
});
|
|
|
|
|
|
2018-01-10 15:58:10 +08:00
|
|
|
|
if (ruleset != null)
|
2017-11-29 16:25:55 +08:00
|
|
|
|
{
|
|
|
|
|
Player p = null;
|
2018-01-10 15:58:10 +08:00
|
|
|
|
AddStep(ruleset.RulesetInfo.Name, () => p = loadPlayerFor(ruleset));
|
2017-11-29 16:25:55 +08:00
|
|
|
|
AddUntilStep(() => p.IsLoaded);
|
|
|
|
|
}
|
2018-01-10 15:58:10 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var r in rulesets.AvailableRulesets)
|
|
|
|
|
{
|
|
|
|
|
Player p = null;
|
|
|
|
|
AddStep(r.Name, () => p = loadPlayerFor(r));
|
|
|
|
|
AddUntilStep(() => p.IsLoaded);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-18 21:32:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 18:41:09 +08:00
|
|
|
|
protected virtual Beatmap CreateBeatmap(Ruleset ruleset) => new TestBeatmap(ruleset.RulesetInfo);
|
2017-09-19 20:40:57 +08:00
|
|
|
|
|
2018-01-10 15:58:10 +08:00
|
|
|
|
private Player loadPlayerFor(RulesetInfo ri) => loadPlayerFor(ri.CreateInstance());
|
|
|
|
|
|
|
|
|
|
private Player loadPlayerFor(Ruleset r)
|
2017-09-19 20:40:57 +08:00
|
|
|
|
{
|
2018-03-12 18:41:09 +08:00
|
|
|
|
var beatmap = CreateBeatmap(r);
|
2017-09-18 21:32:49 +08:00
|
|
|
|
|
2017-12-26 14:02:01 +08:00
|
|
|
|
working = new TestWorkingBeatmap(beatmap);
|
2018-01-10 15:58:10 +08:00
|
|
|
|
working.Mods.Value = new[] { r.GetAllMods().First(m => m is ModNoFail) };
|
2017-09-18 21:32:49 +08:00
|
|
|
|
|
|
|
|
|
if (Player != null)
|
|
|
|
|
Remove(Player);
|
|
|
|
|
|
2018-01-10 15:58:10 +08:00
|
|
|
|
var player = CreatePlayer(working, r);
|
2017-11-29 16:25:55 +08:00
|
|
|
|
|
|
|
|
|
LoadComponentAsync(player, LoadScreen);
|
|
|
|
|
|
|
|
|
|
return player;
|
2017-09-18 21:32:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 14:02:01 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (working != null)
|
|
|
|
|
// note that this will override any mod rate application
|
|
|
|
|
working.Track.Rate = Clock.Rate;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 19:42:07 +08:00
|
|
|
|
protected virtual Player CreatePlayer(WorkingBeatmap beatmap, Ruleset ruleset) => new Player
|
2017-09-18 21:32:49 +08:00
|
|
|
|
{
|
2017-11-23 19:42:07 +08:00
|
|
|
|
InitialBeatmap = beatmap,
|
2017-12-26 13:00:58 +08:00
|
|
|
|
AllowPause = false,
|
|
|
|
|
AllowLeadIn = false,
|
|
|
|
|
AllowResults = false,
|
2017-11-23 19:42:07 +08:00
|
|
|
|
};
|
2017-09-18 21:32:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|