2020-03-26 02:30:59 +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.Linq ;
using NUnit.Framework ;
2020-03-30 06:29:00 +00:00
using osu.Framework.Allocation ;
2020-03-26 02:30:59 +00:00
using osu.Framework.Audio.Sample ;
using osu.Framework.Bindables ;
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
using osu.Framework.Graphics.Shapes ;
using osu.Framework.Graphics.Sprites ;
using osu.Framework.Graphics.Textures ;
using osu.Framework.Testing ;
using osu.Game.Audio ;
using osu.Game.Beatmaps ;
using osu.Game.Beatmaps.ControlPoints ;
using osu.Game.Rulesets.Catch.Objects ;
using osu.Game.Rulesets.Catch.Objects.Drawables ;
using osu.Game.Rulesets.Catch.Skinning ;
using osu.Game.Rulesets.Catch.UI ;
using osu.Game.Skinning ;
using osu.Game.Tests.Visual ;
using osuTK ;
using osuTK.Graphics ;
namespace osu.Game.Rulesets.Catch.Tests
{
public class TestSceneHyperDashColouring : OsuTestScene
{
2020-03-30 06:29:00 +00:00
[Resolved]
private SkinManager skins { get ; set ; }
2020-03-26 06:19:00 +00:00
[Test]
public void TestHyperDashCatcherColour ( )
{
CatcherArea catcherArea = null ;
AddStep ( "setup catcher" , ( ) = >
{
2020-04-04 15:07:29 +00:00
Child = setupSkinHierarchy ( catcherArea = new CatcherArea
{
RelativePositionAxes = Axes . None ,
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Scale = new Vector2 ( 4f ) ,
} , false , false , false ) ;
2020-03-26 06:19:00 +00:00
} ) ;
2020-04-04 15:07:29 +00:00
AddStep ( "start hyper-dashing" , ( ) = >
2020-03-26 06:19:00 +00:00
{
catcherArea . MovableCatcher . SetHyperDashState ( 2 ) ;
catcherArea . MovableCatcher . FinishTransforms ( ) ;
} ) ;
2020-04-04 15:07:29 +00:00
AddAssert ( "catcher has default hyper-dash colour" , ( ) = > catcherArea . MovableCatcher . Colour = = Color4 . OrangeRed ) ;
AddAssert ( "catcher trails have default hyper-dash colour" , ( ) = > catcherArea . OfType < Container < CatcherTrailSprite > > ( ) . Any ( c = > c . Colour = = Catcher . DefaultHyperDashColour ) ) ;
2020-03-26 06:19:00 +00:00
2020-04-04 15:07:29 +00:00
AddStep ( "finish hyper-dashing" , ( ) = >
2020-03-26 06:19:00 +00:00
{
catcherArea . MovableCatcher . SetHyperDashState ( 1 ) ;
catcherArea . MovableCatcher . FinishTransforms ( ) ;
} ) ;
2020-04-04 15:07:29 +00:00
AddAssert ( "hyper-dash colour cleared from catcher" , ( ) = > catcherArea . MovableCatcher . Colour = = Color4 . White ) ;
2020-03-26 06:19:00 +00:00
}
[Test]
public void TestCustomHyperDashCatcherColour ( )
{
CatcherArea catcherArea = null ;
AddStep ( "setup catcher" , ( ) = >
{
2020-04-04 15:07:29 +00:00
Child = setupSkinHierarchy ( catcherArea = new CatcherArea
{
RelativePositionAxes = Axes . None ,
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Scale = new Vector2 ( 4f ) ,
} , true , false , false ) ;
2020-03-26 06:19:00 +00:00
} ) ;
2020-04-04 15:07:29 +00:00
AddStep ( "start hyper-dashing" , ( ) = >
2020-03-26 06:19:00 +00:00
{
catcherArea . MovableCatcher . SetHyperDashState ( 2 ) ;
catcherArea . MovableCatcher . FinishTransforms ( ) ;
} ) ;
2020-04-04 15:07:29 +00:00
AddAssert ( "catcher use hyper-dash colour from skin" , ( ) = > catcherArea . MovableCatcher . Colour = = TestSkin . CustomHyperDashColour ) ;
AddAssert ( "catcher trails use hyper-dash colour from skin" , ( ) = > catcherArea . OfType < Container < CatcherTrailSprite > > ( ) . Any ( c = > c . Colour = = TestSkin . CustomHyperDashColour ) ) ;
2020-03-26 06:19:00 +00:00
AddStep ( "clear hyper-dash" , ( ) = >
{
catcherArea . MovableCatcher . SetHyperDashState ( 1 ) ;
catcherArea . MovableCatcher . FinishTransforms ( ) ;
} ) ;
2020-04-04 15:07:29 +00:00
AddAssert ( "hyper-dash colour cleared from catcher" , ( ) = > catcherArea . MovableCatcher . Colour = = Color4 . White ) ;
2020-03-26 06:19:00 +00:00
}
[Test]
public void TestHyperDashCatcherEndGlowColour ( )
{
CatcherArea catcherArea = null ;
AddStep ( "setup catcher" , ( ) = >
{
2020-04-04 15:07:29 +00:00
Child = setupSkinHierarchy ( catcherArea = new CatcherArea
{
RelativePositionAxes = Axes . None ,
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Scale = new Vector2 ( 4f ) ,
} , false , false , false ) ;
2020-03-26 06:19:00 +00:00
} ) ;
2020-04-04 15:07:29 +00:00
AddStep ( "start hyper-dashing" , ( ) = > catcherArea . MovableCatcher . SetHyperDashState ( 2 ) ) ;
AddAssert ( "end-glow catcher sprite has default hyper-dash colour" , ( ) = > catcherArea . OfType < Container < CatcherTrailSprite > > ( ) . Any ( c = > c . Colour = = Catcher . DefaultHyperDashColour ) ) ;
2020-03-26 06:19:00 +00:00
}
[TestCase(true)]
[TestCase(false)]
public void TestCustomHyperDashCatcherEndGlowColour ( bool customHyperDashCatcherColour )
{
CatcherArea catcherArea = null ;
AddStep ( "setup catcher" , ( ) = >
{
2020-04-04 15:07:29 +00:00
Child = setupSkinHierarchy ( catcherArea = new CatcherArea
{
RelativePositionAxes = Axes . None ,
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Scale = new Vector2 ( 4f ) ,
} , customHyperDashCatcherColour , true , false ) ;
2020-03-26 06:19:00 +00:00
} ) ;
2020-04-04 15:07:29 +00:00
AddStep ( "start hyper-dashing" , ( ) = > catcherArea . MovableCatcher . SetHyperDashState ( 2 ) ) ;
AddAssert ( "end-glow catcher sprite use its hyper-dash colour from skin" , ( ) = > catcherArea . OfType < Container < CatcherTrailSprite > > ( ) . Any ( c = > c . Colour = = TestSkin . CustomHyperDashAfterColour ) ) ;
2020-03-26 06:19:00 +00:00
}
[Test]
public void TestCustomHyperDashCatcherEndGlowColourFallback ( )
{
CatcherArea catcherArea = null ;
AddStep ( "setup catcher" , ( ) = >
{
2020-04-04 15:07:29 +00:00
Child = setupSkinHierarchy ( catcherArea = new CatcherArea
{
RelativePositionAxes = Axes . None ,
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Scale = new Vector2 ( 4f ) ,
} , true , false , false ) ;
2020-03-26 06:19:00 +00:00
} ) ;
2020-04-04 15:07:29 +00:00
AddStep ( "start hyper-dashing" , ( ) = > catcherArea . MovableCatcher . SetHyperDashState ( 2 ) ) ;
AddAssert ( "end-glow catcher sprite colour falls back to catcher colour from skin" , ( ) = > catcherArea . OfType < Container < CatcherTrailSprite > > ( ) . Any ( c = > c . Colour = = TestSkin . CustomHyperDashColour ) ) ;
2020-03-26 06:19:00 +00:00
}
2020-03-26 02:40:38 +00:00
[TestCase(false)]
[TestCase(true)]
public void TestHyperDashFruitColour ( bool legacyFruit )
{
DrawableFruit drawableFruit = null ;
2020-04-03 16:50:32 +00:00
AddStep ( "setup hyper-dash fruit" , ( ) = >
2020-03-26 02:40:38 +00:00
{
2020-03-30 06:29:00 +00:00
var fruit = new Fruit { HyperDashTarget = new Banana ( ) } ;
2020-03-26 02:40:38 +00:00
fruit . ApplyDefaults ( new ControlPointInfo ( ) , new BeatmapDifficulty ( ) ) ;
2020-03-30 06:29:00 +00:00
Child = setupSkinHierarchy ( drawableFruit = new DrawableFruit ( fruit )
{
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Scale = new Vector2 ( 4f ) ,
} , false , false , false , legacyFruit ) ;
2020-03-26 02:40:38 +00:00
} ) ;
2020-04-03 16:50:32 +00:00
AddAssert ( "hyper-dash fruit has default colour" , ( ) = >
2020-03-30 06:29:00 +00:00
legacyFruit
? checkLegacyFruitHyperDashColour ( drawableFruit , Catcher . DefaultHyperDashColour )
: checkFruitHyperDashColour ( drawableFruit , Catcher . DefaultHyperDashColour ) ) ;
2020-03-26 02:40:38 +00:00
}
[TestCase(false, true)]
[TestCase(false, false)]
[TestCase(true, true)]
[TestCase(true, false)]
public void TestCustomHyperDashFruitColour ( bool legacyFruit , bool customCatcherHyperDashColour )
{
DrawableFruit drawableFruit = null ;
2020-04-03 16:50:32 +00:00
AddStep ( "setup hyper-dash fruit" , ( ) = >
2020-03-26 02:40:38 +00:00
{
2020-03-30 06:29:00 +00:00
var fruit = new Fruit { HyperDashTarget = new Banana ( ) } ;
2020-03-26 02:40:38 +00:00
fruit . ApplyDefaults ( new ControlPointInfo ( ) , new BeatmapDifficulty ( ) ) ;
2020-03-30 06:29:00 +00:00
Child = setupSkinHierarchy ( drawableFruit = new DrawableFruit ( fruit )
{
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Scale = new Vector2 ( 4f ) ,
} , customCatcherHyperDashColour , false , true , legacyFruit ) ;
2020-03-26 02:40:38 +00:00
} ) ;
2020-04-03 16:50:32 +00:00
AddAssert ( "hyper-dash fruit use fruit colour from skin" , ( ) = >
2020-03-30 06:29:00 +00:00
legacyFruit
? checkLegacyFruitHyperDashColour ( drawableFruit , TestSkin . CustomHyperDashFruitColour )
: checkFruitHyperDashColour ( drawableFruit , TestSkin . CustomHyperDashFruitColour ) ) ;
2020-03-26 02:40:38 +00:00
}
[TestCase(false)]
[TestCase(true)]
public void TestCustomHyperDashFruitColourFallback ( bool legacyFruit )
{
DrawableFruit drawableFruit = null ;
2020-04-03 16:50:32 +00:00
AddStep ( "setup hyper-dash fruit" , ( ) = >
2020-03-26 02:40:38 +00:00
{
2020-03-30 06:29:00 +00:00
var fruit = new Fruit { HyperDashTarget = new Banana ( ) } ;
2020-03-26 02:40:38 +00:00
fruit . ApplyDefaults ( new ControlPointInfo ( ) , new BeatmapDifficulty ( ) ) ;
2020-03-30 06:29:00 +00:00
Child = setupSkinHierarchy (
2020-03-26 02:40:38 +00:00
drawableFruit = new DrawableFruit ( fruit )
{
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Scale = new Vector2 ( 4f ) ,
2020-03-30 06:29:00 +00:00
} , true , false , false , legacyFruit ) ;
2020-03-26 02:40:38 +00:00
} ) ;
2020-04-03 16:50:32 +00:00
AddAssert ( "hyper-dash fruit colour falls back to catcher colour from skin" , ( ) = >
2020-03-30 06:29:00 +00:00
legacyFruit
? checkLegacyFruitHyperDashColour ( drawableFruit , TestSkin . CustomHyperDashColour )
: checkFruitHyperDashColour ( drawableFruit , TestSkin . CustomHyperDashColour ) ) ;
2020-03-26 02:40:38 +00:00
}
2020-04-03 16:53:38 +00:00
private Drawable setupSkinHierarchy ( Drawable child , bool customCatcherColour , bool customAfterColour , bool customFruitColour , bool legacySkin = true )
2020-03-26 02:30:59 +00:00
{
2020-03-30 06:29:00 +00:00
var testSkinProvider = new SkinProvidingContainer ( new TestSkin ( customCatcherColour , customAfterColour , customFruitColour ) ) ;
if ( legacySkin )
{
var legacySkinProvider = new SkinProvidingContainer ( skins . GetSkin ( DefaultLegacySkin . Info ) ) ;
var legacySkinTransformer = new SkinProvidingContainer ( new CatchLegacySkinTransformer ( testSkinProvider ) ) ;
2020-03-26 02:30:59 +00:00
2020-03-30 06:29:00 +00:00
return legacySkinProvider
. WithChild ( testSkinProvider
. WithChild ( legacySkinTransformer
. WithChild ( child ) ) ) ;
}
2020-03-26 02:30:59 +00:00
2020-03-30 06:29:00 +00:00
return testSkinProvider . WithChild ( child ) ;
2020-03-26 02:30:59 +00:00
}
2020-03-30 06:29:00 +00:00
private bool checkFruitHyperDashColour ( DrawableFruit fruit , Color4 expectedColour ) = >
fruit . ChildrenOfType < SkinnableDrawable > ( ) . First ( ) . Drawable . ChildrenOfType < Circle > ( ) . Single ( c = > c . BorderColour = = expectedColour ) . Any ( d = > d . Colour = = expectedColour ) ;
2020-03-26 02:30:59 +00:00
2020-03-30 06:29:00 +00:00
private bool checkLegacyFruitHyperDashColour ( DrawableFruit fruit , Color4 expectedColour ) = >
fruit . ChildrenOfType < SkinnableDrawable > ( ) . First ( ) . Drawable . ChildrenOfType < Sprite > ( ) . Any ( c = > c . Colour = = expectedColour ) ;
2020-03-26 02:30:59 +00:00
2020-03-30 06:29:00 +00:00
private class TestSkin : ISkin
2020-03-26 02:30:59 +00:00
{
public static Color4 CustomHyperDashColour { get ; } = Color4 . Goldenrod ;
public static Color4 CustomHyperDashFruitColour { get ; } = Color4 . Cyan ;
public static Color4 CustomHyperDashAfterColour { get ; } = Color4 . Lime ;
2020-03-30 06:29:00 +00:00
private readonly bool customCatcherColour ;
private readonly bool customAfterColour ;
private readonly bool customFruitColour ;
2020-03-26 02:30:59 +00:00
2020-04-03 16:53:38 +00:00
public TestSkin ( bool customCatcherColour , bool customAfterColour , bool customFruitColour )
2020-03-26 02:30:59 +00:00
{
2020-03-30 06:29:00 +00:00
this . customCatcherColour = customCatcherColour ;
this . customAfterColour = customAfterColour ;
this . customFruitColour = customFruitColour ;
2020-03-26 02:30:59 +00:00
}
public Drawable GetDrawableComponent ( ISkinComponent component ) = > null ;
2020-03-30 06:29:00 +00:00
public Texture GetTexture ( string componentName ) = > null ;
2020-03-26 02:30:59 +00:00
public SampleChannel GetSample ( ISampleInfo sampleInfo ) = > null ;
public IBindable < TValue > GetConfig < TLookup , TValue > ( TLookup lookup )
{
2020-03-30 06:33:47 +00:00
if ( lookup is CatchSkinColour config )
2020-03-26 02:30:59 +00:00
{
2020-03-30 06:33:47 +00:00
if ( config = = CatchSkinColour . HyperDash & & customCatcherColour )
2020-03-28 04:43:47 +00:00
return SkinUtils . As < TValue > ( new Bindable < Color4 > ( CustomHyperDashColour ) ) ;
2020-03-26 02:30:59 +00:00
2020-03-30 06:33:47 +00:00
if ( config = = CatchSkinColour . HyperDashFruit & & customFruitColour )
2020-03-28 04:43:47 +00:00
return SkinUtils . As < TValue > ( new Bindable < Color4 > ( CustomHyperDashFruitColour ) ) ;
2020-03-26 02:30:59 +00:00
2020-03-30 06:33:47 +00:00
if ( config = = CatchSkinColour . HyperDashAfterImage & & customAfterColour )
2020-03-28 04:43:47 +00:00
return SkinUtils . As < TValue > ( new Bindable < Color4 > ( CustomHyperDashAfterColour ) ) ;
2020-03-26 02:30:59 +00:00
}
return null ;
}
}
}
}