2020-04-24 04:59:05 +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.
using System.Collections.Generic ;
using System.Linq ;
2020-04-30 19:41:57 +00:00
using Humanizer ;
2020-04-24 04:59:05 +00:00
using NUnit.Framework ;
using osu.Framework.Allocation ;
2020-04-29 22:14:27 +00:00
using osu.Framework.Extensions.IEnumerableExtensions ;
2020-04-30 22:24:39 +00:00
using osu.Framework.Graphics ;
2020-07-25 10:13:19 +00:00
using osu.Framework.Graphics.Animations ;
2020-04-24 04:59:05 +00:00
using osu.Framework.Testing ;
2020-04-26 23:40:57 +00:00
using osu.Game.Beatmaps ;
2020-04-24 04:59:05 +00:00
using osu.Game.Beatmaps.ControlPoints ;
using osu.Game.Rulesets.Judgements ;
using osu.Game.Rulesets.Objects ;
using osu.Game.Rulesets.Scoring ;
using osu.Game.Rulesets.Taiko.Judgements ;
using osu.Game.Rulesets.Taiko.Objects ;
2020-04-30 19:41:57 +00:00
using osu.Game.Rulesets.Taiko.Scoring ;
2020-04-24 04:59:05 +00:00
using osu.Game.Rulesets.Taiko.UI ;
using osu.Game.Rulesets.UI.Scrolling ;
using osu.Game.Tests.Visual ;
namespace osu.Game.Rulesets.Taiko.Tests.Skinning
{
[TestFixture]
2022-11-24 05:32:20 +00:00
public partial class TestSceneDrawableTaikoMascot : TaikoSkinnableTestScene
2020-04-24 04:59:05 +00:00
{
[Cached(typeof(IScrollingInfo))]
private ScrollingTestContainer . TestScrollingInfo info = new ScrollingTestContainer . TestScrollingInfo
{
Direction = { Value = ScrollingDirection . Left } ,
TimeRange = { Value = 5000 } ,
} ;
2022-08-17 08:36:41 +00:00
private TaikoScoreProcessor scoreProcessor = null ! ;
2020-04-30 19:41:57 +00:00
2020-04-29 19:27:02 +00:00
private IEnumerable < DrawableTaikoMascot > mascots = > this . ChildrenOfType < DrawableTaikoMascot > ( ) ;
2020-07-25 10:13:19 +00:00
private IEnumerable < DrawableTaikoMascot > animatedMascots = >
mascots . Where ( mascot = > mascot . ChildrenOfType < TextureAnimation > ( ) . All ( animation = > animation . FrameCount > 0 ) ) ;
2020-04-28 21:22:50 +00:00
private IEnumerable < TaikoPlayfield > playfields = > this . ChildrenOfType < TaikoPlayfield > ( ) ;
2020-04-27 21:17:19 +00:00
2020-04-30 19:41:57 +00:00
[SetUp]
public void SetUp ( )
{
scoreProcessor = new TaikoScoreProcessor ( ) ;
}
2020-04-24 04:59:05 +00:00
[Test]
2020-04-29 19:27:02 +00:00
public void TestStateAnimations ( )
2020-04-24 04:59:05 +00:00
{
2020-04-29 18:28:46 +00:00
AddStep ( "set beatmap" , ( ) = > setBeatmap ( ) ) ;
2020-04-24 04:59:05 +00:00
2021-06-02 07:04:53 +00:00
AddStep ( "clear state" , ( ) = > SetContents ( _ = > new TaikoMascotAnimation ( TaikoMascotAnimationState . Clear ) ) ) ;
AddStep ( "idle state" , ( ) = > SetContents ( _ = > new TaikoMascotAnimation ( TaikoMascotAnimationState . Idle ) ) ) ;
AddStep ( "kiai state" , ( ) = > SetContents ( _ = > new TaikoMascotAnimation ( TaikoMascotAnimationState . Kiai ) ) ) ;
AddStep ( "fail state" , ( ) = > SetContents ( _ = > new TaikoMascotAnimation ( TaikoMascotAnimationState . Fail ) ) ) ;
2020-04-24 04:59:05 +00:00
}
2020-04-30 20:03:39 +00:00
[Test]
public void TestInitialState ( )
{
2022-08-17 14:03:39 +00:00
AddStep ( "set beatmap" , ( ) = > setBeatmap ( ) ) ;
2021-06-02 07:04:53 +00:00
AddStep ( "create mascot" , ( ) = > SetContents ( _ = > new DrawableTaikoMascot { RelativeSizeAxes = Axes . Both } ) ) ;
2020-04-30 20:03:39 +00:00
AddAssert ( "mascot initially idle" , ( ) = > allMascotsIn ( TaikoMascotAnimationState . Idle ) ) ;
}
2020-04-29 22:14:27 +00:00
[Test]
public void TestClearStateTransition ( )
{
AddStep ( "set beatmap" , ( ) = > setBeatmap ( ) ) ;
2021-06-02 07:04:53 +00:00
AddStep ( "create mascot" , ( ) = > SetContents ( _ = > new DrawableTaikoMascot { RelativeSizeAxes = Axes . Both } ) ) ;
2020-04-29 22:14:27 +00:00
2020-05-11 20:53:05 +00:00
AddStep ( "set clear state" , ( ) = > mascots . ForEach ( mascot = > mascot . State . Value = TaikoMascotAnimationState . Clear ) ) ;
AddStep ( "miss" , ( ) = > mascots . ForEach ( mascot = > mascot . LastResult . Value = new JudgementResult ( new Hit ( ) , new TaikoJudgement ( ) ) { Type = HitResult . Miss } ) ) ;
2020-07-25 10:13:19 +00:00
AddAssert ( "skins with animations remain in clear state" , ( ) = > animatedMascotsIn ( TaikoMascotAnimationState . Clear ) ) ;
2020-04-30 22:24:39 +00:00
AddUntilStep ( "state reverts to fail" , ( ) = > allMascotsIn ( TaikoMascotAnimationState . Fail ) ) ;
2020-04-29 22:14:27 +00:00
2020-05-11 20:53:05 +00:00
AddStep ( "set clear state again" , ( ) = > mascots . ForEach ( mascot = > mascot . State . Value = TaikoMascotAnimationState . Clear ) ) ;
2020-07-25 10:13:19 +00:00
AddAssert ( "skins with animations change to clear" , ( ) = > animatedMascotsIn ( TaikoMascotAnimationState . Clear ) ) ;
2020-04-29 22:14:27 +00:00
}
2020-04-24 04:59:05 +00:00
[Test]
2020-04-30 19:41:57 +00:00
public void TestIdleState ( )
2020-04-24 04:59:05 +00:00
{
2022-08-17 14:03:39 +00:00
prepareDrawableRulesetAndBeatmap ( false ) ;
2020-04-24 04:59:05 +00:00
2023-05-19 05:06:53 +00:00
var hit = new Hit ( ) ;
assertStateAfterResult ( new JudgementResult ( hit , new TaikoJudgement ( ) ) { Type = HitResult . Great } , TaikoMascotAnimationState . Idle ) ;
assertStateAfterResult ( new JudgementResult ( new Hit . StrongNestedHit ( hit ) , new TaikoStrongJudgement ( ) ) { Type = HitResult . IgnoreMiss } , TaikoMascotAnimationState . Idle ) ;
2020-04-30 19:41:57 +00:00
}
2020-04-26 23:40:57 +00:00
2020-04-30 19:41:57 +00:00
[Test]
public void TestKiaiState ( )
{
2022-08-17 14:03:39 +00:00
prepareDrawableRulesetAndBeatmap ( true ) ;
2020-04-29 19:42:28 +00:00
2020-09-29 08:16:55 +00:00
assertStateAfterResult ( new JudgementResult ( new Hit ( ) , new TaikoJudgement ( ) ) { Type = HitResult . Ok } , TaikoMascotAnimationState . Kiai ) ;
2020-09-29 06:36:08 +00:00
assertStateAfterResult ( new JudgementResult ( new Hit ( ) , new TaikoStrongJudgement ( ) ) { Type = HitResult . IgnoreMiss } , TaikoMascotAnimationState . Kiai ) ;
2020-04-30 19:41:57 +00:00
assertStateAfterResult ( new JudgementResult ( new Hit ( ) , new TaikoJudgement ( ) ) { Type = HitResult . Miss } , TaikoMascotAnimationState . Fail ) ;
2020-04-26 23:40:57 +00:00
}
[Test]
2020-04-30 19:41:57 +00:00
public void TestMissState ( )
2020-04-26 23:40:57 +00:00
{
2022-08-17 14:03:39 +00:00
prepareDrawableRulesetAndBeatmap ( false ) ;
2020-04-26 23:40:57 +00:00
2020-04-30 19:41:57 +00:00
assertStateAfterResult ( new JudgementResult ( new Hit ( ) , new TaikoJudgement ( ) ) { Type = HitResult . Great } , TaikoMascotAnimationState . Idle ) ;
assertStateAfterResult ( new JudgementResult ( new Hit ( ) , new TaikoJudgement ( ) ) { Type = HitResult . Miss } , TaikoMascotAnimationState . Fail ) ;
2020-09-29 08:16:55 +00:00
assertStateAfterResult ( new JudgementResult ( new Hit ( ) , new TaikoJudgement ( ) ) { Type = HitResult . Ok } , TaikoMascotAnimationState . Idle ) ;
2020-04-30 19:41:57 +00:00
}
2020-04-26 23:40:57 +00:00
2020-04-30 19:41:57 +00:00
[TestCase(true)]
[TestCase(false)]
public void TestClearStateOnComboMilestone ( bool kiai )
{
2022-08-17 14:03:39 +00:00
prepareDrawableRulesetAndBeatmap ( kiai ) ;
2020-04-30 19:41:57 +00:00
AddRepeatStep ( "reach 49 combo" , ( ) = > applyNewResult ( new JudgementResult ( new Hit ( ) , new TaikoJudgement ( ) ) { Type = HitResult . Great } ) , 49 ) ;
2020-09-29 08:16:55 +00:00
assertStateAfterResult ( new JudgementResult ( new Hit ( ) , new TaikoJudgement ( ) ) { Type = HitResult . Ok } , TaikoMascotAnimationState . Clear ) ;
2020-04-30 19:41:57 +00:00
}
2020-04-30 20:16:25 +00:00
[TestCase(true, TaikoMascotAnimationState.Kiai)]
[TestCase(false, TaikoMascotAnimationState.Idle)]
public void TestClearStateOnClearedSwell ( bool kiai , TaikoMascotAnimationState expectedStateAfterClear )
2020-04-30 19:41:57 +00:00
{
2022-08-17 14:03:39 +00:00
prepareDrawableRulesetAndBeatmap ( kiai ) ;
2020-04-24 04:59:05 +00:00
2020-04-30 19:41:57 +00:00
assertStateAfterResult ( new JudgementResult ( new Swell ( ) , new TaikoSwellJudgement ( ) ) { Type = HitResult . Great } , TaikoMascotAnimationState . Clear ) ;
2022-06-20 12:39:47 +00:00
AddUntilStep ( $"state reverts to {expectedStateAfterClear.ToString().ToLowerInvariant()}" , ( ) = > allMascotsIn ( expectedStateAfterClear ) ) ;
2020-04-26 23:40:57 +00:00
}
private void setBeatmap ( bool kiai = false )
{
var controlPointInfo = new ControlPointInfo ( ) ;
controlPointInfo . Add ( 0 , new TimingControlPoint { BeatLength = 90 } ) ;
if ( kiai )
controlPointInfo . Add ( 0 , new EffectControlPoint { KiaiMode = true } ) ;
2020-04-28 21:24:21 +00:00
Beatmap . Value = CreateWorkingBeatmap ( new Beatmap
2020-04-26 23:40:57 +00:00
{
HitObjects = new List < HitObject > { new Hit { Type = HitType . Centre } } ,
BeatmapInfo = new BeatmapInfo
{
2022-01-18 13:57:39 +00:00
Difficulty = new BeatmapDifficulty ( ) ,
2020-04-26 23:40:57 +00:00
Metadata = new BeatmapMetadata
{
2020-04-30 19:41:57 +00:00
Artist = "Unknown" ,
Title = "Sample Beatmap" ,
2022-01-18 14:30:40 +00:00
Author = { Username = "Craftplacer" } ,
2020-04-26 23:40:57 +00:00
} ,
Ruleset = new TaikoRuleset ( ) . RulesetInfo
} ,
ControlPointInfo = controlPointInfo
} ) ;
2020-04-30 19:41:57 +00:00
scoreProcessor . ApplyBeatmap ( Beatmap . Value . Beatmap ) ;
}
2022-08-17 14:03:39 +00:00
private void prepareDrawableRulesetAndBeatmap ( bool kiai )
2020-04-30 19:41:57 +00:00
{
2022-08-17 08:36:41 +00:00
AddStep ( "set beatmap" , ( ) = > setBeatmap ( kiai ) ) ;
2020-04-30 19:41:57 +00:00
AddStep ( "create drawable ruleset" , ( ) = >
{
2021-06-02 07:04:53 +00:00
SetContents ( _ = >
2020-04-30 19:41:57 +00:00
{
var ruleset = new TaikoRuleset ( ) ;
return new DrawableTaikoRuleset ( ruleset , Beatmap . Value . GetPlayableBeatmap ( ruleset . RulesetInfo ) ) ;
} ) ;
} ) ;
2022-08-17 08:36:41 +00:00
AddUntilStep ( "wait for track to be loaded" , ( ) = > MusicController . TrackLoaded ) ;
AddStep ( "start track" , ( ) = > MusicController . CurrentTrack . Restart ( ) ) ;
AddUntilStep ( "wait for track started" , ( ) = > MusicController . IsPlaying ) ;
2020-04-30 19:41:57 +00:00
}
private void assertStateAfterResult ( JudgementResult judgementResult , TaikoMascotAnimationState expectedState )
{
2022-08-17 08:36:41 +00:00
TaikoMascotAnimationState [ ] mascotStates = null ! ;
2020-07-25 10:13:19 +00:00
2022-06-20 12:39:47 +00:00
AddStep ( $"{judgementResult.Type.ToString().ToLowerInvariant()} result for {judgementResult.Judgement.GetType().Name.Humanize(LetterCasing.LowerCase)}" ,
2020-07-25 10:13:19 +00:00
( ) = >
{
applyNewResult ( judgementResult ) ;
// store the states as soon as possible, so that the delay between steps doesn't incorrectly fail the test
// due to not checking if the state changed quickly enough.
Schedule ( ( ) = > mascotStates = animatedMascots . Select ( mascot = > mascot . State . Value ) . ToArray ( ) ) ;
} ) ;
2020-04-30 19:41:57 +00:00
2022-08-17 08:36:41 +00:00
AddAssert ( $"state is {expectedState.ToString().ToLowerInvariant()}" , ( ) = > mascotStates . Distinct ( ) , ( ) = > Is . EquivalentTo ( new [ ] { expectedState } ) ) ;
2020-04-26 23:40:57 +00:00
}
2020-04-30 19:41:57 +00:00
private void applyNewResult ( JudgementResult judgementResult )
2020-04-26 23:40:57 +00:00
{
2020-04-30 19:58:05 +00:00
scoreProcessor . ApplyResult ( judgementResult ) ;
2020-04-26 23:40:57 +00:00
foreach ( var playfield in playfields )
{
2020-04-30 19:41:57 +00:00
var hit = new DrawableTestHit ( new Hit ( ) , judgementResult . Type ) ;
2020-09-26 15:18:50 +00:00
playfield . Add ( hit ) ;
2020-04-26 23:40:57 +00:00
2020-04-30 19:41:57 +00:00
playfield . OnNewResult ( hit , judgementResult ) ;
2020-04-26 23:40:57 +00:00
}
2020-05-11 20:53:05 +00:00
foreach ( var mascot in mascots )
{
mascot . LastResult . Value = judgementResult ;
}
2020-04-24 04:59:05 +00:00
}
2020-04-29 22:14:27 +00:00
private bool allMascotsIn ( TaikoMascotAnimationState state ) = > mascots . All ( d = > d . State . Value = = state ) ;
2020-07-25 10:13:19 +00:00
private bool animatedMascotsIn ( TaikoMascotAnimationState state ) = > animatedMascots . Any ( d = > d . State . Value = = state ) ;
2020-04-24 04:59:05 +00:00
}
}