1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:07:38 +08:00
osu-lazer/osu.Game/Tests/Visual/ModPerfectTestScene.cs

69 lines
2.2 KiB
C#
Raw Normal View History

2020-03-02 11:42:48 +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 osu.Framework.Extensions.TypeExtensions;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Scoring;
namespace osu.Game.Tests.Visual
{
public abstract class ModPerfectTestScene : ModSandboxTestScene
{
2020-03-02 12:24:02 +08:00
private readonly Ruleset ruleset;
2020-03-02 11:42:48 +08:00
private readonly ModPerfect perfectMod;
protected ModPerfectTestScene(Ruleset ruleset, ModPerfect perfectMod)
: base(ruleset)
{
2020-03-02 12:24:02 +08:00
this.ruleset = ruleset;
2020-03-02 11:42:48 +08:00
this.perfectMod = perfectMod;
}
protected void CreateHitObjectTest(HitObjectTestCase testCaseData, bool shouldMiss) => CreateModTest(new ModTestCaseData(testCaseData.HitObject.GetType().ReadableName(), perfectMod)
{
Beatmap = new Beatmap
{
2020-03-02 12:24:02 +08:00
BeatmapInfo = { Ruleset = ruleset.RulesetInfo },
2020-03-02 11:42:48 +08:00
HitObjects = { testCaseData.HitObject }
},
Autoplay = !shouldMiss,
PassCondition = () => ((PerfectModTestPlayer)Player).CheckFailed(shouldMiss && testCaseData.FailOnMiss)
});
protected sealed override TestPlayer CreateReplayPlayer(Score score) => new PerfectModTestPlayer(score);
private class PerfectModTestPlayer : TestPlayer
{
public PerfectModTestPlayer(Score score)
: base(score)
{
}
protected override bool AllowFail => true;
public bool CheckFailed(bool failed)
{
if (!failed)
return ScoreProcessor.HasCompleted && !HealthProcessor.HasFailed;
return ScoreProcessor.JudgedHits > 0 && HealthProcessor.HasFailed;
}
}
protected class HitObjectTestCase
{
public readonly HitObject HitObject;
public readonly bool FailOnMiss;
public HitObjectTestCase(HitObject hitObject, bool failOnMiss = true)
{
HitObject = hitObject;
FailOnMiss = failOnMiss;
}
}
}
}