2019-05-10 18:10:07 +09:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-03-18 16:39:34 +09:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 16:37:17 +09:00
|
|
|
#nullable disable
|
|
|
|
|
2020-03-02 12:20:25 +09:00
|
|
|
using System;
|
2019-03-18 16:39:34 +09:00
|
|
|
using System.Linq;
|
2020-04-23 13:25:06 +03:00
|
|
|
using JetBrains.Annotations;
|
2019-03-26 13:16:46 +09:00
|
|
|
using osu.Framework.Allocation;
|
2023-02-01 23:42:44 +09:00
|
|
|
using osu.Framework.Logging;
|
2019-03-18 19:44:14 +09:00
|
|
|
using osu.Framework.Testing;
|
2019-04-12 14:53:23 +09:00
|
|
|
using osu.Game.Configuration;
|
2019-03-18 16:39:34 +09:00
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2023-09-19 05:09:01 +03:00
|
|
|
using osu.Game.Screens.Play;
|
2019-03-18 16:39:34 +09:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2022-11-24 14:32:20 +09:00
|
|
|
public abstract partial class PlayerTestScene : RateAdjustedBeatmapTestScene
|
2019-03-18 16:39:34 +09:00
|
|
|
{
|
2020-03-02 12:20:25 +09:00
|
|
|
/// <summary>
|
|
|
|
/// Whether custom test steps are provided. Custom tests should invoke <see cref="CreateTest"/> to create the test steps.
|
|
|
|
/// </summary>
|
2020-11-01 18:47:40 +01:00
|
|
|
protected virtual bool HasCustomSteps => false;
|
2020-03-02 12:20:25 +09:00
|
|
|
|
2020-03-05 11:25:07 +09:00
|
|
|
protected TestPlayer Player;
|
2019-03-18 16:39:34 +09:00
|
|
|
|
2019-08-28 19:57:17 +09:00
|
|
|
protected OsuConfigManager LocalConfig;
|
|
|
|
|
2023-02-01 23:42:44 +09:00
|
|
|
private double lastReportedTime;
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
if (Player?.GameplayClockContainer != null)
|
|
|
|
{
|
|
|
|
int roundedTime = (int)Player.GameplayClockContainer.CurrentTime / 1000;
|
|
|
|
|
|
|
|
if (roundedTime != lastReportedTime)
|
|
|
|
{
|
|
|
|
lastReportedTime = roundedTime;
|
|
|
|
Logger.Log($"⏱️ Gameplay clock reached {lastReportedTime * 1000:N0} ms");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-26 13:16:46 +09:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2019-08-28 19:57:17 +09:00
|
|
|
Dependencies.Cache(LocalConfig = new OsuConfigManager(LocalStorage));
|
|
|
|
LocalConfig.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
|
2019-03-18 19:44:14 +09:00
|
|
|
}
|
2019-03-18 16:39:34 +09:00
|
|
|
|
2019-03-18 19:44:14 +09:00
|
|
|
[SetUpSteps]
|
2020-01-31 13:54:26 +09:00
|
|
|
public override void SetUpSteps()
|
2019-03-18 19:44:14 +09:00
|
|
|
{
|
2020-01-31 13:54:26 +09:00
|
|
|
base.SetUpSteps();
|
|
|
|
|
2020-03-02 12:20:25 +09:00
|
|
|
if (!HasCustomSteps)
|
2022-06-28 15:19:02 +09:00
|
|
|
CreateTest();
|
2020-03-02 12:20:25 +09:00
|
|
|
}
|
|
|
|
|
2022-06-28 15:19:02 +09:00
|
|
|
protected void CreateTest([CanBeNull] Action action = null)
|
2020-03-02 12:20:25 +09:00
|
|
|
{
|
|
|
|
if (action != null && !HasCustomSteps)
|
|
|
|
throw new InvalidOperationException($"Cannot add custom test steps without {nameof(HasCustomSteps)} being set.");
|
|
|
|
|
|
|
|
action?.Invoke();
|
|
|
|
|
2022-07-07 16:42:36 +09:00
|
|
|
AddStep($"Load player for {CreatePlayerRuleset().Description}", LoadPlayer);
|
2019-04-25 17:36:17 +09:00
|
|
|
AddUntilStep("player loaded", () => Player.IsLoaded && Player.Alpha == 1);
|
2019-03-18 16:39:34 +09:00
|
|
|
}
|
|
|
|
|
2019-03-18 19:43:55 +09:00
|
|
|
protected virtual bool AllowFail => false;
|
|
|
|
|
2019-09-02 12:54:59 +09:00
|
|
|
protected virtual bool Autoplay => false;
|
|
|
|
|
2022-09-19 11:31:38 +09:00
|
|
|
protected void LoadPlayer() => LoadPlayer(Array.Empty<Mod>());
|
|
|
|
|
|
|
|
protected void LoadPlayer(Mod[] mods)
|
2019-03-18 16:39:34 +09:00
|
|
|
{
|
2023-09-19 05:09:01 +03:00
|
|
|
// if a player screen is present already, we must exit that before loading another one,
|
|
|
|
// otherwise it'll crash on SpectatorClient.BeginPlaying being called while client is in "playing" state already.
|
|
|
|
if (Stack.CurrentScreen is Player)
|
|
|
|
Stack.Exit();
|
|
|
|
|
2021-07-11 03:46:19 +03:00
|
|
|
var ruleset = CreatePlayerRuleset();
|
|
|
|
Ruleset.Value = ruleset.RulesetInfo;
|
|
|
|
|
2020-04-23 13:25:06 +03:00
|
|
|
var beatmap = CreateBeatmap(ruleset.RulesetInfo);
|
2019-03-18 16:39:34 +09:00
|
|
|
|
2019-05-31 14:40:53 +09:00
|
|
|
Beatmap.Value = CreateWorkingBeatmap(beatmap);
|
2022-09-19 11:31:38 +09:00
|
|
|
|
|
|
|
SelectedMods.Value = mods;
|
2020-03-03 17:12:01 -08:00
|
|
|
|
2019-03-18 19:43:55 +09:00
|
|
|
if (!AllowFail)
|
2019-09-04 20:28:04 +09:00
|
|
|
{
|
2021-09-10 11:09:13 +09:00
|
|
|
var noFailMod = ruleset.CreateMod<ModNoFail>();
|
2019-09-04 20:28:04 +09:00
|
|
|
if (noFailMod != null)
|
2022-09-19 11:31:38 +09:00
|
|
|
SelectedMods.Value = SelectedMods.Value.Append(noFailMod).ToArray();
|
2019-09-04 20:28:04 +09:00
|
|
|
}
|
2019-03-18 16:39:34 +09:00
|
|
|
|
2019-09-02 12:54:59 +09:00
|
|
|
if (Autoplay)
|
|
|
|
{
|
2020-04-23 13:25:06 +03:00
|
|
|
var mod = ruleset.GetAutoplayMod();
|
2019-09-02 12:54:59 +09:00
|
|
|
if (mod != null)
|
2022-09-19 11:31:38 +09:00
|
|
|
SelectedMods.Value = SelectedMods.Value.Append(mod).ToArray();
|
2019-09-02 12:54:59 +09:00
|
|
|
}
|
|
|
|
|
2020-04-23 13:25:06 +03:00
|
|
|
Player = CreatePlayer(ruleset);
|
2019-09-02 13:24:39 +09:00
|
|
|
LoadScreen(Player);
|
2019-09-02 12:54:59 +09:00
|
|
|
}
|
2019-09-02 13:24:39 +09:00
|
|
|
|
2020-09-15 14:43:24 +09:00
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
LocalConfig?.Dispose();
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
}
|
|
|
|
|
2020-06-03 23:43:18 +03: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 11:25:07 +09:00
|
|
|
protected virtual TestPlayer CreatePlayer(Ruleset ruleset) => new TestPlayer(false, false);
|
2019-03-18 16:39:34 +09:00
|
|
|
}
|
|
|
|
}
|