osu/osu.Game.Tests/Visual/Gameplay/TestSceneHitErrorMeter.cs

280 lines
11 KiB
C#
Raw Normal View History

2019-08-19 18:10:12 +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.
2021-05-18 06:12:29 +00:00
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
2019-08-19 18:10:12 +00:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
2019-08-19 18:25:14 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Threading;
using osu.Framework.Utils;
2019-11-25 02:30:55 +00:00
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Judgements;
2019-09-06 06:24:00 +00:00
using osu.Game.Rulesets.Mania.Scoring;
2021-05-18 06:12:29 +00:00
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects;
2019-09-06 06:24:00 +00:00
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.Taiko.Scoring;
2021-05-18 06:12:29 +00:00
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
2019-08-30 09:46:42 +00:00
using osu.Game.Screens.Play.HUD.HitErrorMeters;
2019-08-19 18:10:12 +00:00
namespace osu.Game.Tests.Visual.Gameplay
{
2019-12-21 11:30:49 +00:00
public class TestSceneHitErrorMeter : OsuTestScene
2019-08-19 18:10:12 +00:00
{
[Cached(typeof(ScoreProcessor))]
private TestScoreProcessor scoreProcessor = new TestScoreProcessor();
2021-05-18 06:12:29 +00:00
[Cached(typeof(DrawableRuleset))]
private TestDrawableRuleset drawableRuleset = new TestDrawableRuleset();
[SetUpSteps]
public void SetUp()
2019-08-19 18:10:12 +00:00
{
AddStep("reset score processor", () => scoreProcessor.Reset());
}
[Test]
public void TestBasic()
{
AddStep("create display", () => recreateDisplay(new OsuHitWindows(), 5));
2019-08-30 07:40:24 +00:00
AddRepeatStep("New random judgement", () => newJudgement(), 40);
2021-05-18 06:12:29 +00:00
AddRepeatStep("New max negative", () => newJudgement(-drawableRuleset.HitWindows.WindowFor(HitResult.Meh)), 20);
AddRepeatStep("New max positive", () => newJudgement(drawableRuleset.HitWindows.WindowFor(HitResult.Meh)), 20);
2019-08-19 18:10:12 +00:00
AddStep("New fixed judgement (50ms)", () => newJudgement(50));
ScheduledDelegate del = null;
AddStep("Judgement barrage", () =>
{
int runCount = 0;
del = Scheduler.AddDelayed(() =>
{
newJudgement(runCount++ / 10f);
if (runCount == 500)
// ReSharper disable once AccessToModifiedClosure
del?.Cancel();
}, 10, true);
});
AddUntilStep("wait for barrage", () => del.Cancelled);
2019-08-19 18:10:12 +00:00
}
[Test]
public void TestOsu()
{
AddStep("OD 1", () => recreateDisplay(new OsuHitWindows(), 1));
AddStep("OD 10", () => recreateDisplay(new OsuHitWindows(), 10));
}
[Test]
public void TestTaiko()
{
AddStep("OD 1", () => recreateDisplay(new TaikoHitWindows(), 1));
AddStep("OD 10", () => recreateDisplay(new TaikoHitWindows(), 10));
}
[Test]
public void TestMania()
{
AddStep("OD 1", () => recreateDisplay(new ManiaHitWindows(), 1));
AddStep("OD 10", () => recreateDisplay(new ManiaHitWindows(), 10));
}
[Test]
public void TestEmpty()
2019-08-19 18:10:12 +00:00
{
AddStep("empty windows", () => recreateDisplay(HitWindows.Empty, 5));
AddStep("hit", () => newJudgement());
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("circle added", () =>
this.ChildrenOfType<ColourHitErrorMeter>().All(
meter => meter.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Count() == 1));
AddStep("miss", () => newJudgement(50, HitResult.Miss));
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("circle added", () =>
this.ChildrenOfType<ColourHitErrorMeter>().All(
meter => meter.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Count() == 2));
2019-08-19 18:10:12 +00:00
}
[Test]
public void TestBonus()
{
AddStep("OD 1", () => recreateDisplay(new OsuHitWindows(), 1));
AddStep("small bonus", () => newJudgement(result: HitResult.SmallBonus));
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Any());
AddStep("large bonus", () => newJudgement(result: HitResult.LargeBonus));
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Any());
}
[Test]
public void TestIgnore()
{
AddStep("OD 1", () => recreateDisplay(new OsuHitWindows(), 1));
AddStep("ignore hit", () => newJudgement(result: HitResult.IgnoreHit));
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Any());
AddStep("ignore miss", () => newJudgement(result: HitResult.IgnoreMiss));
AddAssert("no bars added", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("no circle added", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Any());
}
[Test]
public void TestClear()
{
AddStep("OD 1", () => recreateDisplay(new OsuHitWindows(), 1));
AddStep("hit", () => newJudgement(0.2D));
AddAssert("bar added", () => this.ChildrenOfType<BarHitErrorMeter>().All(
meter => meter.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Count() == 1));
AddAssert("circle added", () => this.ChildrenOfType<ColourHitErrorMeter>().All(
meter => meter.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Count() == 1));
AddStep("clear", () => this.ChildrenOfType<HitErrorMeter>().ForEach(meter => meter.Clear()));
AddAssert("bar cleared", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddAssert("colour cleared", () => !this.ChildrenOfType<ColourHitErrorMeter.HitErrorCircle>().Any());
}
2019-08-19 18:10:12 +00:00
private void recreateDisplay(HitWindows hitWindows, float overallDifficulty)
{
2019-08-30 10:47:13 +00:00
hitWindows?.SetDifficulty(overallDifficulty);
2021-05-18 06:12:29 +00:00
drawableRuleset.HitWindows = hitWindows;
2019-08-19 18:10:12 +00:00
Clear();
Add(new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both,
Children = new[]
{
2019-11-25 02:30:55 +00:00
new OsuSpriteText { Text = $@"Great: {hitWindows?.WindowFor(HitResult.Great)}" },
2020-09-29 08:16:55 +00:00
new OsuSpriteText { Text = $@"Good: {hitWindows?.WindowFor(HitResult.Ok)}" },
2019-11-25 02:30:55 +00:00
new OsuSpriteText { Text = $@"Meh: {hitWindows?.WindowFor(HitResult.Meh)}" },
}
});
2021-05-18 06:12:29 +00:00
Add(new BarHitErrorMeter
2019-08-19 18:25:14 +00:00
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
});
2021-05-18 06:12:29 +00:00
Add(new BarHitErrorMeter
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
2019-08-19 18:25:14 +00:00
});
2019-12-21 11:30:49 +00:00
2021-05-18 06:12:29 +00:00
Add(new BarHitErrorMeter
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.CentreLeft,
Rotation = 270,
});
2021-05-18 06:12:29 +00:00
Add(new ColourHitErrorMeter
2019-12-21 11:30:49 +00:00
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding { Right = 50 }
});
2021-05-18 06:12:29 +00:00
Add(new ColourHitErrorMeter
2019-12-21 11:30:49 +00:00
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Left = 50 }
});
2021-05-18 06:12:29 +00:00
Add(new ColourHitErrorMeter
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.CentreLeft,
Rotation = 270,
Margin = new MarginPadding { Left = 50 }
});
2019-08-19 18:10:12 +00:00
}
private void newJudgement(double offset = 0, HitResult result = HitResult.Perfect)
2019-08-19 18:10:12 +00:00
{
2021-05-18 06:12:29 +00:00
scoreProcessor.ApplyResult(new JudgementResult(new HitCircle { HitWindows = drawableRuleset.HitWindows }, new Judgement())
2019-08-19 18:10:12 +00:00
{
2019-08-30 07:40:24 +00:00
TimeOffset = offset == 0 ? RNG.Next(-150, 150) : offset,
Type = result,
});
2019-08-19 18:10:12 +00:00
}
2021-05-18 06:12:29 +00:00
[SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")]
private class TestDrawableRuleset : DrawableRuleset
{
public HitWindows HitWindows;
public override IEnumerable<HitObject> Objects => new[] { new HitCircle { HitWindows = HitWindows } };
public override event Action<JudgementResult> NewResult
{
add => throw new InvalidOperationException();
remove => throw new InvalidOperationException();
}
public override event Action<JudgementResult> RevertResult
{
add => throw new InvalidOperationException();
remove => throw new InvalidOperationException();
}
2021-05-18 06:12:29 +00:00
public override Playfield Playfield { get; }
public override Container Overlays { get; }
public override Container FrameStableComponents { get; }
public override IFrameStableClock FrameStableClock { get; }
internal override bool FrameStablePlayback { get; set; }
2021-05-18 06:12:29 +00:00
public override IReadOnlyList<Mod> Mods { get; }
public override double GameplayStartTime { get; }
public override GameplayCursorContainer Cursor { get; }
public TestDrawableRuleset()
: base(new OsuRuleset())
{
}
public override void SetReplayScore(Score replayScore) => throw new NotImplementedException();
public override void SetRecordTarget(Score score) => throw new NotImplementedException();
public override void RequestResume(Action continueResume) => throw new NotImplementedException();
public override void CancelResume() => throw new NotImplementedException();
}
private class TestScoreProcessor : ScoreProcessor
{
public void Reset() => base.Reset(false);
}
2019-08-19 18:10:12 +00:00
}
}