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

123 lines
4.5 KiB
C#
Raw Normal View History

2021-10-05 15:48:54 +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.
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Linq;
2021-10-05 16:10:24 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
2021-10-05 15:48:54 +08:00
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Osu.Scoring;
2021-10-05 15:48:54 +08:00
using osu.Game.Rulesets.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osu.Game.Skinning.Triangles;
using osu.Game.Tests.Gameplay;
2021-10-05 15:48:54 +08:00
namespace osu.Game.Tests.Visual.Gameplay
{
public partial class TestScenePerformancePointsCounter : SkinnableHUDComponentTestScene
2021-10-05 15:48:54 +08:00
{
[Cached(typeof(ScoreProcessor))]
private readonly ScoreProcessor scoreProcessor = new OsuScoreProcessor();
2021-10-05 15:48:54 +08:00
[Cached]
private readonly GameplayState gameplayState = TestGameplayState.Create(new OsuRuleset());
2021-10-05 15:48:54 +08:00
private int iteration;
protected override Drawable CreateDefaultImplementation() => new TrianglesPerformancePointsCounter();
protected override Drawable CreateArgonImplementation() => new ArgonPerformancePointsCounter();
protected override Drawable CreateLegacyImplementation() => Empty();
private Bindable<JudgementResult> lastJudgementResult => (Bindable<JudgementResult>)gameplayState.LastJudgementResult;
public override void SetUpSteps()
{
AddStep("reset", () =>
{
var ruleset = new OsuRuleset();
var beatmap = CreateWorkingBeatmap(ruleset.RulesetInfo)
.GetPlayableBeatmap(ruleset.RulesetInfo);
iteration = 0;
scoreProcessor.ApplyBeatmap(beatmap);
lastJudgementResult.SetDefault();
});
2021-10-05 15:48:54 +08:00
base.SetUpSteps();
}
2021-10-05 15:48:54 +08:00
[Test]
public void TestDisplay()
2021-10-05 15:48:54 +08:00
{
AddSliderStep("pp", 0, 2000, 0, v => this.ChildrenOfType<PerformancePointsCounter>().ForEach(c => c.Current.Value = v));
AddToggleStep("toggle validity", v => this.ChildrenOfType<PerformancePointsCounter>().ForEach(c => c.IsValid = v));
}
2021-10-05 15:48:54 +08:00
2021-10-05 16:10:24 +08:00
[Test]
public void TestBasicCounting()
{
int previousValue = 0;
AddAssert("counter displaying zero", () => this.ChildrenOfType<PerformancePointsCounter>().All(c => c.Current.Value == 0));
2021-10-05 15:48:54 +08:00
2021-10-05 16:10:24 +08:00
AddRepeatStep("Add judgement", applyOneJudgement, 10);
2021-10-05 15:48:54 +08:00
AddUntilStep("counter non-zero", () => this.ChildrenOfType<PerformancePointsCounter>().All(c => c.Current.Value > 0));
AddUntilStep("counter valid", () => this.ChildrenOfType<PerformancePointsCounter>().All(c => c.IsValid));
2021-10-05 15:48:54 +08:00
AddStep("Revert judgement", () =>
{
previousValue = this.ChildrenOfType<PerformancePointsCounter>().First().Current.Value;
2021-10-05 15:48:54 +08:00
scoreProcessor.RevertResult(new JudgementResult(new HitObject(), new OsuJudgement()));
});
2021-10-05 16:10:24 +08:00
AddUntilStep("counter decreased", () => this.ChildrenOfType<PerformancePointsCounter>().All(c => c.Current.Value < previousValue));
2021-10-05 16:10:24 +08:00
AddStep("Add judgement", applyOneJudgement);
AddUntilStep("counter non-zero", () => this.ChildrenOfType<PerformancePointsCounter>().All(c => c.Current.Value > 0));
2021-10-05 16:10:24 +08:00
}
[Test]
public void TestCounterUpdatesWithJudgementsBeforeCreation()
{
AddRepeatStep("Add judgement", applyOneJudgement, 10);
AddStep("recreate counter", SetUpComponents);
AddUntilStep("counter non-zero", () => this.ChildrenOfType<PerformancePointsCounter>().All(c => c.Current.Value > 0));
AddUntilStep("counter valid", () => this.ChildrenOfType<PerformancePointsCounter>().All(c => c.IsValid));
}
2021-10-05 16:10:24 +08:00
private void applyOneJudgement()
{
var scoreInfo = gameplayState.Score.ScoreInfo;
scoreInfo.MaxCombo = iteration * 1000;
scoreInfo.Accuracy = 1;
scoreInfo.Statistics[HitResult.Great] = iteration * 1000;
lastJudgementResult.Value = new OsuJudgementResult(new HitObject
2021-10-05 16:10:24 +08:00
{
StartTime = iteration * 10000,
}, new OsuJudgement())
{
Type = HitResult.Perfect,
};
scoreProcessor.ApplyResult(lastJudgementResult.Value);
2021-10-05 16:10:24 +08:00
iteration++;
2021-10-05 15:48:54 +08:00
}
}
}