2020-03-01 05:16:28 +00: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.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-03-02 01:50:41 +00:00
|
|
|
|
using JetBrains.Annotations;
|
2020-03-02 01:28:39 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-03-01 05:16:28 +00:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
2020-03-05 01:11:27 +00:00
|
|
|
|
public abstract class ModTestScene : PlayerTestScene
|
2020-03-01 05:16:28 +00:00
|
|
|
|
{
|
2020-03-02 03:20:25 +00:00
|
|
|
|
protected sealed override bool HasCustomSteps => true;
|
|
|
|
|
|
2020-03-05 02:33:30 +00:00
|
|
|
|
private ModTestData currentTestData;
|
2020-03-02 01:28:39 +00:00
|
|
|
|
|
2020-03-05 01:19:42 +00:00
|
|
|
|
protected void CreateModTest(ModTestData testData) => CreateTest(() =>
|
2020-03-01 05:16:28 +00:00
|
|
|
|
{
|
2020-03-05 02:33:30 +00:00
|
|
|
|
AddStep("set test data", () => currentTestData = testData);
|
2020-03-02 03:20:25 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
public override void TearDownSteps()
|
|
|
|
|
{
|
2020-03-03 03:58:07 +00:00
|
|
|
|
AddUntilStep("test passed", () =>
|
|
|
|
|
{
|
2020-03-05 02:33:30 +00:00
|
|
|
|
if (currentTestData == null)
|
2020-03-03 03:58:07 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
2020-03-05 02:33:30 +00:00
|
|
|
|
return currentTestData.PassCondition?.Invoke() ?? false;
|
2020-03-03 03:58:07 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-02 03:20:25 +00:00
|
|
|
|
base.TearDownSteps();
|
2020-03-01 05:16:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-05 02:33:30 +00:00
|
|
|
|
protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTestData?.Beatmap ?? base.CreateBeatmap(ruleset);
|
2020-03-01 05:16:28 +00:00
|
|
|
|
|
2020-03-08 13:18:45 +00:00
|
|
|
|
protected sealed override TestPlayer CreatePlayer(Ruleset ruleset)
|
2020-03-01 05:16:28 +00:00
|
|
|
|
{
|
2020-03-05 02:33:30 +00:00
|
|
|
|
var mods = new List<Mod>(SelectedMods.Value);
|
2020-03-02 01:28:39 +00:00
|
|
|
|
|
2020-08-11 19:55:20 +00:00
|
|
|
|
if (currentTestData.Mods != null)
|
|
|
|
|
mods.AddRange(currentTestData.Mods);
|
2020-03-05 02:33:30 +00:00
|
|
|
|
if (currentTestData.Autoplay)
|
|
|
|
|
mods.Add(ruleset.GetAutoplayMod());
|
2020-03-01 05:16:28 +00:00
|
|
|
|
|
2020-03-05 02:33:30 +00:00
|
|
|
|
SelectedMods.Value = mods;
|
2020-03-01 05:16:28 +00:00
|
|
|
|
|
2020-03-08 13:18:45 +00:00
|
|
|
|
return CreateModPlayer(ruleset);
|
2020-03-05 02:33:30 +00:00
|
|
|
|
}
|
2020-03-02 01:50:41 +00:00
|
|
|
|
|
2020-03-08 13:18:45 +00:00
|
|
|
|
protected virtual TestPlayer CreateModPlayer(Ruleset ruleset) => new ModTestPlayer(AllowFail);
|
|
|
|
|
|
2020-03-05 02:33:30 +00:00
|
|
|
|
protected class ModTestPlayer : TestPlayer
|
2020-03-02 01:50:41 +00:00
|
|
|
|
{
|
2020-05-12 11:08:35 +00:00
|
|
|
|
private readonly bool allowFail;
|
|
|
|
|
|
|
|
|
|
protected override bool CheckModsAllowFailure() => allowFail;
|
2020-03-04 01:12:01 +00:00
|
|
|
|
|
2020-03-05 02:33:30 +00:00
|
|
|
|
public ModTestPlayer(bool allowFail)
|
|
|
|
|
: base(false, false)
|
2020-03-02 01:50:41 +00:00
|
|
|
|
{
|
2020-05-12 11:08:35 +00:00
|
|
|
|
this.allowFail = allowFail;
|
2020-03-02 01:50:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-05 01:19:42 +00:00
|
|
|
|
protected class ModTestData
|
2020-03-02 01:28:39 +00:00
|
|
|
|
{
|
2020-03-02 01:50:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether to use a replay to simulate an auto-play. True by default.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool Autoplay = true;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The beatmap for this test case.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[CanBeNull]
|
2020-03-02 01:28:39 +00:00
|
|
|
|
public IBeatmap Beatmap;
|
2020-03-02 01:50:41 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The conditions that cause this test case to pass.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[CanBeNull]
|
|
|
|
|
public Func<bool> PassCondition;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-08-11 19:55:20 +00:00
|
|
|
|
/// The <see cref="Mod"/>s this test case tests.
|
2020-03-02 01:50:41 +00:00
|
|
|
|
/// </summary>
|
2020-08-11 19:55:20 +00: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 05:16:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|