1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-24 12:43:06 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneSliderReversal.cs

111 lines
3.7 KiB
C#
Raw Normal View History

2023-08-14 20:14:11 +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;
2023-08-15 04:09:12 +08:00
using osu.Framework.Utils;
2023-08-14 20:14:11 +08:00
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Tests.Beatmaps;
using osuTK;
using osuTK.Input;
namespace osu.Game.Rulesets.Osu.Tests.Editor
{
public partial class TestSceneSliderReversal : TestSceneOsuEditor
{
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestBeatmap(Ruleset.Value, false);
private readonly PathControlPoint[][] paths =
{
createPathSegment(
2023-11-13 15:24:09 +08:00
PathType.PERFECT_CURVE,
2023-08-14 20:14:11 +08:00
new Vector2(200, -50),
new Vector2(250, 0)
),
createPathSegment(
PathType.LINEAR,
2023-08-14 20:14:11 +08:00
new Vector2(100, 0),
new Vector2(100, 100)
)
};
private static PathControlPoint[] createPathSegment(PathType type, params Vector2[] positions)
{
2023-08-15 03:56:08 +08:00
return positions.Select(p => new PathControlPoint
2023-08-14 20:14:11 +08:00
{
Position = p
2023-08-15 03:56:08 +08:00
}).Prepend(new PathControlPoint
{
Type = type
}).ToArray();
2023-08-14 20:14:11 +08:00
}
2023-08-15 04:41:25 +08:00
private Slider selectedSlider => (Slider)EditorBeatmap.SelectedHitObjects[0];
2023-08-15 04:09:12 +08:00
2023-08-14 20:14:11 +08:00
[TestCase(0, 250)]
[TestCase(0, 200)]
[TestCase(1, 120)]
[TestCase(1, 80)]
2023-08-14 20:14:11 +08:00
public void TestSliderReversal(int pathIndex, double length)
{
var controlPoints = paths[pathIndex];
Vector2 oldStartPos = default;
Vector2 oldEndPos = default;
double oldDistance = default;
var oldControlPointTypes = controlPoints.Select(p => p.Type);
2023-08-14 20:14:11 +08:00
AddStep("Add slider", () =>
{
var slider = new Slider
{
Position = new Vector2(OsuPlayfield.BASE_SIZE.X / 2, OsuPlayfield.BASE_SIZE.Y / 2),
Path = new SliderPath(controlPoints)
{
ExpectedDistance = { Value = length }
}
};
EditorBeatmap.Add(slider);
oldStartPos = slider.Position;
oldEndPos = slider.EndPosition;
oldDistance = slider.Path.Distance;
});
AddStep("Select slider", () =>
{
var slider = (Slider)EditorBeatmap.HitObjects[0];
EditorBeatmap.SelectedHitObjects.Add(slider);
});
AddStep("Reverse slider", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
2023-08-15 04:09:12 +08:00
AddAssert("Slider has correct length", () =>
2023-08-15 04:41:25 +08:00
Precision.AlmostEquals(selectedSlider.Path.Distance, oldDistance));
2023-08-15 04:09:12 +08:00
AddAssert("Slider has correct start position", () =>
2023-08-15 04:41:25 +08:00
Vector2.Distance(selectedSlider.Position, oldEndPos) < 1);
2023-08-15 04:09:12 +08:00
AddAssert("Slider has correct end position", () =>
2023-08-15 04:41:25 +08:00
Vector2.Distance(selectedSlider.EndPosition, oldStartPos) < 1);
AddAssert("Control points have correct types", () =>
{
var newControlPointTypes = selectedSlider.Path.ControlPoints.Select(p => p.Type).ToArray();
return oldControlPointTypes.Take(newControlPointTypes.Length).SequenceEqual(newControlPointTypes);
});
2023-08-14 20:14:11 +08:00
}
}
}