osu/osu.Game/Tests/Visual/ModSandboxTestScene.cs

65 lines
1.9 KiB
C#
Raw Normal View History

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;
using System.Linq;
using osu.Game.Beatmaps;
2020-03-01 05:16:28 +00:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual
{
2020-03-02 01:06:49 +00:00
public abstract class ModSandboxTestScene : PlayerTestScene
2020-03-01 05:16:28 +00:00
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
2020-03-02 01:06:49 +00:00
typeof(ModSandboxTestScene)
2020-03-01 05:16:28 +00:00
};
protected ModSandboxTestScene(Ruleset ruleset)
2020-03-01 05:16:28 +00:00
: base(ruleset)
{
}
private ModTestCaseData currentTest;
2020-03-01 05:16:28 +00:00
public override void SetUpSteps()
{
foreach (var testCase in CreateTestCases())
{
AddStep("set test case", () => currentTest = testCase);
base.SetUpSteps();
}
2020-03-01 05:16:28 +00:00
}
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTest.Beatmap;
2020-03-01 05:16:28 +00:00
protected override Player CreatePlayer(Ruleset ruleset)
{
SelectedMods.Value = SelectedMods.Value.Append(currentTest.Mod).ToArray();
if (currentTest.Autoplay)
{
// We're simulating an auto-play via a replay so that the auto-play mod does not interfere
var beatmap = Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, SelectedMods.Value);
var score = ruleset.GetAutoplayMod().CreateReplayScore(beatmap);
return new TestReplayPlayer(score, false, false);
}
2020-03-01 05:16:28 +00:00
return base.CreatePlayer(ruleset);
}
protected abstract ModTestCaseData[] CreateTestCases();
2020-03-01 05:16:28 +00:00
protected class ModTestCaseData
{
public Mod Mod;
public bool Autoplay;
public IBeatmap Beatmap;
2020-03-01 05:16:28 +00:00
}
}
}