// 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 System.Linq; using JetBrains.Annotations; using osu.Game.Beatmaps; using osu.Game.Replays; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Scoring; using osu.Game.Screens.Play; namespace osu.Game.Tests.Visual { public abstract class ModSandboxTestScene : PlayerTestScene { public override IReadOnlyList RequiredTypes => new[] { typeof(ModSandboxTestScene) }; protected ModSandboxTestScene(Ruleset ruleset) : base(ruleset) { } private ModTestCaseData currentTest; public override void SetUpSteps() { foreach (var testCase in CreateTestCases()) { AddStep(testCase.Name, () => currentTest = testCase); base.SetUpSteps(); AddUntilStep("test passed", () => testCase.PassCondition?.Invoke() ?? true); } } protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTest?.Beatmap ?? base.CreateBeatmap(ruleset); protected sealed override Player CreatePlayer(Ruleset ruleset) { SelectedMods.Value = SelectedMods.Value.Append(currentTest.Mod).ToArray(); var score = currentTest.Autoplay ? ruleset.GetAutoplayMod().CreateReplayScore(Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, SelectedMods.Value)) : new Score { Replay = new Replay() }; return CreateReplayPlayer(score); } /// /// Creates the test cases for this test scene. /// protected abstract ModTestCaseData[] CreateTestCases(); /// /// Creates the for a test case. /// /// The . protected virtual TestPlayer CreateReplayPlayer(Score score) => new TestPlayer(score); protected class TestPlayer : TestReplayPlayer { public TestPlayer(Score score) : base(score, false, false) { } } protected class ModTestCaseData { /// /// 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 name of this test case, displayed in the test browser. /// public readonly string Name; /// /// The this test case tests. /// public readonly Mod Mod; public ModTestCaseData(string name, Mod mod) { Name = name; Mod = mod; } } } }