2020-03-26 10:30:59 +08: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 14:29:00 +08:00
using osu.Framework.Allocation ;
2020-03-26 10:30:59 +08:00
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
using osu.Framework.Graphics.Sprites ;
using osu.Framework.Testing ;
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 14:29:00 +08:00
[Resolved]
private SkinManager skins { get ; set ; }
2020-03-26 14:19:00 +08:00
[Test]
2020-04-21 10:58:56 +08:00
public void TestDefaultCatcherColour ( )
2020-03-26 14:19:00 +08:00
{
2020-04-21 10:58:56 +08:00
var skin = new TestSkin ( ) ;
2020-03-26 14:19:00 +08:00
2020-04-21 10:58:56 +08:00
checkHyperDashCatcherColour ( skin , Catcher . DEFAULT_HYPER_DASH_COLOUR ) ;
}
2020-03-26 14:19:00 +08:00
2020-04-21 10:58:56 +08:00
[Test]
public void TestCustomCatcherColour ( )
{
var skin = new TestSkin
2020-03-26 14:19:00 +08:00
{
2020-04-21 10:58:56 +08:00
HyperDashColour = Color4 . Goldenrod
} ;
2020-03-26 14:19:00 +08:00
2020-04-21 10:58:56 +08:00
checkHyperDashCatcherColour ( skin , skin . HyperDashColour ) ;
}
2020-03-26 14:19:00 +08:00
2020-04-21 10:58:56 +08:00
[Test]
public void TestCustomEndGlowColour ( )
{
var skin = new TestSkin
2020-03-26 14:19:00 +08:00
{
2020-04-21 10:58:56 +08:00
HyperDashAfterImageColour = Color4 . Lime
} ;
2020-03-26 14:19:00 +08:00
2020-04-21 10:58:56 +08:00
checkHyperDashCatcherColour ( skin , Catcher . DEFAULT_HYPER_DASH_COLOUR , skin . HyperDashAfterImageColour ) ;
2020-03-26 14:19:00 +08:00
}
[Test]
2020-04-21 10:58:56 +08:00
public void TestCustomEndGlowColourPriority ( )
2020-03-26 14:19:00 +08:00
{
2020-04-21 10:58:56 +08:00
var skin = new TestSkin
2020-03-26 14:19:00 +08:00
{
2020-04-21 10:58:56 +08:00
HyperDashColour = Color4 . Goldenrod ,
HyperDashAfterImageColour = Color4 . Lime
} ;
2020-03-26 14:19:00 +08:00
2020-04-21 10:58:56 +08:00
checkHyperDashCatcherColour ( skin , skin . HyperDashColour , skin . HyperDashAfterImageColour ) ;
}
2020-03-26 14:19:00 +08:00
2020-04-05 05:02:33 +08:00
[Test]
2020-04-19 18:41:00 +08:00
public void TestDefaultFruitColour ( )
2020-03-26 10:40:38 +08:00
{
2020-04-19 18:41:00 +08:00
var skin = new TestSkin ( ) ;
2020-03-26 10:40:38 +08:00
2020-04-19 18:41:00 +08:00
checkHyperDashFruitColour ( skin , Catcher . DEFAULT_HYPER_DASH_COLOUR ) ;
}
2020-03-26 14:19:00 +08:00
2020-04-19 18:41:00 +08:00
[Test]
public void TestCustomFruitColour ( )
{
var skin = new TestSkin
2020-03-26 14:19:00 +08:00
{
2020-04-19 18:41:00 +08:00
HyperDashFruitColour = Color4 . Cyan
} ;
2020-03-26 14:19:00 +08:00
2020-04-19 18:41:00 +08:00
checkHyperDashFruitColour ( skin , skin . HyperDashFruitColour ) ;
2020-03-26 14:19:00 +08:00
}
[Test]
2020-04-19 18:41:00 +08:00
public void TestCustomFruitColourPriority ( )
2020-03-26 14:19:00 +08:00
{
2020-04-19 18:41:00 +08:00
var skin = new TestSkin
2020-03-26 14:19:00 +08:00
{
2020-04-19 18:41:00 +08:00
HyperDashColour = Color4 . Goldenrod ,
HyperDashFruitColour = Color4 . Cyan
} ;
2020-03-26 14:19:00 +08:00
2020-04-19 18:41:00 +08:00
checkHyperDashFruitColour ( skin , skin . HyperDashFruitColour ) ;
2020-03-26 14:19:00 +08:00
}
2020-04-05 05:02:33 +08:00
[Test]
2020-04-19 18:41:00 +08:00
public void TestFruitColourFallback ( )
2020-03-26 14:19:00 +08:00
{
2020-04-19 18:41:00 +08:00
var skin = new TestSkin
2020-03-26 14:19:00 +08:00
{
2020-04-19 18:41:00 +08:00
HyperDashColour = Color4 . Goldenrod
} ;
2020-03-26 14:19:00 +08:00
2020-04-19 18:41:00 +08:00
checkHyperDashFruitColour ( skin , skin . HyperDashColour ) ;
2020-03-26 14:19:00 +08:00
}
2020-04-21 10:58:56 +08:00
private void checkHyperDashCatcherColour ( ISkin skin , Color4 expectedCatcherColour , Color4 ? expectedEndGlowColour = null )
2020-03-26 14:19:00 +08:00
{
CatcherArea catcherArea = null ;
2020-04-21 10:58:56 +08:00
AddStep ( "create hyper-dashing catcher" , ( ) = >
2020-03-26 14:19:00 +08:00
{
2020-04-04 23:07:29 +08:00
Child = setupSkinHierarchy ( catcherArea = new CatcherArea
{
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Scale = new Vector2 ( 4f ) ,
2020-04-21 10:58:56 +08:00
} , skin ) ;
catcherArea . MovableCatcher . SetHyperDashState ( 2 ) ;
catcherArea . MovableCatcher . FinishTransforms ( ) ;
2020-03-26 14:19:00 +08:00
} ) ;
2020-04-21 10:58:56 +08:00
AddAssert ( "catcher colour is correct" , ( ) = >
expectedCatcherColour = = Catcher . DEFAULT_HYPER_DASH_COLOUR
? catcherArea . MovableCatcher . Colour = = Catcher . DEFAULT_CATCHER_HYPER_DASH_COLOUR
: catcherArea . MovableCatcher . Colour = = expectedCatcherColour ) ;
2020-03-26 14:19:00 +08:00
2020-04-21 10:58:56 +08:00
AddAssert ( "catcher trails colours are correct" , ( ) = > catcherArea . OfType < Container < CatcherTrailSprite > > ( ) . Any ( c = > c . Colour = = expectedCatcherColour ) ) ;
AddAssert ( "catcher end-glow colours are correct" , ( ) = > catcherArea . OfType < Container < CatcherTrailSprite > > ( ) . Any ( c = > c . Colour = = ( expectedEndGlowColour ? ? expectedCatcherColour ) ) ) ;
2020-03-26 10:40:38 +08:00
2020-04-21 10:58:56 +08:00
AddStep ( "finish hyper-dashing" , ( ) = >
2020-03-26 10:40:38 +08:00
{
2020-04-21 10:58:56 +08:00
catcherArea . MovableCatcher . SetHyperDashState ( 1 ) ;
catcherArea . MovableCatcher . FinishTransforms ( ) ;
2020-03-26 10:40:38 +08:00
} ) ;
2020-04-21 10:58:56 +08:00
AddAssert ( "catcher colour returned to white" , ( ) = > catcherArea . MovableCatcher . Colour = = Color4 . White ) ;
2020-03-26 10:40:38 +08:00
}
2020-04-19 18:41:00 +08:00
private void checkHyperDashFruitColour ( ISkin skin , Color4 expectedColour )
2020-03-26 10:40:38 +08:00
{
DrawableFruit drawableFruit = null ;
2020-04-19 18:41:00 +08:00
AddStep ( "create hyper-dash fruit" , ( ) = >
2020-03-26 10:40:38 +08:00
{
2020-03-30 14:29:00 +08:00
var fruit = new Fruit { HyperDashTarget = new Banana ( ) } ;
2020-03-26 10:40:38 +08:00
fruit . ApplyDefaults ( new ControlPointInfo ( ) , new BeatmapDifficulty ( ) ) ;
2020-03-30 14:29:00 +08:00
Child = setupSkinHierarchy ( drawableFruit = new DrawableFruit ( fruit )
{
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Scale = new Vector2 ( 4f ) ,
2020-04-19 18:41:00 +08:00
} , skin ) ;
2020-03-26 10:40:38 +08:00
} ) ;
2020-04-19 18:41:00 +08:00
AddAssert ( "hyper-dash colour is correct" , ( ) = > checkLegacyFruitHyperDashColour ( drawableFruit , expectedColour ) ) ;
2020-03-26 10:40:38 +08:00
}
2020-04-19 18:41:00 +08:00
private Drawable setupSkinHierarchy ( Drawable child , ISkin skin )
2020-03-26 10:40:38 +08:00
{
2020-04-05 05:02:33 +08:00
var legacySkinProvider = new SkinProvidingContainer ( skins . GetSkin ( DefaultLegacySkin . Info ) ) ;
2020-04-19 18:41:00 +08:00
var testSkinProvider = new SkinProvidingContainer ( skin ) ;
2020-04-05 05:02:33 +08:00
var legacySkinTransformer = new SkinProvidingContainer ( new CatchLegacySkinTransformer ( testSkinProvider ) ) ;
2020-03-30 14:29:00 +08:00
2020-04-05 05:02:33 +08:00
return legacySkinProvider
. WithChild ( testSkinProvider
. WithChild ( legacySkinTransformer
. WithChild ( child ) ) ) ;
2020-03-26 10:30:59 +08:00
}
2020-03-30 14:29:00 +08:00
private bool checkLegacyFruitHyperDashColour ( DrawableFruit fruit , Color4 expectedColour ) = >
fruit . ChildrenOfType < SkinnableDrawable > ( ) . First ( ) . Drawable . ChildrenOfType < Sprite > ( ) . Any ( c = > c . Colour = = expectedColour ) ;
2020-03-26 10:30:59 +08:00
2020-04-05 05:13:23 +08:00
private class TestSkin : LegacySkin
2020-03-26 10:30:59 +08:00
{
2020-04-19 18:41:00 +08:00
public Color4 HyperDashColour
2020-03-26 10:30:59 +08:00
{
2020-04-19 18:41:00 +08:00
get = > Configuration . CustomColours [ CatchSkinColour . HyperDash . ToString ( ) ] ;
set = > Configuration . CustomColours [ CatchSkinColour . HyperDash . ToString ( ) ] = value ;
2020-03-26 10:30:59 +08:00
}
2020-04-19 18:41:00 +08:00
public Color4 HyperDashAfterImageColour
2020-03-26 10:30:59 +08:00
{
2020-04-19 18:41:00 +08:00
get = > Configuration . CustomColours [ CatchSkinColour . HyperDashAfterImage . ToString ( ) ] ;
set = > Configuration . CustomColours [ CatchSkinColour . HyperDashAfterImage . ToString ( ) ] = value ;
}
2020-03-26 10:30:59 +08:00
2020-04-19 18:41:00 +08:00
public Color4 HyperDashFruitColour
{
get = > Configuration . CustomColours [ CatchSkinColour . HyperDashFruit . ToString ( ) ] ;
set = > Configuration . CustomColours [ CatchSkinColour . HyperDashFruit . ToString ( ) ] = value ;
}
2020-03-26 10:30:59 +08:00
2020-04-19 18:41:00 +08:00
public TestSkin ( )
: base ( new SkinInfo ( ) , null , null , string . Empty )
{
2020-03-26 10:30:59 +08:00
}
}
}
}