2020-03-01 13:16:28 +08:00
|
|
|
|
// 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
|
|
|
|
|
|
2020-03-01 13:16:28 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-03-02 09:50:41 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2020-03-02 09:28:39 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2022-01-29 22:31:24 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using osu.Game.Replays;
|
2020-03-01 13:16:28 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2022-01-29 22:31:24 +08:00
|
|
|
|
using osu.Game.Rulesets.Replays;
|
|
|
|
|
using osu.Game.Scoring;
|
2020-03-01 13:16:28 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public abstract partial class ModTestScene : PlayerTestScene
|
2020-03-01 13:16:28 +08:00
|
|
|
|
{
|
2020-03-02 11:20:25 +08:00
|
|
|
|
protected sealed override bool HasCustomSteps => true;
|
|
|
|
|
|
2023-12-22 12:38:52 +08:00
|
|
|
|
protected ModTestData CurrentTestData { get; private set; }
|
2020-03-02 09:28:39 +08:00
|
|
|
|
|
2020-03-05 09:19:42 +08:00
|
|
|
|
protected void CreateModTest(ModTestData testData) => CreateTest(() =>
|
2020-03-01 13:16:28 +08:00
|
|
|
|
{
|
2023-12-22 12:38:52 +08:00
|
|
|
|
AddStep("set test data", () => CurrentTestData = testData);
|
2020-03-02 11:20:25 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
public override void TearDownSteps()
|
|
|
|
|
{
|
2020-03-03 11:58:07 +08:00
|
|
|
|
AddUntilStep("test passed", () =>
|
|
|
|
|
{
|
2023-12-22 12:38:52 +08:00
|
|
|
|
if (CurrentTestData == null)
|
2020-03-03 11:58:07 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
2023-12-22 12:38:52 +08:00
|
|
|
|
return CurrentTestData.PassCondition?.Invoke() ?? false;
|
2020-03-03 11:58:07 +08:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-02 11:20:25 +08:00
|
|
|
|
base.TearDownSteps();
|
2020-03-01 13:16:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-22 12:38:52 +08:00
|
|
|
|
protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => CurrentTestData?.Beatmap ?? base.CreateBeatmap(ruleset);
|
2020-03-01 13:16:28 +08:00
|
|
|
|
|
2020-03-08 21:18:45 +08:00
|
|
|
|
protected sealed override TestPlayer CreatePlayer(Ruleset ruleset)
|
2020-03-01 13:16:28 +08:00
|
|
|
|
{
|
2020-03-05 10:33:30 +08:00
|
|
|
|
var mods = new List<Mod>(SelectedMods.Value);
|
2020-03-02 09:28:39 +08:00
|
|
|
|
|
2023-12-22 12:38:52 +08:00
|
|
|
|
if (CurrentTestData.Mods != null)
|
|
|
|
|
mods.AddRange(CurrentTestData.Mods);
|
|
|
|
|
if (CurrentTestData.Autoplay)
|
2020-03-05 10:33:30 +08:00
|
|
|
|
mods.Add(ruleset.GetAutoplayMod());
|
2020-03-01 13:16:28 +08:00
|
|
|
|
|
2020-03-05 10:33:30 +08:00
|
|
|
|
SelectedMods.Value = mods;
|
2020-03-01 13:16:28 +08:00
|
|
|
|
|
2020-03-08 21:18:45 +08:00
|
|
|
|
return CreateModPlayer(ruleset);
|
2020-03-05 10:33:30 +08:00
|
|
|
|
}
|
2020-03-02 09:50:41 +08:00
|
|
|
|
|
2023-12-22 12:38:52 +08:00
|
|
|
|
protected virtual TestPlayer CreateModPlayer(Ruleset ruleset) => new ModTestPlayer(CurrentTestData, AllowFail);
|
2020-03-08 21:18:45 +08:00
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
protected partial class ModTestPlayer : TestPlayer
|
2020-03-02 09:50:41 +08:00
|
|
|
|
{
|
2020-05-12 19:08:35 +08:00
|
|
|
|
private readonly bool allowFail;
|
2022-01-29 22:54:17 +08:00
|
|
|
|
private readonly ModTestData currentTestData;
|
2020-05-12 19:08:35 +08:00
|
|
|
|
|
|
|
|
|
protected override bool CheckModsAllowFailure() => allowFail;
|
2020-03-04 09:12:01 +08:00
|
|
|
|
|
2022-01-29 22:31:24 +08:00
|
|
|
|
public ModTestPlayer(ModTestData data, bool allowFail)
|
2023-02-14 14:07:45 +08:00
|
|
|
|
: base(true, false)
|
2020-03-02 09:50:41 +08:00
|
|
|
|
{
|
2020-05-12 19:08:35 +08:00
|
|
|
|
this.allowFail = allowFail;
|
2022-01-29 22:31:24 +08:00
|
|
|
|
currentTestData = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PrepareReplay()
|
|
|
|
|
{
|
2022-01-29 23:19:51 +08:00
|
|
|
|
if (currentTestData.Autoplay && currentTestData.ReplayFrames?.Count > 0)
|
|
|
|
|
throw new InvalidOperationException(@$"{nameof(ModTestData.Autoplay)} must be false when {nameof(ModTestData.ReplayFrames)} is specified.");
|
2022-01-29 22:31:24 +08:00
|
|
|
|
|
2022-01-29 23:19:51 +08:00
|
|
|
|
if (currentTestData.ReplayFrames != null)
|
2022-01-29 22:31:24 +08:00
|
|
|
|
{
|
|
|
|
|
DrawableRuleset?.SetReplayScore(new Score
|
|
|
|
|
{
|
2022-01-29 23:19:51 +08:00
|
|
|
|
Replay = new Replay { Frames = currentTestData.ReplayFrames },
|
2022-01-29 22:31:24 +08:00
|
|
|
|
ScoreInfo = new ScoreInfo { User = new APIUser { Username = @"Test" } },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.PrepareReplay();
|
2020-03-02 09:50:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-05 09:19:42 +08:00
|
|
|
|
protected class ModTestData
|
2020-03-02 09:28:39 +08:00
|
|
|
|
{
|
2020-03-02 09:50:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether to use a replay to simulate an auto-play. True by default.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Autoplay = true;
|
|
|
|
|
|
2022-01-29 22:31:24 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The frames to use for replay. <see cref="Autoplay"/> must be set to false.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[CanBeNull]
|
2022-01-29 23:19:51 +08:00
|
|
|
|
public List<ReplayFrame> ReplayFrames;
|
2022-01-29 22:31:24 +08:00
|
|
|
|
|
2020-03-02 09:50:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The beatmap for this test case.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[CanBeNull]
|
2020-03-02 09:28:39 +08:00
|
|
|
|
public IBeatmap Beatmap;
|
2020-03-02 09:50:41 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The conditions that cause this test case to pass.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[CanBeNull]
|
|
|
|
|
public Func<bool> PassCondition;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-08-12 03:55:20 +08:00
|
|
|
|
/// The <see cref="Mod"/>s this test case tests.
|
2020-03-02 09:50:41 +08:00
|
|
|
|
/// </summary>
|
2020-08-12 03:55:20 +08:00
|
|
|
|
public IReadOnlyList<Mod> Mods;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convenience property for setting <see cref="Mods"/> if only
|
|
|
|
|
/// a single mod is to be tested.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Mod Mod
|
|
|
|
|
{
|
|
|
|
|
set => Mods = new[] { value };
|
|
|
|
|
}
|
2020-03-01 13:16:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|