2021-07-08 14:42:29 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-07-19 21:33:03 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Framework.Utils;
|
2021-07-08 14:42:29 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Edit.Blueprints;
|
2021-07-19 21:33:03 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Edit.Blueprints.Components;
|
2021-07-08 14:42:29 +08:00
|
|
|
using osu.Game.Rulesets.Catch.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
using osuTK;
|
2021-07-19 21:33:03 +08:00
|
|
|
using osuTK.Input;
|
2021-07-08 14:42:29 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.Tests.Editor
|
|
|
|
{
|
|
|
|
public partial class TestSceneJuiceStreamSelectionBlueprint : CatchSelectionBlueprintTestScene
|
|
|
|
{
|
2021-07-19 21:33:03 +08:00
|
|
|
private JuiceStream hitObject;
|
|
|
|
|
|
|
|
private readonly ManualClock manualClock = new ManualClock();
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void SetUp() => Schedule(() =>
|
|
|
|
{
|
|
|
|
EditorBeatmap.Clear();
|
|
|
|
Content.Clear();
|
|
|
|
|
|
|
|
manualClock.CurrentTime = 0;
|
|
|
|
Content.Clock = new FramedClock(manualClock);
|
|
|
|
|
|
|
|
InputManager.ReleaseButton(MouseButton.Left);
|
|
|
|
InputManager.ReleaseKey(Key.ShiftLeft);
|
|
|
|
InputManager.ReleaseKey(Key.ControlLeft);
|
|
|
|
});
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestBasicComponentLayout()
|
|
|
|
{
|
|
|
|
double[] times = { 100, 300, 500 };
|
|
|
|
float[] positions = { 100, 200, 100 };
|
|
|
|
addBlueprintStep(times, positions);
|
|
|
|
|
|
|
|
for (int i = 0; i < times.Length; i++)
|
|
|
|
addVertexCheckStep(times.Length, i, times[i], positions[i]);
|
|
|
|
|
|
|
|
AddAssert("correct outline count", () =>
|
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
int expected = hitObject.NestedHitObjects.Count(h => !(h is TinyDroplet));
|
2021-07-19 21:33:03 +08:00
|
|
|
return this.ChildrenOfType<FruitOutline>().Count() == expected;
|
|
|
|
});
|
|
|
|
AddAssert("correct vertex piece count", () =>
|
|
|
|
this.ChildrenOfType<VertexPiece>().Count() == times.Length);
|
|
|
|
|
|
|
|
AddAssert("first vertex is semitransparent", () =>
|
|
|
|
Precision.DefinitelyBigger(1, this.ChildrenOfType<VertexPiece>().First().Alpha));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestVertexDrag()
|
|
|
|
{
|
|
|
|
double[] times = { 100, 400, 700 };
|
|
|
|
float[] positions = { 100, 100, 100 };
|
|
|
|
addBlueprintStep(times, positions);
|
|
|
|
|
|
|
|
addDragStartStep(times[1], positions[1]);
|
|
|
|
|
|
|
|
AddMouseMoveStep(500, 150);
|
|
|
|
addVertexCheckStep(3, 1, 500, 150);
|
|
|
|
|
|
|
|
addDragEndStep();
|
|
|
|
addDragStartStep(times[2], positions[2]);
|
|
|
|
|
|
|
|
AddMouseMoveStep(300, 50);
|
|
|
|
addVertexCheckStep(3, 1, 300, 50);
|
|
|
|
addVertexCheckStep(3, 2, 500, 150);
|
|
|
|
|
|
|
|
AddMouseMoveStep(-100, 100);
|
|
|
|
addVertexCheckStep(3, 1, times[0], positions[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMultipleDrag()
|
|
|
|
{
|
|
|
|
double[] times = { 100, 300, 500, 700 };
|
|
|
|
float[] positions = { 100, 100, 100, 100 };
|
|
|
|
addBlueprintStep(times, positions);
|
|
|
|
|
|
|
|
AddMouseMoveStep(times[1], positions[1]);
|
|
|
|
AddStep("press left", () => InputManager.PressButton(MouseButton.Left));
|
|
|
|
AddStep("release left", () => InputManager.ReleaseButton(MouseButton.Left));
|
|
|
|
AddStep("hold control", () => InputManager.PressKey(Key.ControlLeft));
|
|
|
|
addDragStartStep(times[2], positions[2]);
|
|
|
|
|
|
|
|
AddMouseMoveStep(times[2] - 50, positions[2] - 50);
|
|
|
|
addVertexCheckStep(4, 1, times[1] - 50, positions[1] - 50);
|
|
|
|
addVertexCheckStep(4, 2, times[2] - 50, positions[2] - 50);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2022-05-08 21:33:16 +08:00
|
|
|
public void TestSliderVelocityChange()
|
2021-07-19 21:33:03 +08:00
|
|
|
{
|
2022-05-08 21:33:16 +08:00
|
|
|
double[] times = { 100, 300 };
|
|
|
|
float[] positions = { 200, 300 };
|
|
|
|
addBlueprintStep(times, positions);
|
|
|
|
AddAssert("default slider velocity", () => hitObject.DifficultyControlPoint.SliderVelocityBindable.IsDefault);
|
2021-07-19 21:33:03 +08:00
|
|
|
|
|
|
|
addDragStartStep(times[1], positions[1]);
|
2022-05-08 21:33:16 +08:00
|
|
|
AddMouseMoveStep(times[1], 400);
|
|
|
|
AddAssert("slider velocity changed", () => !hitObject.DifficultyControlPoint.SliderVelocityBindable.IsDefault);
|
2021-07-19 21:33:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestScrollWhileDrag()
|
2021-07-08 14:42:29 +08:00
|
|
|
{
|
2021-07-19 21:33:03 +08:00
|
|
|
double[] times = { 300, 500 };
|
|
|
|
float[] positions = { 100, 100 };
|
|
|
|
addBlueprintStep(times, positions);
|
|
|
|
|
|
|
|
addDragStartStep(times[1], positions[1]);
|
|
|
|
// This mouse move is necessary to start drag and capture the input.
|
|
|
|
AddMouseMoveStep(times[1], positions[1] + 50);
|
|
|
|
|
|
|
|
AddStep("scroll playfield", () => manualClock.CurrentTime += 200);
|
|
|
|
AddMouseMoveStep(times[1] + 200, positions[1] + 100);
|
|
|
|
addVertexCheckStep(2, 1, times[1] + 200, positions[1] + 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestUpdateFromHitObject()
|
|
|
|
{
|
|
|
|
double[] times = { 100, 300 };
|
|
|
|
float[] positions = { 200, 200 };
|
|
|
|
addBlueprintStep(times, positions);
|
|
|
|
|
|
|
|
AddStep("update hit object path", () =>
|
2021-07-08 14:42:29 +08:00
|
|
|
{
|
2021-07-19 21:33:03 +08:00
|
|
|
hitObject.Path = new SliderPath(PathType.PerfectCurve, new[]
|
2021-07-08 14:42:29 +08:00
|
|
|
{
|
|
|
|
Vector2.Zero,
|
2021-07-19 21:33:03 +08:00
|
|
|
new Vector2(100, 100),
|
2021-07-08 14:42:29 +08:00
|
|
|
new Vector2(0, 200),
|
2021-07-19 21:33:03 +08:00
|
|
|
});
|
|
|
|
EditorBeatmap.Update(hitObject);
|
2021-07-08 14:42:29 +08:00
|
|
|
});
|
2021-07-19 21:33:03 +08:00
|
|
|
AddAssert("path is updated", () => getVertices().Count > 2);
|
|
|
|
}
|
|
|
|
|
2021-07-19 21:43:28 +08:00
|
|
|
[Test]
|
|
|
|
public void TestAddVertex()
|
|
|
|
{
|
|
|
|
double[] times = { 100, 700 };
|
|
|
|
float[] positions = { 200, 200 };
|
|
|
|
addBlueprintStep(times, positions, 0.2);
|
|
|
|
|
|
|
|
addAddVertexSteps(500, 150);
|
|
|
|
addVertexCheckStep(3, 1, 500, 150);
|
|
|
|
|
2022-05-08 21:33:16 +08:00
|
|
|
addAddVertexSteps(90, 200);
|
2021-07-19 21:43:28 +08:00
|
|
|
addVertexCheckStep(4, 1, times[0], positions[0]);
|
|
|
|
|
|
|
|
addAddVertexSteps(750, 180);
|
|
|
|
addVertexCheckStep(5, 4, 750, 180);
|
|
|
|
AddAssert("duration is changed", () => Precision.AlmostEquals(hitObject.Duration, 800 - times[0], 1e-3));
|
|
|
|
}
|
|
|
|
|
2021-07-19 21:46:32 +08:00
|
|
|
[Test]
|
|
|
|
public void TestDeleteVertex()
|
|
|
|
{
|
|
|
|
double[] times = { 100, 300, 500 };
|
|
|
|
float[] positions = { 100, 200, 150 };
|
|
|
|
addBlueprintStep(times, positions);
|
|
|
|
|
|
|
|
addDeleteVertexSteps(times[1], positions[1]);
|
|
|
|
addVertexCheckStep(2, 1, times[2], positions[2]);
|
|
|
|
|
|
|
|
// The first vertex cannot be deleted.
|
|
|
|
addDeleteVertexSteps(times[0], positions[0]);
|
|
|
|
addVertexCheckStep(2, 0, times[0], positions[0]);
|
|
|
|
|
|
|
|
addDeleteVertexSteps(times[2], positions[2]);
|
|
|
|
addVertexCheckStep(1, 0, times[0], positions[0]);
|
|
|
|
}
|
|
|
|
|
2021-07-19 21:49:03 +08:00
|
|
|
[Test]
|
|
|
|
public void TestVertexResampling()
|
|
|
|
{
|
|
|
|
addBlueprintStep(100, 100, new SliderPath(PathType.PerfectCurve, new[]
|
|
|
|
{
|
|
|
|
Vector2.Zero,
|
|
|
|
new Vector2(100, 100),
|
|
|
|
new Vector2(50, 200),
|
|
|
|
}), 0.5);
|
|
|
|
AddAssert("1 vertex per 1 nested HO", () => getVertices().Count == hitObject.NestedHitObjects.Count);
|
2021-08-26 13:02:56 +08:00
|
|
|
AddAssert("slider path not yet changed", () => hitObject.Path.ControlPoints[0].Type == PathType.PerfectCurve);
|
2021-07-19 21:49:03 +08:00
|
|
|
addAddVertexSteps(150, 150);
|
2021-08-26 13:02:56 +08:00
|
|
|
AddAssert("slider path change to linear", () => hitObject.Path.ControlPoints[0].Type == PathType.Linear);
|
2021-07-19 21:49:03 +08:00
|
|
|
}
|
|
|
|
|
2021-07-19 21:33:03 +08:00
|
|
|
private void addBlueprintStep(double time, float x, SliderPath sliderPath, double velocity) => AddStep("add selection blueprint", () =>
|
|
|
|
{
|
|
|
|
hitObject = new JuiceStream
|
|
|
|
{
|
|
|
|
StartTime = time,
|
|
|
|
X = x,
|
|
|
|
Path = sliderPath,
|
|
|
|
};
|
2021-10-02 11:34:29 +08:00
|
|
|
EditorBeatmap.Difficulty.SliderMultiplier = velocity;
|
2021-07-19 21:33:03 +08:00
|
|
|
EditorBeatmap.Add(hitObject);
|
|
|
|
EditorBeatmap.Update(hitObject);
|
|
|
|
Assert.That(hitObject.Velocity, Is.EqualTo(velocity));
|
2021-07-08 14:42:29 +08:00
|
|
|
AddBlueprint(new JuiceStreamSelectionBlueprint(hitObject));
|
2021-07-19 21:33:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
private void addBlueprintStep(double[] times, float[] positions, double velocity = 0.5)
|
|
|
|
{
|
|
|
|
var path = new JuiceStreamPath();
|
|
|
|
for (int i = 1; i < times.Length; i++)
|
2022-05-08 17:32:01 +08:00
|
|
|
path.Add(times[i] - times[0], positions[i] - positions[0]);
|
2021-07-19 21:33:03 +08:00
|
|
|
|
|
|
|
var sliderPath = new SliderPath();
|
2022-05-08 17:32:01 +08:00
|
|
|
path.ConvertToSliderPath(sliderPath, 0, velocity);
|
2021-07-19 21:33:03 +08:00
|
|
|
addBlueprintStep(times[0], positions[0], sliderPath, velocity);
|
2021-07-08 14:42:29 +08:00
|
|
|
}
|
2021-07-19 21:33:03 +08:00
|
|
|
|
|
|
|
private IReadOnlyList<JuiceStreamPathVertex> getVertices() => this.ChildrenOfType<EditablePath>().Single().Vertices;
|
|
|
|
|
|
|
|
private void addVertexCheckStep(int count, int index, double time, float x) => AddAssert($"vertex {index} of {count} at {time}, {x}", () =>
|
|
|
|
{
|
2022-05-08 17:32:01 +08:00
|
|
|
double expectedTime = time - hitObject.StartTime;
|
2021-07-19 21:33:03 +08:00
|
|
|
float expectedX = x - hitObject.OriginalX;
|
|
|
|
var vertices = getVertices();
|
|
|
|
return vertices.Count == count &&
|
2022-05-08 17:32:01 +08:00
|
|
|
Precision.AlmostEquals(vertices[index].Time, expectedTime, 1e-3) &&
|
2021-07-19 21:33:03 +08:00
|
|
|
Precision.AlmostEquals(vertices[index].X, expectedX);
|
|
|
|
});
|
|
|
|
|
|
|
|
private void addDragStartStep(double time, float x)
|
|
|
|
{
|
|
|
|
AddMouseMoveStep(time, x);
|
|
|
|
AddStep("start dragging", () => InputManager.PressButton(MouseButton.Left));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addDragEndStep() => AddStep("end dragging", () => InputManager.ReleaseButton(MouseButton.Left));
|
2021-07-19 21:43:28 +08:00
|
|
|
|
|
|
|
private void addAddVertexSteps(double time, float x)
|
|
|
|
{
|
|
|
|
AddMouseMoveStep(time, x);
|
|
|
|
AddStep("add vertex", () =>
|
|
|
|
{
|
|
|
|
InputManager.PressKey(Key.ControlLeft);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
InputManager.ReleaseKey(Key.ControlLeft);
|
|
|
|
});
|
|
|
|
}
|
2021-07-19 21:46:32 +08:00
|
|
|
|
|
|
|
private void addDeleteVertexSteps(double time, float x)
|
|
|
|
{
|
|
|
|
AddMouseMoveStep(time, x);
|
|
|
|
AddStep("delete vertex", () =>
|
|
|
|
{
|
|
|
|
InputManager.PressKey(Key.ShiftLeft);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
InputManager.ReleaseKey(Key.ShiftLeft);
|
|
|
|
});
|
|
|
|
}
|
2021-07-08 14:42:29 +08:00
|
|
|
}
|
|
|
|
}
|