mirror of
https://github.com/ppy/osu.git
synced 2024-09-21 15:27:24 +08:00
Refactor TestSceneDrawableTaikoMascot
to read a bit better
This commit is contained in:
parent
4ef4d66f49
commit
7d8fbc4dbc
@ -1,8 +1,6 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
@ -36,7 +34,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
TimeRange = { Value = 5000 },
|
TimeRange = { Value = 5000 },
|
||||||
};
|
};
|
||||||
|
|
||||||
private TaikoScoreProcessor scoreProcessor;
|
private TaikoScoreProcessor scoreProcessor = null!;
|
||||||
|
|
||||||
private IEnumerable<DrawableTaikoMascot> mascots => this.ChildrenOfType<DrawableTaikoMascot>();
|
private IEnumerable<DrawableTaikoMascot> mascots => this.ChildrenOfType<DrawableTaikoMascot>();
|
||||||
|
|
||||||
@ -89,9 +87,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestIdleState()
|
public void TestIdleState()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => setBeatmap());
|
prepareTest(false);
|
||||||
|
|
||||||
createDrawableRuleset();
|
|
||||||
|
|
||||||
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Idle);
|
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Idle);
|
||||||
assertStateAfterResult(new JudgementResult(new Hit.StrongNestedHit(), new TaikoStrongJudgement()) { Type = HitResult.IgnoreMiss }, TaikoMascotAnimationState.Idle);
|
assertStateAfterResult(new JudgementResult(new Hit.StrongNestedHit(), new TaikoStrongJudgement()) { Type = HitResult.IgnoreMiss }, TaikoMascotAnimationState.Idle);
|
||||||
@ -100,9 +96,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestKiaiState()
|
public void TestKiaiState()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => setBeatmap(true));
|
prepareTest(true);
|
||||||
|
|
||||||
createDrawableRuleset();
|
|
||||||
|
|
||||||
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Ok }, TaikoMascotAnimationState.Kiai);
|
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Ok }, TaikoMascotAnimationState.Kiai);
|
||||||
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoStrongJudgement()) { Type = HitResult.IgnoreMiss }, TaikoMascotAnimationState.Kiai);
|
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoStrongJudgement()) { Type = HitResult.IgnoreMiss }, TaikoMascotAnimationState.Kiai);
|
||||||
@ -112,9 +106,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestMissState()
|
public void TestMissState()
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => setBeatmap());
|
prepareTest(false);
|
||||||
|
|
||||||
createDrawableRuleset();
|
|
||||||
|
|
||||||
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Idle);
|
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Idle);
|
||||||
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Miss }, TaikoMascotAnimationState.Fail);
|
assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Miss }, TaikoMascotAnimationState.Fail);
|
||||||
@ -128,7 +120,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
{
|
{
|
||||||
AddStep("set beatmap", () => setBeatmap(kiai));
|
AddStep("set beatmap", () => setBeatmap(kiai));
|
||||||
|
|
||||||
createDrawableRuleset();
|
prepareTest(kiai);
|
||||||
|
|
||||||
AddRepeatStep("reach 49 combo", () => applyNewResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }), 49);
|
AddRepeatStep("reach 49 combo", () => applyNewResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }), 49);
|
||||||
|
|
||||||
@ -139,9 +131,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
[TestCase(false, TaikoMascotAnimationState.Idle)]
|
[TestCase(false, TaikoMascotAnimationState.Idle)]
|
||||||
public void TestClearStateOnClearedSwell(bool kiai, TaikoMascotAnimationState expectedStateAfterClear)
|
public void TestClearStateOnClearedSwell(bool kiai, TaikoMascotAnimationState expectedStateAfterClear)
|
||||||
{
|
{
|
||||||
AddStep("set beatmap", () => setBeatmap(kiai));
|
prepareTest(kiai);
|
||||||
|
|
||||||
createDrawableRuleset();
|
|
||||||
|
|
||||||
assertStateAfterResult(new JudgementResult(new Swell(), new TaikoSwellJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Clear);
|
assertStateAfterResult(new JudgementResult(new Swell(), new TaikoSwellJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Clear);
|
||||||
AddUntilStep($"state reverts to {expectedStateAfterClear.ToString().ToLowerInvariant()}", () => allMascotsIn(expectedStateAfterClear));
|
AddUntilStep($"state reverts to {expectedStateAfterClear.ToString().ToLowerInvariant()}", () => allMascotsIn(expectedStateAfterClear));
|
||||||
@ -175,25 +165,27 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
scoreProcessor.ApplyBeatmap(Beatmap.Value.Beatmap);
|
scoreProcessor.ApplyBeatmap(Beatmap.Value.Beatmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDrawableRuleset()
|
private void prepareTest(bool kiai)
|
||||||
{
|
{
|
||||||
AddUntilStep("wait for beatmap to be loaded", () => Beatmap.Value.Track.IsLoaded);
|
AddStep("set beatmap", () => setBeatmap(kiai));
|
||||||
|
|
||||||
AddStep("create drawable ruleset", () =>
|
AddStep("create drawable ruleset", () =>
|
||||||
{
|
{
|
||||||
Beatmap.Value.Track.Start();
|
|
||||||
|
|
||||||
SetContents(_ =>
|
SetContents(_ =>
|
||||||
{
|
{
|
||||||
var ruleset = new TaikoRuleset();
|
var ruleset = new TaikoRuleset();
|
||||||
return new DrawableTaikoRuleset(ruleset, Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo));
|
return new DrawableTaikoRuleset(ruleset, Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddUntilStep("wait for track to be loaded", () => MusicController.TrackLoaded);
|
||||||
|
AddStep("start track", () => MusicController.CurrentTrack.Restart());
|
||||||
|
AddUntilStep("wait for track started", () => MusicController.IsPlaying);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertStateAfterResult(JudgementResult judgementResult, TaikoMascotAnimationState expectedState)
|
private void assertStateAfterResult(JudgementResult judgementResult, TaikoMascotAnimationState expectedState)
|
||||||
{
|
{
|
||||||
TaikoMascotAnimationState[] mascotStates = null;
|
TaikoMascotAnimationState[] mascotStates = null!;
|
||||||
|
|
||||||
AddStep($"{judgementResult.Type.ToString().ToLowerInvariant()} result for {judgementResult.Judgement.GetType().Name.Humanize(LetterCasing.LowerCase)}",
|
AddStep($"{judgementResult.Type.ToString().ToLowerInvariant()} result for {judgementResult.Judgement.GetType().Name.Humanize(LetterCasing.LowerCase)}",
|
||||||
() =>
|
() =>
|
||||||
@ -204,7 +196,7 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning
|
|||||||
Schedule(() => mascotStates = animatedMascots.Select(mascot => mascot.State.Value).ToArray());
|
Schedule(() => mascotStates = animatedMascots.Select(mascot => mascot.State.Value).ToArray());
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert($"state is {expectedState.ToString().ToLowerInvariant()}", () => mascotStates.All(state => state == expectedState));
|
AddAssert($"state is {expectedState.ToString().ToLowerInvariant()}", () => mascotStates.Distinct(), () => Is.EquivalentTo(new[] { expectedState }));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyNewResult(JudgementResult judgementResult)
|
private void applyNewResult(JudgementResult judgementResult)
|
||||||
|
Loading…
Reference in New Issue
Block a user