mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 17:32:54 +08:00
Merge pull request #15579 from bdach/pp-counter-initial-update
Fix PP counter not updating until next judgement when shown for the first time
This commit is contained in:
commit
3d57aebf0c
@ -1,9 +1,10 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
@ -20,16 +21,17 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
{
|
{
|
||||||
public class TestScenePerformancePointsCounter : OsuTestScene
|
public class TestScenePerformancePointsCounter : OsuTestScene
|
||||||
{
|
{
|
||||||
[Cached]
|
private DependencyProvidingContainer dependencyContainer;
|
||||||
private GameplayState gameplayState;
|
|
||||||
|
|
||||||
[Cached]
|
private GameplayState gameplayState;
|
||||||
private ScoreProcessor scoreProcessor;
|
private ScoreProcessor scoreProcessor;
|
||||||
|
|
||||||
private int iteration;
|
private int iteration;
|
||||||
|
private Bindable<JudgementResult> lastJudgementResult = new Bindable<JudgementResult>();
|
||||||
private PerformancePointsCounter counter;
|
private PerformancePointsCounter counter;
|
||||||
|
|
||||||
public TestScenePerformancePointsCounter()
|
[SetUpSteps]
|
||||||
|
public void SetUpSteps() => AddStep("create components", () =>
|
||||||
{
|
{
|
||||||
var ruleset = CreateRuleset();
|
var ruleset = CreateRuleset();
|
||||||
|
|
||||||
@ -38,32 +40,43 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
var beatmap = CreateWorkingBeatmap(ruleset.RulesetInfo)
|
var beatmap = CreateWorkingBeatmap(ruleset.RulesetInfo)
|
||||||
.GetPlayableBeatmap(ruleset.RulesetInfo);
|
.GetPlayableBeatmap(ruleset.RulesetInfo);
|
||||||
|
|
||||||
|
lastJudgementResult = new Bindable<JudgementResult>();
|
||||||
|
|
||||||
gameplayState = new GameplayState(beatmap, ruleset);
|
gameplayState = new GameplayState(beatmap, ruleset);
|
||||||
|
gameplayState.LastJudgementResult.BindTo(lastJudgementResult);
|
||||||
|
|
||||||
scoreProcessor = new ScoreProcessor();
|
scoreProcessor = new ScoreProcessor();
|
||||||
}
|
|
||||||
|
Child = dependencyContainer = new DependencyProvidingContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
CachedDependencies = new (Type, object)[]
|
||||||
|
{
|
||||||
|
(typeof(GameplayState), gameplayState),
|
||||||
|
(typeof(ScoreProcessor), scoreProcessor)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
iteration = 0;
|
||||||
|
});
|
||||||
|
|
||||||
protected override Ruleset CreateRuleset() => new OsuRuleset();
|
protected override Ruleset CreateRuleset() => new OsuRuleset();
|
||||||
|
|
||||||
[SetUpSteps]
|
private void createCounter() => AddStep("Create counter", () =>
|
||||||
public void SetUpSteps()
|
|
||||||
{
|
{
|
||||||
AddStep("Create counter", () =>
|
dependencyContainer.Child = counter = new PerformancePointsCounter
|
||||||
{
|
{
|
||||||
iteration = 0;
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
Child = counter = new PerformancePointsCounter
|
Scale = new Vector2(5),
|
||||||
{
|
};
|
||||||
Anchor = Anchor.Centre,
|
});
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Scale = new Vector2(5),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestBasicCounting()
|
public void TestBasicCounting()
|
||||||
{
|
{
|
||||||
int previousValue = 0;
|
int previousValue = 0;
|
||||||
|
createCounter();
|
||||||
|
|
||||||
AddAssert("counter displaying zero", () => counter.Current.Value == 0);
|
AddAssert("counter displaying zero", () => counter.Current.Value == 0);
|
||||||
|
|
||||||
@ -86,6 +99,17 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
AddUntilStep("counter non-zero", () => counter.Current.Value > 0);
|
AddUntilStep("counter non-zero", () => counter.Current.Value > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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);
|
||||||
|
}
|
||||||
|
|
||||||
private void applyOneJudgement()
|
private void applyOneJudgement()
|
||||||
{
|
{
|
||||||
var scoreInfo = gameplayState.Score.ScoreInfo;
|
var scoreInfo = gameplayState.Score.ScoreInfo;
|
||||||
@ -94,13 +118,14 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
scoreInfo.Accuracy = 1;
|
scoreInfo.Accuracy = 1;
|
||||||
scoreInfo.Statistics[HitResult.Great] = iteration * 1000;
|
scoreInfo.Statistics[HitResult.Great] = iteration * 1000;
|
||||||
|
|
||||||
scoreProcessor.ApplyResult(new OsuJudgementResult(new HitObject
|
lastJudgementResult.Value = new OsuJudgementResult(new HitObject
|
||||||
{
|
{
|
||||||
StartTime = iteration * 10000,
|
StartTime = iteration * 10000,
|
||||||
}, new OsuJudgement())
|
}, new OsuJudgement())
|
||||||
{
|
{
|
||||||
Type = HitResult.Perfect,
|
Type = HitResult.Perfect,
|
||||||
});
|
};
|
||||||
|
scoreProcessor.ApplyResult(lastJudgementResult.Value);
|
||||||
|
|
||||||
iteration++;
|
iteration++;
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,9 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
scoreProcessor.NewJudgement += onJudgementChanged;
|
scoreProcessor.NewJudgement += onJudgementChanged;
|
||||||
scoreProcessor.JudgementReverted += onJudgementChanged;
|
scoreProcessor.JudgementReverted += onJudgementChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gameplayState?.LastJudgementResult.Value != null)
|
||||||
|
onJudgementChanged(gameplayState.LastJudgementResult.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isValid;
|
private bool isValid;
|
||||||
@ -155,7 +158,10 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
if (scoreProcessor != null)
|
if (scoreProcessor != null)
|
||||||
|
{
|
||||||
scoreProcessor.NewJudgement -= onJudgementChanged;
|
scoreProcessor.NewJudgement -= onJudgementChanged;
|
||||||
|
scoreProcessor.JudgementReverted -= onJudgementChanged;
|
||||||
|
}
|
||||||
|
|
||||||
loadCancellationSource?.Cancel();
|
loadCancellationSource?.Cancel();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user