2019-01-24 08:43:03 +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.
2018-10-25 10:34:35 +00:00
2020-04-13 06:31:54 +00:00
using NUnit.Framework ;
using osu.Framework.Utils ;
2018-10-25 10:34:35 +00:00
using osu.Game.Rulesets.Edit ;
using osu.Game.Rulesets.Objects ;
using osu.Game.Rulesets.Objects.Drawables ;
2020-04-13 06:31:54 +00:00
using osu.Game.Rulesets.Objects.Types ;
2018-11-07 07:08:56 +00:00
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders ;
2018-10-25 10:34:35 +00:00
using osu.Game.Rulesets.Osu.Objects ;
using osu.Game.Rulesets.Osu.Objects.Drawables ;
using osu.Game.Tests.Visual ;
2020-04-13 06:31:54 +00:00
using osuTK ;
using osuTK.Input ;
2018-10-25 10:34:35 +00:00
2020-09-25 09:48:04 +00:00
namespace osu.Game.Rulesets.Osu.Tests.Editor
2018-10-25 10:34:35 +00:00
{
2019-05-14 19:37:25 +00:00
public class TestSceneSliderPlacementBlueprint : PlacementBlueprintTestScene
2018-10-25 10:34:35 +00:00
{
2020-04-13 06:31:54 +00:00
[SetUp]
public void Setup ( ) = > Schedule ( ( ) = >
{
HitObjectContainer . Clear ( ) ;
ResetPlacement ( ) ;
} ) ;
[Test]
public void TestBeginPlacementWithoutFinishing ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
assertPlaced ( false ) ;
}
[Test]
public void TestPlaceWithoutMovingMouse ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertLength ( 0 ) ;
assertControlPointType ( 0 , PathType . Linear ) ;
}
[Test]
public void TestPlaceWithMouseMovement ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 400 , 200 ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertLength ( 200 ) ;
assertControlPointCount ( 2 ) ;
assertControlPointType ( 0 , PathType . Linear ) ;
}
[Test]
public void TestPlaceNormalControlPoint ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 3 ) ;
assertControlPointPosition ( 1 , new Vector2 ( 100 , 0 ) ) ;
assertControlPointType ( 0 , PathType . PerfectCurve ) ;
}
[Test]
public void TestPlaceTwoNormalControlPoints ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 400 , 300 ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 4 ) ;
assertControlPointPosition ( 1 , new Vector2 ( 100 , 0 ) ) ;
assertControlPointPosition ( 2 , new Vector2 ( 100 , 100 ) ) ;
assertControlPointType ( 0 , PathType . Bezier ) ;
}
[Test]
public void TestPlaceSegmentControlPoint ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 3 ) ;
assertControlPointPosition ( 1 , new Vector2 ( 100 , 0 ) ) ;
assertControlPointType ( 0 , PathType . Linear ) ;
assertControlPointType ( 1 , PathType . Linear ) ;
}
[Test]
public void TestMoveToPerfectCurveThenPlaceLinear ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 ) ) ;
addMovementStep ( new Vector2 ( 300 , 200 ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 2 ) ;
assertControlPointType ( 0 , PathType . Linear ) ;
assertLength ( 100 ) ;
}
[Test]
public void TestMoveToBezierThenPlacePerfectCurve ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 400 , 300 ) ) ;
addMovementStep ( new Vector2 ( 300 ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 3 ) ;
assertControlPointType ( 0 , PathType . PerfectCurve ) ;
}
[Test]
public void TestMoveToFourthOrderBezierThenPlaceThirdOrderBezier ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 400 , 300 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 400 ) ) ;
addMovementStep ( new Vector2 ( 400 , 300 ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 4 ) ;
assertControlPointType ( 0 , PathType . Bezier ) ;
}
[Test]
public void TestPlaceLinearSegmentThenPlaceLinearSegment ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 300 ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 3 ) ;
assertControlPointPosition ( 1 , new Vector2 ( 100 , 0 ) ) ;
assertControlPointPosition ( 2 , new Vector2 ( 100 ) ) ;
assertControlPointType ( 0 , PathType . Linear ) ;
assertControlPointType ( 1 , PathType . Linear ) ;
}
[Test]
public void TestPlaceLinearSegmentThenPlacePerfectCurveSegment ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 300 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 400 , 300 ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 4 ) ;
assertControlPointPosition ( 1 , new Vector2 ( 100 , 0 ) ) ;
assertControlPointPosition ( 2 , new Vector2 ( 100 ) ) ;
assertControlPointType ( 0 , PathType . Linear ) ;
assertControlPointType ( 1 , PathType . PerfectCurve ) ;
}
[Test]
public void TestPlacePerfectCurveSegmentThenPlacePerfectCurveSegment ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 200 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 300 , 300 ) ) ;
addClickStep ( MouseButton . Left ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 400 , 300 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 400 ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 5 ) ;
assertControlPointPosition ( 1 , new Vector2 ( 100 , 0 ) ) ;
assertControlPointPosition ( 2 , new Vector2 ( 100 ) ) ;
assertControlPointPosition ( 3 , new Vector2 ( 200 , 100 ) ) ;
assertControlPointPosition ( 4 , new Vector2 ( 200 ) ) ;
assertControlPointType ( 0 , PathType . PerfectCurve ) ;
assertControlPointType ( 2 , PathType . PerfectCurve ) ;
}
2020-04-23 03:17:11 +00:00
[Test]
public void TestBeginPlacementWithoutReleasingMouse ( )
{
addMovementStep ( new Vector2 ( 200 ) ) ;
AddStep ( "press left button" , ( ) = > InputManager . PressButton ( MouseButton . Left ) ) ;
addMovementStep ( new Vector2 ( 400 , 200 ) ) ;
AddStep ( "release left button" , ( ) = > InputManager . ReleaseButton ( MouseButton . Left ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertLength ( 200 ) ;
assertControlPointCount ( 2 ) ;
assertControlPointType ( 0 , PathType . Linear ) ;
}
2021-03-24 04:15:50 +00:00
[Test]
public void TestPlacePerfectCurveSegmentAlmostLinearlyExterior ( )
{
Vector2 startPosition = new Vector2 ( 200 ) ;
addMovementStep ( startPosition ) ;
addClickStep ( MouseButton . Left ) ;
2021-03-24 04:14:35 +00:00
addMovementStep ( startPosition + new Vector2 ( 300 , 0 ) ) ;
2021-03-21 05:30:17 +00:00
addClickStep ( MouseButton . Left ) ;
2021-03-24 04:14:35 +00:00
addMovementStep ( startPosition + new Vector2 ( 150 , 0.1f ) ) ;
2021-03-21 05:30:17 +00:00
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 3 ) ;
2021-03-22 14:59:45 +00:00
assertControlPointType ( 0 , PathType . Bezier ) ;
2021-03-21 05:30:17 +00:00
}
2021-03-22 14:59:59 +00:00
[Test]
2021-03-24 04:15:28 +00:00
public void TestPlacePerfectCurveSegmentRecovery ( )
2021-03-22 14:59:59 +00:00
{
2021-03-24 04:14:35 +00:00
Vector2 startPosition = new Vector2 ( 200 ) ;
addMovementStep ( startPosition ) ;
2021-03-22 14:59:59 +00:00
addClickStep ( MouseButton . Left ) ;
2021-03-31 18:08:39 +00:00
addMovementStep ( startPosition + new Vector2 ( 300 , 0 ) ) ;
2021-03-22 14:59:59 +00:00
addClickStep ( MouseButton . Left ) ;
2021-03-31 18:08:39 +00:00
addMovementStep ( startPosition + new Vector2 ( 150 , 0.1f ) ) ; // Should convert to bezier
2021-03-31 18:48:17 +00:00
addMovementStep ( startPosition + new Vector2 ( 400.0f , 50.0f ) ) ; // Should convert back to perfect
2021-03-22 14:59:59 +00:00
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 3 ) ;
assertControlPointType ( 0 , PathType . PerfectCurve ) ;
}
2021-03-24 04:54:48 +00:00
[Test]
public void TestPlacePerfectCurveSegmentLarge ( )
{
2021-03-24 16:24:05 +00:00
Vector2 startPosition = new Vector2 ( 400 ) ;
addMovementStep ( startPosition ) ;
2021-03-24 04:54:48 +00:00
addClickStep ( MouseButton . Left ) ;
2021-04-01 18:34:04 +00:00
addMovementStep ( startPosition + new Vector2 ( 220 , 220 ) ) ;
2021-03-24 04:54:48 +00:00
addClickStep ( MouseButton . Left ) ;
2021-03-24 16:24:05 +00:00
// Playfield dimensions are 640 x 480.
2021-04-01 18:34:04 +00:00
// So a 440 x 440 bounding box should be ok.
addMovementStep ( startPosition + new Vector2 ( - 220 , 220 ) ) ;
2021-03-24 04:54:48 +00:00
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 3 ) ;
assertControlPointType ( 0 , PathType . PerfectCurve ) ;
}
[Test]
public void TestPlacePerfectCurveSegmentTooLarge ( )
{
2021-03-24 16:24:05 +00:00
Vector2 startPosition = new Vector2 ( 480 , 200 ) ;
addMovementStep ( startPosition ) ;
2021-03-24 04:54:48 +00:00
addClickStep ( MouseButton . Left ) ;
2021-03-24 16:24:05 +00:00
addMovementStep ( startPosition + new Vector2 ( 400 , 400 ) ) ;
2021-03-24 04:54:48 +00:00
addClickStep ( MouseButton . Left ) ;
2021-03-24 16:24:05 +00:00
// Playfield dimensions are 640 x 480.
// So an 800 * 800 bounding box area should not be ok.
addMovementStep ( startPosition + new Vector2 ( - 400 , 400 ) ) ;
2021-03-24 04:54:48 +00:00
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 3 ) ;
assertControlPointType ( 0 , PathType . Bezier ) ;
}
2021-03-24 16:24:33 +00:00
[Test]
public void TestPlacePerfectCurveSegmentCompleteArc ( )
{
addMovementStep ( new Vector2 ( 400 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 600 , 400 ) ) ;
addClickStep ( MouseButton . Left ) ;
addMovementStep ( new Vector2 ( 400 , 410 ) ) ;
addClickStep ( MouseButton . Right ) ;
assertPlaced ( true ) ;
assertControlPointCount ( 3 ) ;
assertControlPointType ( 0 , PathType . PerfectCurve ) ;
}
2020-04-13 06:31:54 +00:00
private void addMovementStep ( Vector2 position ) = > AddStep ( $"move mouse to {position}" , ( ) = > InputManager . MoveMouseTo ( InputManager . ToScreenSpace ( position ) ) ) ;
private void addClickStep ( MouseButton button )
{
2020-11-05 14:41:56 +00:00
AddStep ( $"click {button}" , ( ) = > InputManager . Click ( button ) ) ;
2020-04-13 06:31:54 +00:00
}
private void assertPlaced ( bool expected ) = > AddAssert ( $"slider {(expected ? " placed " : " not placed ")}" , ( ) = > ( getSlider ( ) ! = null ) = = expected ) ;
private void assertLength ( double expected ) = > AddAssert ( $"slider length is {expected}" , ( ) = > Precision . AlmostEquals ( expected , getSlider ( ) . Distance , 1 ) ) ;
private void assertControlPointCount ( int expected ) = > AddAssert ( $"has {expected} control points" , ( ) = > getSlider ( ) . Path . ControlPoints . Count = = expected ) ;
private void assertControlPointType ( int index , PathType type ) = > AddAssert ( $"control point {index} is {type}" , ( ) = > getSlider ( ) . Path . ControlPoints [ index ] . Type . Value = = type ) ;
private void assertControlPointPosition ( int index , Vector2 position ) = >
AddAssert ( $"control point {index} at {position}" , ( ) = > Precision . AlmostEquals ( position , getSlider ( ) . Path . ControlPoints [ index ] . Position . Value , 1 ) ) ;
2020-11-05 04:51:46 +00:00
private Slider getSlider ( ) = > HitObjectContainer . Count > 0 ? ( ( DrawableSlider ) HitObjectContainer [ 0 ] ) . HitObject : null ;
2020-04-13 06:31:54 +00:00
2018-10-25 10:34:35 +00:00
protected override DrawableHitObject CreateHitObject ( HitObject hitObject ) = > new DrawableSlider ( ( Slider ) hitObject ) ;
2018-11-07 06:04:48 +00:00
protected override PlacementBlueprint CreateBlueprint ( ) = > new SliderPlacementBlueprint ( ) ;
2018-10-25 10:34:35 +00:00
}
}