1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 01:42:54 +08:00
osu-lazer/osu.Game/Tests/Visual/ModTestScene.cs

94 lines
2.7 KiB
C#
Raw Normal View History

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.
using System;
using System.Collections.Generic;
2020-03-02 09:50:41 +08:00
using JetBrains.Annotations;
using osu.Game.Beatmaps;
2020-03-01 13:16:28 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
namespace osu.Game.Tests.Visual
{
public abstract class ModTestScene : PlayerTestScene
2020-03-01 13:16:28 +08:00
{
protected sealed override bool HasCustomSteps => true;
private ModTestData currentTestData;
2020-03-05 09:19:42 +08:00
protected void CreateModTest(ModTestData testData) => CreateTest(() =>
2020-03-01 13:16:28 +08:00
{
AddStep("set test data", () => currentTestData = testData);
});
public override void TearDownSteps()
{
2020-03-03 11:58:07 +08:00
AddUntilStep("test passed", () =>
{
if (currentTestData == null)
2020-03-03 11:58:07 +08:00
return true;
return currentTestData.PassCondition?.Invoke() ?? false;
2020-03-03 11:58:07 +08:00
});
base.TearDownSteps();
2020-03-01 13:16:28 +08:00
}
protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTestData?.Beatmap ?? base.CreateBeatmap(ruleset);
2020-03-01 13:16:28 +08:00
protected sealed override TestPlayer CreatePlayer(Ruleset ruleset)
2020-03-01 13:16:28 +08:00
{
var mods = new List<Mod>(SelectedMods.Value);
if (currentTestData.Mod != null)
mods.Add(currentTestData.Mod);
if (currentTestData.Autoplay)
mods.Add(ruleset.GetAutoplayMod());
2020-03-01 13:16:28 +08:00
SelectedMods.Value = mods;
2020-03-01 13:16:28 +08:00
return CreateModPlayer(ruleset);
}
2020-03-02 09:50:41 +08:00
protected virtual TestPlayer CreateModPlayer(Ruleset ruleset) => new ModTestPlayer(AllowFail);
protected class ModTestPlayer : TestPlayer
2020-03-02 09:50:41 +08:00
{
private readonly bool allowFail;
protected override bool CheckModsAllowFailure() => allowFail;
public ModTestPlayer(bool allowFail)
: base(false, false)
2020-03-02 09:50:41 +08:00
{
this.allowFail = allowFail;
2020-03-02 09:50:41 +08:00
}
}
2020-03-05 09:19:42 +08:00
protected class ModTestData
{
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;
/// <summary>
/// The beatmap for this test case.
/// </summary>
[CanBeNull]
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>
/// The <see cref="Mod"/> this test case tests.
/// </summary>
public Mod Mod;
2020-03-01 13:16:28 +08:00
}
}
}