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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

136 lines
4.2 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;
2021-10-05 15:48:54 +08:00
using System.Diagnostics;
2021-10-05 16:10:24 +08:00
using NUnit.Framework;
using osu.Framework.Bindables;
2021-10-05 15:48:54 +08:00
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Rulesets;
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.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Screens.Play.HUD;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestScenePerformancePointsCounter : OsuTestScene
{
private DependencyProvidingContainer dependencyContainer;
2021-10-05 15:48:54 +08:00
private GameplayState gameplayState;
2021-10-05 15:48:54 +08:00
private ScoreProcessor scoreProcessor;
private int iteration;
private Bindable<JudgementResult> lastJudgementResult = new Bindable<JudgementResult>();
2021-10-05 16:10:24 +08:00
private PerformancePointsCounter counter;
2021-10-05 15:48:54 +08:00
[SetUpSteps]
public void SetUpSteps() => AddStep("create components", () =>
2021-10-05 15:48:54 +08:00
{
var ruleset = CreateRuleset();
Debug.Assert(ruleset != null);
var beatmap = CreateWorkingBeatmap(ruleset.RulesetInfo)
.GetPlayableBeatmap(ruleset.RulesetInfo);
lastJudgementResult = new Bindable<JudgementResult>();
2021-10-05 15:48:54 +08:00
gameplayState = new GameplayState(beatmap, ruleset);
gameplayState.LastJudgementResult.BindTo(lastJudgementResult);
scoreProcessor = new ScoreProcessor(ruleset);
Child = dependencyContainer = new DependencyProvidingContainer
{
RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[]
{
(typeof(GameplayState), gameplayState),
(typeof(ScoreProcessor), scoreProcessor)
}
};
iteration = 0;
});
2021-10-05 15:48:54 +08:00
protected override Ruleset CreateRuleset() => new OsuRuleset();
private void createCounter() => AddStep("Create counter", () =>
2021-10-05 15:48:54 +08:00
{
dependencyContainer.Child = counter = new PerformancePointsCounter
2021-10-05 15:48:54 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(5),
};
});
2021-10-05 15:48:54 +08:00
2021-10-05 16:10:24 +08:00
[Test]
public void TestBasicCounting()
{
int previousValue = 0;
createCounter();
2021-10-05 16:10:24 +08:00
AddAssert("counter displaying zero", () => counter.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
2021-10-05 16:10:24 +08:00
AddUntilStep("counter non-zero", () => counter.Current.Value > 0);
AddUntilStep("counter opaque", () => counter.Child.Alpha == 1);
2021-10-05 15:48:54 +08:00
AddStep("Revert judgement", () =>
{
previousValue = counter.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", () => counter.Current.Value < previousValue);
2021-10-05 16:10:24 +08:00
AddStep("Add judgement", applyOneJudgement);
AddUntilStep("counter non-zero", () => counter.Current.Value > 0);
2021-10-05 16:10:24 +08:00
}
[Test]
public void TestCounterUpdatesWithJudgementsBeforeCreation()
{
AddRepeatStep("Add judgement", applyOneJudgement, 10);
createCounter();
AddUntilStep("counter non-zero", () => counter.Current.Value > 0);
AddUntilStep("counter opaque", () => counter.Child.Alpha == 1);
}
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
}
}
}