2019-05-10 17:10:07 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-03-18 15:39:34 +08:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-03-02 11:20:25 +08:00
|
|
|
using System;
|
2019-03-18 15:39:34 +08:00
|
|
|
using System.Linq;
|
2020-04-23 18:25:06 +08:00
|
|
|
using JetBrains.Annotations;
|
2019-03-26 12:16:46 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-09-02 11:54:59 +08:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2019-03-18 18:44:14 +08:00
|
|
|
using osu.Framework.Testing;
|
2019-04-12 13:53:23 +08:00
|
|
|
using osu.Game.Configuration;
|
2019-03-18 15:39:34 +08:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2019-05-15 03:37:25 +08:00
|
|
|
public abstract class PlayerTestScene : RateAdjustedBeatmapTestScene
|
2019-03-18 15:39:34 +08:00
|
|
|
{
|
2020-03-02 11:20:25 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether custom test steps are provided. Custom tests should invoke <see cref="CreateTest"/> to create the test steps.
|
|
|
|
/// </summary>
|
2020-11-02 01:47:40 +08:00
|
|
|
protected virtual bool HasCustomSteps => false;
|
2020-03-02 11:20:25 +08:00
|
|
|
|
2020-03-05 10:25:07 +08:00
|
|
|
protected TestPlayer Player;
|
2019-03-18 15:39:34 +08:00
|
|
|
|
2019-08-28 18:57:17 +08:00
|
|
|
protected OsuConfigManager LocalConfig;
|
|
|
|
|
2019-03-26 12:16:46 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2019-08-28 18:57:17 +08:00
|
|
|
Dependencies.Cache(LocalConfig = new OsuConfigManager(LocalStorage));
|
|
|
|
LocalConfig.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
|
2019-03-18 18:44:14 +08:00
|
|
|
}
|
2019-03-18 15:39:34 +08:00
|
|
|
|
2019-03-18 18:44:14 +08:00
|
|
|
[SetUpSteps]
|
2020-01-31 12:54:26 +08:00
|
|
|
public override void SetUpSteps()
|
2019-03-18 18:44:14 +08:00
|
|
|
{
|
2020-01-31 12:54:26 +08:00
|
|
|
base.SetUpSteps();
|
|
|
|
|
2020-03-02 11:20:25 +08: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-06-10 23:23:31 +08:00
|
|
|
AddStep(CreatePlayerRuleset().Description, LoadPlayer);
|
2019-04-25 16:36:17 +08:00
|
|
|
AddUntilStep("player loaded", () => Player.IsLoaded && Player.Alpha == 1);
|
2019-03-18 15:39:34 +08:00
|
|
|
}
|
|
|
|
|
2019-03-18 18:43:55 +08:00
|
|
|
protected virtual bool AllowFail => false;
|
|
|
|
|
2019-09-02 11:54:59 +08:00
|
|
|
protected virtual bool Autoplay => false;
|
|
|
|
|
2020-03-01 13:16:28 +08:00
|
|
|
protected void LoadPlayer()
|
2019-03-18 15:39:34 +08:00
|
|
|
{
|
2021-07-11 08:46:19 +08:00
|
|
|
var ruleset = CreatePlayerRuleset();
|
|
|
|
Ruleset.Value = ruleset.RulesetInfo;
|
|
|
|
|
2020-04-23 18:25:06 +08:00
|
|
|
var beatmap = CreateBeatmap(ruleset.RulesetInfo);
|
2019-03-18 15:39:34 +08:00
|
|
|
|
2019-05-31 13:40:53 +08:00
|
|
|
Beatmap.Value = CreateWorkingBeatmap(beatmap);
|
2020-03-04 09:12:01 +08:00
|
|
|
SelectedMods.Value = Array.Empty<Mod>();
|
|
|
|
|
2019-03-18 18:43:55 +08:00
|
|
|
if (!AllowFail)
|
2019-09-04 19:28:04 +08:00
|
|
|
{
|
2021-09-10 10:09:13 +08:00
|
|
|
var noFailMod = ruleset.CreateMod<ModNoFail>();
|
2019-09-04 19:28:04 +08:00
|
|
|
if (noFailMod != null)
|
2019-12-13 20:45:38 +08:00
|
|
|
SelectedMods.Value = new[] { noFailMod };
|
2019-09-04 19:28:04 +08:00
|
|
|
}
|
2019-03-18 15:39:34 +08:00
|
|
|
|
2019-09-02 11:54:59 +08:00
|
|
|
if (Autoplay)
|
|
|
|
{
|
2020-04-23 18:25:06 +08:00
|
|
|
var mod = ruleset.GetAutoplayMod();
|
2019-09-02 11:54:59 +08:00
|
|
|
if (mod != null)
|
2019-12-13 20:45:38 +08:00
|
|
|
SelectedMods.Value = SelectedMods.Value.Concat(mod.Yield()).ToArray();
|
2019-09-02 11:54:59 +08:00
|
|
|
}
|
|
|
|
|
2020-04-23 18:25:06 +08:00
|
|
|
Player = CreatePlayer(ruleset);
|
2019-09-02 12:24:39 +08:00
|
|
|
LoadScreen(Player);
|
2019-09-02 11:54:59 +08:00
|
|
|
}
|
2019-09-02 12:24:39 +08:00
|
|
|
|
2020-09-15 13:43:24 +08:00
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
LocalConfig?.Dispose();
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
}
|
|
|
|
|
2020-06-04 04:43:18 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates the ruleset for setting up the <see cref="Player"/> component.
|
|
|
|
/// </summary>
|
|
|
|
[NotNull]
|
|
|
|
protected abstract Ruleset CreatePlayerRuleset();
|
|
|
|
|
|
|
|
protected sealed override Ruleset CreateRuleset() => CreatePlayerRuleset();
|
|
|
|
|
2020-03-05 10:25:07 +08:00
|
|
|
protected virtual TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false);
|
2019-03-18 15:39:34 +08:00
|
|
|
}
|
|
|
|
}
|