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