2019-11-01 05:52:33 +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;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2019-11-01 06:13:50 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables.Connections;
|
2019-11-01 05:52:33 +00:00
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Tests
|
|
|
|
{
|
|
|
|
public class TestSceneFollowPoints : OsuTestScene
|
|
|
|
{
|
2019-11-01 06:17:51 +00:00
|
|
|
private Container<DrawableOsuHitObject> hitObjectContainer;
|
2019-11-01 05:52:33 +00:00
|
|
|
private FollowPointRenderer followPointRenderer;
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2019-11-05 10:31:58 +00:00
|
|
|
hitObjectContainer = new TestHitObjectContainer { RelativeSizeAxes = Axes.Both },
|
2019-11-01 05:52:33 +00:00
|
|
|
followPointRenderer = new FollowPointRenderer { RelativeSizeAxes = Axes.Both }
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
[Test]
|
2019-11-05 13:50:01 +00:00
|
|
|
public void TestAddObject()
|
2019-11-01 05:52:33 +00:00
|
|
|
{
|
2019-11-05 10:31:58 +00:00
|
|
|
addObjectsStep(() => new OsuHitObject[] { new HitCircle { Position = new Vector2(100, 100) } });
|
|
|
|
|
|
|
|
assertGroups();
|
2019-11-01 05:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2019-11-05 13:50:01 +00:00
|
|
|
public void TestRemoveObject()
|
2019-11-01 05:52:33 +00:00
|
|
|
{
|
2019-11-05 10:31:58 +00:00
|
|
|
addObjectsStep(() => new OsuHitObject[] { new HitCircle { Position = new Vector2(100, 100) } });
|
|
|
|
|
|
|
|
removeObjectStep(() => getObject(0));
|
2019-11-01 06:12:42 +00:00
|
|
|
|
2019-11-05 10:31:58 +00:00
|
|
|
assertGroups();
|
2019-11-01 05:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2019-11-05 13:50:01 +00:00
|
|
|
public void TestAddMultipleObjects()
|
2019-11-01 05:52:33 +00:00
|
|
|
{
|
2019-11-05 10:31:58 +00:00
|
|
|
addMultipleObjectsStep();
|
|
|
|
|
|
|
|
assertGroups();
|
2019-11-01 05:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2019-11-05 13:50:01 +00:00
|
|
|
public void TestRemoveEndObject()
|
2019-11-01 05:52:33 +00:00
|
|
|
{
|
2019-11-05 10:31:58 +00:00
|
|
|
addMultipleObjectsStep();
|
2019-11-01 06:12:42 +00:00
|
|
|
|
2019-11-05 10:31:58 +00:00
|
|
|
removeObjectStep(() => getObject(4));
|
2019-11-01 06:12:42 +00:00
|
|
|
|
2019-11-05 10:31:58 +00:00
|
|
|
assertGroups();
|
2019-11-01 05:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2019-11-05 13:50:01 +00:00
|
|
|
public void TestRemoveStartObject()
|
2019-11-01 05:52:33 +00:00
|
|
|
{
|
2019-11-05 10:31:58 +00:00
|
|
|
addMultipleObjectsStep();
|
2019-11-01 06:12:42 +00:00
|
|
|
|
2019-11-05 10:31:58 +00:00
|
|
|
removeObjectStep(() => getObject(0));
|
2019-11-01 06:12:42 +00:00
|
|
|
|
2019-11-05 10:31:58 +00:00
|
|
|
assertGroups();
|
2019-11-01 05:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2019-11-05 13:50:01 +00:00
|
|
|
public void TestRemoveMiddleObject()
|
2019-11-01 05:52:33 +00:00
|
|
|
{
|
2019-11-05 10:31:58 +00:00
|
|
|
addMultipleObjectsStep();
|
2019-11-01 06:12:42 +00:00
|
|
|
|
2019-11-05 10:31:58 +00:00
|
|
|
removeObjectStep(() => getObject(2));
|
2019-11-01 06:12:42 +00:00
|
|
|
|
2019-11-05 10:31:58 +00:00
|
|
|
assertGroups();
|
2019-11-01 06:12:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2019-11-05 13:50:01 +00:00
|
|
|
public void TestMoveObject()
|
2019-11-01 06:12:42 +00:00
|
|
|
{
|
2019-11-05 10:31:58 +00:00
|
|
|
addMultipleObjectsStep();
|
2019-11-01 06:12:42 +00:00
|
|
|
|
2019-11-05 10:31:58 +00:00
|
|
|
AddStep("move hitobject", () => getObject(2).HitObject.Position = new Vector2(300, 100));
|
2019-11-01 06:12:42 +00:00
|
|
|
|
2019-11-05 10:31:58 +00:00
|
|
|
assertGroups();
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(0, 0)] // Start -> Start
|
|
|
|
[TestCase(0, 2)] // Start -> Middle
|
|
|
|
[TestCase(0, 5)] // Start -> End
|
|
|
|
[TestCase(2, 0)] // Middle -> Start
|
|
|
|
[TestCase(1, 3)] // Middle -> Middle (forwards)
|
|
|
|
[TestCase(3, 1)] // Middle -> Middle (backwards)
|
|
|
|
[TestCase(4, 0)] // End -> Start
|
|
|
|
[TestCase(4, 2)] // End -> Middle
|
|
|
|
[TestCase(4, 4)] // End -> End
|
2019-11-05 13:50:01 +00:00
|
|
|
public void TestReorderObjects(int startIndex, int endIndex)
|
2019-11-05 10:31:58 +00:00
|
|
|
{
|
|
|
|
addMultipleObjectsStep();
|
|
|
|
|
|
|
|
reorderObjectStep(startIndex, endIndex);
|
|
|
|
|
|
|
|
assertGroups();
|
2019-11-01 05:52:33 +00:00
|
|
|
}
|
|
|
|
|
2019-11-05 10:31:58 +00:00
|
|
|
private void addMultipleObjectsStep() => addObjectsStep(() => new OsuHitObject[]
|
|
|
|
{
|
|
|
|
new HitCircle { Position = new Vector2(100, 100) },
|
|
|
|
new HitCircle { Position = new Vector2(200, 200) },
|
|
|
|
new HitCircle { Position = new Vector2(300, 300) },
|
|
|
|
new HitCircle { Position = new Vector2(400, 400) },
|
|
|
|
new HitCircle { Position = new Vector2(500, 500) },
|
|
|
|
});
|
|
|
|
|
|
|
|
private void addObjectsStep(Func<OsuHitObject[]> ctorFunc)
|
2019-11-01 05:52:33 +00:00
|
|
|
{
|
2019-11-01 06:12:42 +00:00
|
|
|
AddStep("add hitobjects", () =>
|
2019-11-01 05:52:33 +00:00
|
|
|
{
|
2019-11-01 06:34:13 +00:00
|
|
|
var objects = ctorFunc();
|
2019-11-01 05:52:33 +00:00
|
|
|
|
2019-11-01 06:34:13 +00:00
|
|
|
for (int i = 0; i < objects.Length; i++)
|
2019-11-01 06:12:42 +00:00
|
|
|
{
|
2019-11-01 06:34:13 +00:00
|
|
|
objects[i].StartTime = Time.Current + 1000 + 500 * (i + 1);
|
|
|
|
objects[i].ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
|
2019-11-01 05:52:33 +00:00
|
|
|
|
2019-11-01 06:34:13 +00:00
|
|
|
DrawableOsuHitObject drawableObject = null;
|
2019-11-01 05:52:33 +00:00
|
|
|
|
2019-11-01 06:34:13 +00:00
|
|
|
switch (objects[i])
|
|
|
|
{
|
|
|
|
case HitCircle circle:
|
|
|
|
drawableObject = new DrawableHitCircle(circle);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Slider slider:
|
|
|
|
drawableObject = new DrawableSlider(slider);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Spinner spinner:
|
|
|
|
drawableObject = new DrawableSpinner(spinner);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
hitObjectContainer.Add(drawableObject);
|
|
|
|
followPointRenderer.AddFollowPoints(drawableObject);
|
2019-11-01 06:12:42 +00:00
|
|
|
}
|
2019-11-01 05:52:33 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-05 10:31:58 +00:00
|
|
|
private void removeObjectStep(Func<DrawableOsuHitObject> getFunc)
|
2019-11-01 05:52:33 +00:00
|
|
|
{
|
|
|
|
AddStep("remove hitobject", () =>
|
|
|
|
{
|
2019-11-01 06:12:42 +00:00
|
|
|
var drawableObject = getFunc?.Invoke();
|
2019-11-01 05:52:33 +00:00
|
|
|
|
|
|
|
hitObjectContainer.Remove(drawableObject);
|
|
|
|
followPointRenderer.RemoveFollowPoints(drawableObject);
|
|
|
|
});
|
|
|
|
}
|
2019-11-05 10:31:58 +00:00
|
|
|
|
|
|
|
private void reorderObjectStep(int startIndex, int endIndex)
|
|
|
|
{
|
|
|
|
AddStep($"move object {startIndex} to {endIndex}", () =>
|
|
|
|
{
|
|
|
|
DrawableOsuHitObject toReorder = getObject(startIndex);
|
|
|
|
|
|
|
|
double targetTime;
|
|
|
|
if (endIndex < hitObjectContainer.Count)
|
|
|
|
targetTime = getObject(endIndex).HitObject.StartTime - 1;
|
|
|
|
else
|
|
|
|
targetTime = getObject(hitObjectContainer.Count - 1).HitObject.StartTime + 1;
|
|
|
|
|
|
|
|
hitObjectContainer.Remove(toReorder);
|
|
|
|
toReorder.HitObject.StartTime = targetTime;
|
|
|
|
hitObjectContainer.Add(toReorder);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void assertGroups()
|
|
|
|
{
|
2019-11-06 07:33:42 +00:00
|
|
|
AddAssert("has correct group count", () => followPointRenderer.Connections.Count == hitObjectContainer.Count);
|
2019-11-05 10:31:58 +00:00
|
|
|
AddAssert("group endpoints are correct", () =>
|
|
|
|
{
|
|
|
|
for (int i = 0; i < hitObjectContainer.Count; i++)
|
|
|
|
{
|
|
|
|
DrawableOsuHitObject expectedStart = getObject(i);
|
|
|
|
DrawableOsuHitObject expectedEnd = i < hitObjectContainer.Count - 1 ? getObject(i + 1) : null;
|
|
|
|
|
|
|
|
if (getGroup(i).Start != expectedStart)
|
|
|
|
throw new AssertionException($"Object {i} expected to be the start of group {i}.");
|
|
|
|
|
|
|
|
if (getGroup(i).End != expectedEnd)
|
|
|
|
throw new AssertionException($"Object {(expectedEnd == null ? "null" : i.ToString())} expected to be the end of group {i}.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private DrawableOsuHitObject getObject(int index) => hitObjectContainer[index];
|
|
|
|
|
2019-11-06 07:33:42 +00:00
|
|
|
private FollowPointConnection getGroup(int index) => followPointRenderer.Connections[index];
|
2019-11-05 10:31:58 +00:00
|
|
|
|
|
|
|
private class TestHitObjectContainer : Container<DrawableOsuHitObject>
|
|
|
|
{
|
|
|
|
protected override int Compare(Drawable x, Drawable y)
|
|
|
|
{
|
|
|
|
var osuX = (DrawableOsuHitObject)x;
|
|
|
|
var osuY = (DrawableOsuHitObject)y;
|
|
|
|
|
|
|
|
int compare = osuX.HitObject.StartTime.CompareTo(osuY.HitObject.StartTime);
|
|
|
|
|
|
|
|
if (compare == 0)
|
|
|
|
return base.Compare(x, y);
|
|
|
|
|
|
|
|
return compare;
|
|
|
|
}
|
|
|
|
}
|
2019-11-01 05:52:33 +00:00
|
|
|
}
|
|
|
|
}
|