2019-05-10 09:10:07 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-03-18 07:39:34 +00:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2020-03-02 03:20:25 +00:00
|
|
|
using System;
|
2019-03-18 07:39:34 +00:00
|
|
|
using System.Linq;
|
2019-03-26 04:16:46 +00:00
|
|
|
using osu.Framework.Allocation;
|
2019-09-02 03:54:59 +00:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2019-03-18 10:44:14 +00:00
|
|
|
using osu.Framework.Testing;
|
2019-04-12 05:53:23 +00:00
|
|
|
using osu.Game.Configuration;
|
2019-03-18 07:39:34 +00:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2019-05-14 19:37:25 +00:00
|
|
|
public abstract class PlayerTestScene : RateAdjustedBeatmapTestScene
|
2019-03-18 07:39:34 +00:00
|
|
|
{
|
2020-03-02 03:20:25 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Whether custom test steps are provided. Custom tests should invoke <see cref="CreateTest"/> to create the test steps.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual bool HasCustomSteps { get; } = false;
|
|
|
|
|
2019-03-18 07:39:34 +00:00
|
|
|
private readonly Ruleset ruleset;
|
|
|
|
|
|
|
|
protected Player Player;
|
|
|
|
|
2019-05-14 19:37:25 +00:00
|
|
|
protected PlayerTestScene(Ruleset ruleset)
|
2019-03-18 07:39:34 +00:00
|
|
|
{
|
|
|
|
this.ruleset = ruleset;
|
2019-03-26 04:16:46 +00:00
|
|
|
}
|
2019-03-18 07:39:34 +00:00
|
|
|
|
2019-08-28 10:57:17 +00:00
|
|
|
protected OsuConfigManager LocalConfig;
|
|
|
|
|
2019-03-26 04:16:46 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2019-08-28 10:57:17 +00:00
|
|
|
Dependencies.Cache(LocalConfig = new OsuConfigManager(LocalStorage));
|
|
|
|
LocalConfig.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
|
2019-03-18 10:44:14 +00:00
|
|
|
}
|
2019-03-18 07:39:34 +00:00
|
|
|
|
2019-03-18 10:44:14 +00:00
|
|
|
[SetUpSteps]
|
2020-01-31 04:54:26 +00:00
|
|
|
public override void SetUpSteps()
|
2019-03-18 10:44:14 +00:00
|
|
|
{
|
2020-01-31 04:54:26 +00:00
|
|
|
base.SetUpSteps();
|
|
|
|
|
2020-03-02 03:20:25 +00:00
|
|
|
if (!HasCustomSteps)
|
|
|
|
CreateTest(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void CreateTest(Action action)
|
|
|
|
{
|
|
|
|
if (action != null && !HasCustomSteps)
|
|
|
|
throw new InvalidOperationException($"Cannot add custom test steps without {nameof(HasCustomSteps)} being set.");
|
|
|
|
|
|
|
|
action?.Invoke();
|
|
|
|
|
2020-03-01 05:16:28 +00:00
|
|
|
AddStep(ruleset.RulesetInfo.Name, LoadPlayer);
|
2019-04-25 08:36:17 +00:00
|
|
|
AddUntilStep("player loaded", () => Player.IsLoaded && Player.Alpha == 1);
|
2019-03-18 07:39:34 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 10:43:55 +00:00
|
|
|
protected virtual bool AllowFail => false;
|
|
|
|
|
2019-09-02 03:54:59 +00:00
|
|
|
protected virtual bool Autoplay => false;
|
|
|
|
|
2020-03-01 05:16:28 +00:00
|
|
|
protected void LoadPlayer()
|
2019-03-18 07:39:34 +00:00
|
|
|
{
|
2019-05-31 05:40:53 +00:00
|
|
|
var beatmap = CreateBeatmap(ruleset.RulesetInfo);
|
2019-03-18 07:39:34 +00:00
|
|
|
|
2019-05-31 05:40:53 +00:00
|
|
|
Beatmap.Value = CreateWorkingBeatmap(beatmap);
|
2019-03-18 10:43:55 +00:00
|
|
|
|
|
|
|
if (!AllowFail)
|
2019-09-04 11:28:04 +00:00
|
|
|
{
|
|
|
|
var noFailMod = ruleset.GetAllMods().FirstOrDefault(m => m is ModNoFail);
|
|
|
|
if (noFailMod != null)
|
2019-12-13 12:45:38 +00:00
|
|
|
SelectedMods.Value = new[] { noFailMod };
|
2019-09-04 11:28:04 +00:00
|
|
|
}
|
2019-03-18 07:39:34 +00:00
|
|
|
|
2019-09-02 03:54:59 +00:00
|
|
|
if (Autoplay)
|
|
|
|
{
|
|
|
|
var mod = ruleset.GetAutoplayMod();
|
|
|
|
if (mod != null)
|
2019-12-13 12:45:38 +00:00
|
|
|
SelectedMods.Value = SelectedMods.Value.Concat(mod.Yield()).ToArray();
|
2019-09-02 03:54:59 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 04:24:39 +00:00
|
|
|
Player = CreatePlayer(ruleset);
|
|
|
|
LoadScreen(Player);
|
2019-09-02 03:54:59 +00:00
|
|
|
}
|
2019-09-02 04:24:39 +00:00
|
|
|
|
|
|
|
protected virtual Player CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false);
|
2019-03-18 07:39:34 +00:00
|
|
|
}
|
|
|
|
}
|