1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 13:33:22 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneAllRulesetPlayers.cs

88 lines
2.6 KiB
C#
Raw Normal View History

// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using NUnit.Framework;
using osu.Framework.Allocation;
2019-04-12 13:53:23 +08:00
using osu.Game.Configuration;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Taiko;
using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual.Gameplay
{
/// <summary>
/// A base class which runs <see cref="Player"/> test for all available rulesets.
/// Steps to be run for each ruleset should be added via <see cref="AddCheckSteps"/>.
/// </summary>
public abstract class TestSceneAllRulesetPlayers : RateAdjustedBeatmapTestScene
{
protected Player Player { get; private set; }
protected OsuConfigManager Config { get; private set; }
[BackgroundDependencyLoader]
2022-01-15 08:06:39 +08:00
private void load()
{
Dependencies.Cache(Config = new OsuConfigManager(LocalStorage));
Config.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
}
[Test]
public void TestOsu() => runForRuleset(new OsuRuleset().RulesetInfo);
[Test]
public void TestTaiko() => runForRuleset(new TaikoRuleset().RulesetInfo);
[Test]
public void TestCatch() => runForRuleset(new CatchRuleset().RulesetInfo);
[Test]
public void TestMania() => runForRuleset(new ManiaRuleset().RulesetInfo);
private void runForRuleset(RulesetInfo ruleset)
{
Player p = null;
AddStep($"load {ruleset.Name} player", () => p = loadPlayerFor(ruleset));
AddUntilStep("player loaded", () =>
{
if (p?.IsLoaded == true)
{
p = null;
return true;
}
return false;
});
2019-04-12 13:53:23 +08:00
AddCheckSteps();
}
protected abstract void AddCheckSteps();
private Player loadPlayerFor(RulesetInfo rulesetInfo)
{
Ruleset.Value = rulesetInfo;
var ruleset = rulesetInfo.CreateInstance();
var working = CreateWorkingBeatmap(rulesetInfo);
Beatmap.Value = working;
SelectedMods.Value = new[] { ruleset.CreateMod<ModNoFail>() };
Player = CreatePlayer(ruleset);
LoadScreen(Player);
return Player;
}
protected virtual Player CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false);
}
}