// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using JetBrains.Annotations; using osu.Game.Beatmaps; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; namespace osu.Game.Tests.Visual { public abstract class ModTestScene : PlayerTestScene { protected sealed override bool HasCustomSteps => true; public override IReadOnlyList RequiredTypes => new[] { typeof(ModTestScene) }; protected ModTestScene(Ruleset ruleset) : base(ruleset) { } private ModTestData currentTestData; protected void CreateModTest(ModTestData testData) => CreateTest(() => { AddStep("set test data", () => currentTestData = testData); }); public override void TearDownSteps() { AddUntilStep("test passed", () => { if (currentTestData == null) return true; return currentTestData.PassCondition?.Invoke() ?? false; }); base.TearDownSteps(); } protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTestData?.Beatmap ?? base.CreateBeatmap(ruleset); protected sealed override TestPlayer CreatePlayer(Ruleset ruleset) { var mods = new List(SelectedMods.Value); if (currentTestData.Mod != null) mods.Add(currentTestData.Mod); if (currentTestData.Autoplay) mods.Add(ruleset.GetAutoplayMod()); SelectedMods.Value = mods; return CreateModPlayer(ruleset); } protected virtual TestPlayer CreateModPlayer(Ruleset ruleset) => new ModTestPlayer(AllowFail); protected class ModTestPlayer : TestPlayer { protected override bool AllowFail { get; } public ModTestPlayer(bool allowFail) : base(false, false) { AllowFail = allowFail; } } protected class ModTestData { /// /// Whether to use a replay to simulate an auto-play. True by default. /// public bool Autoplay = true; /// /// The beatmap for this test case. /// [CanBeNull] public IBeatmap Beatmap; /// /// The conditions that cause this test case to pass. /// [CanBeNull] public Func PassCondition; /// /// The this test case tests. /// public Mod Mod; } } }