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.
|
|
|
|
|
2021-11-11 15:10:33 +00:00
|
|
|
using System;
|
2021-10-05 07:48:54 +00:00
|
|
|
using System.Diagnostics;
|
2021-10-05 08:10:24 +00:00
|
|
|
using NUnit.Framework;
|
2021-11-11 15:10:33 +00:00
|
|
|
using osu.Framework.Bindables;
|
2021-10-05 07:48:54 +00: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
|
|
|
|
{
|
2021-11-11 15:10:33 +00:00
|
|
|
private DependencyProvidingContainer dependencyContainer;
|
2021-10-05 07:48:54 +00:00
|
|
|
|
2021-11-11 15:10:33 +00:00
|
|
|
private GameplayState gameplayState;
|
2021-10-05 07:48:54 +00:00
|
|
|
private ScoreProcessor scoreProcessor;
|
|
|
|
|
|
|
|
private int iteration;
|
2021-11-11 15:10:33 +00:00
|
|
|
private Bindable<JudgementResult> lastJudgementResult = new Bindable<JudgementResult>();
|
2021-10-05 08:10:24 +00:00
|
|
|
private PerformancePointsCounter counter;
|
2021-10-05 07:48:54 +00:00
|
|
|
|
2021-11-11 15:10:33 +00:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps() => AddStep("create components", () =>
|
2021-10-05 07:48:54 +00:00
|
|
|
{
|
|
|
|
var ruleset = CreateRuleset();
|
|
|
|
|
|
|
|
Debug.Assert(ruleset != null);
|
|
|
|
|
|
|
|
var beatmap = CreateWorkingBeatmap(ruleset.RulesetInfo)
|
|
|
|
.GetPlayableBeatmap(ruleset.RulesetInfo);
|
|
|
|
|
2021-11-11 15:10:33 +00:00
|
|
|
lastJudgementResult = new Bindable<JudgementResult>();
|
|
|
|
|
2021-10-05 07:48:54 +00:00
|
|
|
gameplayState = new GameplayState(beatmap, ruleset);
|
2021-11-11 15:10:33 +00:00
|
|
|
gameplayState.LastJudgementResult.BindTo(lastJudgementResult);
|
|
|
|
|
2022-03-14 06:51:10 +00:00
|
|
|
scoreProcessor = new ScoreProcessor(ruleset);
|
2021-11-11 15:10:33 +00:00
|
|
|
|
|
|
|
Child = dependencyContainer = new DependencyProvidingContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
CachedDependencies = new (Type, object)[]
|
|
|
|
{
|
|
|
|
(typeof(GameplayState), gameplayState),
|
|
|
|
(typeof(ScoreProcessor), scoreProcessor)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
iteration = 0;
|
|
|
|
});
|
2021-10-05 07:48:54 +00:00
|
|
|
|
|
|
|
protected override Ruleset CreateRuleset() => new OsuRuleset();
|
|
|
|
|
2021-11-11 15:10:33 +00:00
|
|
|
private void createCounter() => AddStep("Create counter", () =>
|
2021-10-05 07:48:54 +00:00
|
|
|
{
|
2021-11-11 15:10:33 +00:00
|
|
|
dependencyContainer.Child = counter = new PerformancePointsCounter
|
2021-10-05 07:48:54 +00:00
|
|
|
{
|
2021-11-11 15:10:33 +00:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Scale = new Vector2(5),
|
|
|
|
};
|
|
|
|
});
|
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;
|
2021-11-11 15:10:33 +00:00
|
|
|
createCounter();
|
2021-10-05 10:08:30 +00:00
|
|
|
|
2021-10-05 08:10:24 +00:00
|
|
|
AddAssert("counter displaying zero", () => counter.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
|
|
|
|
2021-10-05 08:10:24 +00:00
|
|
|
AddUntilStep("counter non-zero", () => counter.Current.Value > 0);
|
2021-10-05 08:24:36 +00:00
|
|
|
AddUntilStep("counter opaque", () => counter.Child.Alpha == 1);
|
2021-10-05 07:48:54 +00:00
|
|
|
|
|
|
|
AddStep("Revert judgement", () =>
|
|
|
|
{
|
2021-10-05 10:08:30 +00:00
|
|
|
previousValue = counter.Current.Value;
|
|
|
|
|
2021-10-05 07:48:54 +00:00
|
|
|
scoreProcessor.RevertResult(new JudgementResult(new HitObject(), new OsuJudgement()));
|
|
|
|
});
|
2021-10-05 08:10:24 +00:00
|
|
|
|
2021-10-05 10:08:30 +00:00
|
|
|
AddUntilStep("counter decreased", () => counter.Current.Value < previousValue);
|
2021-10-05 08:10:24 +00:00
|
|
|
|
|
|
|
AddStep("Add judgement", applyOneJudgement);
|
|
|
|
|
2021-10-05 10:08:30 +00:00
|
|
|
AddUntilStep("counter non-zero", () => counter.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);
|
|
|
|
|
|
|
|
createCounter();
|
|
|
|
|
|
|
|
AddUntilStep("counter non-zero", () => counter.Current.Value > 0);
|
|
|
|
AddUntilStep("counter opaque", () => counter.Child.Alpha == 1);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|