1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 20:22:55 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/Editor/TestSceneOsuReverseSelection.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

301 lines
10 KiB
C#
Raw Normal View History

2024-03-27 19:22:51 +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.
2024-03-28 17:05:26 +08:00
using System.Collections.Generic;
2024-03-27 19:22:51 +08:00
using System.Linq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Tests.Beatmaps;
using osuTK;
using osuTK.Input;
namespace osu.Game.Rulesets.Osu.Tests.Editor
{
[TestFixture]
public partial class TestSceneOsuReverseSelection : TestSceneOsuEditor
{
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestBeatmap(ruleset, false);
[Test]
public void TestReverseSelectionTwoCircles()
{
2024-03-28 17:05:26 +08:00
OsuHitObject[] objects = null!;
bool[] newCombos = null!;
2024-03-27 19:22:51 +08:00
AddStep("Add circles", () =>
{
var circle1 = new HitCircle
{
StartTime = 0,
2024-03-28 17:05:26 +08:00
Position = new Vector2(208, 240)
2024-03-27 19:22:51 +08:00
};
var circle2 = new HitCircle
{
StartTime = 200,
2024-03-28 17:05:26 +08:00
Position = new Vector2(256, 144)
2024-03-27 19:22:51 +08:00
};
EditorBeatmap.AddRange([circle1, circle2]);
});
2024-03-28 17:05:26 +08:00
AddStep("store objects & new combo data", () =>
2024-03-27 19:22:51 +08:00
{
2024-03-28 17:05:26 +08:00
objects = getObjects().ToArray();
newCombos = getObjectNewCombos().ToArray();
2024-03-27 19:22:51 +08:00
});
2024-03-28 17:05:26 +08:00
AddStep("Select circles", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
2024-03-27 19:22:51 +08:00
AddStep("Reverse selection", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
2024-03-28 17:05:26 +08:00
AddAssert("objects reversed", getObjects, () => Is.EqualTo(objects.Reverse()));
AddAssert("new combo positions preserved", getObjectNewCombos, () => Is.EqualTo(newCombos));
2024-03-27 19:22:51 +08:00
}
[Test]
public void TestReverseSelectionThreeCircles()
{
2024-03-28 17:05:26 +08:00
OsuHitObject[] objects = null!;
bool[] newCombos = null!;
2024-03-27 19:22:51 +08:00
AddStep("Add circles", () =>
{
var circle1 = new HitCircle
{
StartTime = 0,
2024-03-28 17:05:26 +08:00
Position = new Vector2(208, 240)
2024-03-27 19:22:51 +08:00
};
var circle2 = new HitCircle
{
StartTime = 200,
2024-03-28 17:05:26 +08:00
Position = new Vector2(256, 144)
2024-03-27 19:22:51 +08:00
};
var circle3 = new HitCircle
{
StartTime = 400,
2024-03-28 17:05:26 +08:00
Position = new Vector2(304, 240)
2024-03-27 19:22:51 +08:00
};
EditorBeatmap.AddRange([circle1, circle2, circle3]);
});
2024-03-28 17:05:26 +08:00
AddStep("store objects & new combo data", () =>
2024-03-27 19:22:51 +08:00
{
2024-03-28 17:05:26 +08:00
objects = getObjects().ToArray();
newCombos = getObjectNewCombos().ToArray();
2024-03-27 19:22:51 +08:00
});
2024-03-28 17:05:26 +08:00
AddStep("Select circles", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
2024-03-27 19:22:51 +08:00
AddStep("Reverse selection", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
2024-03-28 17:05:26 +08:00
AddAssert("objects reversed", getObjects, () => Is.EqualTo(objects.Reverse()));
AddAssert("new combo positions preserved", getObjectNewCombos, () => Is.EqualTo(newCombos));
2024-03-27 19:22:51 +08:00
}
[Test]
public void TestReverseSelectionCircleAndSlider()
{
2024-03-28 17:05:26 +08:00
OsuHitObject[] objects = null!;
bool[] newCombos = null!;
2024-03-27 19:22:51 +08:00
Vector2 sliderHeadOldPosition = default;
Vector2 sliderTailOldPosition = default;
AddStep("Add objects", () =>
{
var circle = new HitCircle
{
StartTime = 0,
2024-03-28 17:05:26 +08:00
Position = new Vector2(208, 240)
2024-03-27 19:22:51 +08:00
};
var slider = new Slider
{
StartTime = 200,
Position = sliderHeadOldPosition = new Vector2(257, 144),
Path = new SliderPath
{
ControlPoints =
{
new PathControlPoint(),
new PathControlPoint(new Vector2(100))
}
}
};
sliderTailOldPosition = slider.EndPosition;
EditorBeatmap.AddRange([circle, slider]);
});
2024-03-28 17:05:26 +08:00
AddStep("store objects & new combo data", () =>
2024-03-27 19:22:51 +08:00
{
2024-03-28 17:05:26 +08:00
objects = getObjects().ToArray();
newCombos = getObjectNewCombos().ToArray();
2024-03-27 19:22:51 +08:00
});
2024-03-28 17:05:26 +08:00
AddStep("Select objects", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
2024-03-27 19:22:51 +08:00
AddStep("Reverse selection", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
2024-03-28 17:05:26 +08:00
AddAssert("objects reversed", getObjects, () => Is.EqualTo(objects.Reverse()));
AddAssert("new combo positions preserved", getObjectNewCombos, () => Is.EqualTo(newCombos));
2024-03-27 19:22:51 +08:00
AddAssert("Slider head is at slider tail", () =>
Vector2.Distance(EditorBeatmap.HitObjects.OfType<Slider>().ElementAt(0).Position, sliderTailOldPosition) < 1);
AddAssert("Slider tail is at slider head", () =>
Vector2.Distance(EditorBeatmap.HitObjects.OfType<Slider>().ElementAt(0).EndPosition, sliderHeadOldPosition) < 1);
}
[Test]
public void TestReverseSelectionTwoCirclesAndSlider()
{
2024-03-28 17:05:26 +08:00
OsuHitObject[] objects = null!;
bool[] newCombos = null!;
2024-03-27 19:22:51 +08:00
Vector2 sliderHeadOldPosition = default;
Vector2 sliderTailOldPosition = default;
AddStep("Add objects", () =>
{
var circle1 = new HitCircle
{
StartTime = 0,
2024-03-28 17:05:26 +08:00
Position = new Vector2(208, 240)
2024-03-27 19:22:51 +08:00
};
var circle2 = new HitCircle
{
StartTime = 200,
2024-03-28 17:05:26 +08:00
Position = new Vector2(256, 144)
2024-03-27 19:22:51 +08:00
};
var slider = new Slider
{
StartTime = 200,
Position = sliderHeadOldPosition = new Vector2(304, 240),
Path = new SliderPath
{
ControlPoints =
{
new PathControlPoint(),
new PathControlPoint(new Vector2(100))
}
}
};
sliderTailOldPosition = slider.EndPosition;
EditorBeatmap.AddRange([circle1, circle2, slider]);
});
2024-03-28 17:05:26 +08:00
AddStep("store objects & new combo data", () =>
2024-03-27 19:22:51 +08:00
{
2024-03-28 17:05:26 +08:00
objects = getObjects().ToArray();
newCombos = getObjectNewCombos().ToArray();
2024-03-27 19:22:51 +08:00
});
2024-03-28 17:05:26 +08:00
AddStep("Select objects", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
2024-03-27 19:22:51 +08:00
AddStep("Reverse selection", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
2024-03-28 17:05:26 +08:00
AddAssert("objects reversed", getObjects, () => Is.EqualTo(objects.Reverse()));
AddAssert("new combo positions preserved", getObjectNewCombos, () => Is.EqualTo(newCombos));
2024-03-27 19:22:51 +08:00
AddAssert("Slider head is at slider tail", () =>
Vector2.Distance(EditorBeatmap.HitObjects.OfType<Slider>().ElementAt(0).Position, sliderTailOldPosition) < 1);
AddAssert("Slider tail is at slider head", () =>
Vector2.Distance(EditorBeatmap.HitObjects.OfType<Slider>().ElementAt(0).EndPosition, sliderHeadOldPosition) < 1);
}
[Test]
public void TestReverseSelectionTwoCombos()
{
2024-03-28 17:05:26 +08:00
OsuHitObject[] objects = null!;
bool[] newCombos = null!;
2024-03-27 19:22:51 +08:00
AddStep("Add circles", () =>
{
var circle1 = new HitCircle
{
StartTime = 0,
2024-03-28 17:05:26 +08:00
Position = new Vector2(216, 240)
2024-03-27 19:22:51 +08:00
};
var circle2 = new HitCircle
{
StartTime = 200,
2024-03-28 17:05:26 +08:00
Position = new Vector2(120, 192)
2024-03-27 19:22:51 +08:00
};
var circle3 = new HitCircle
{
StartTime = 400,
2024-03-28 17:05:26 +08:00
Position = new Vector2(216, 144)
2024-03-27 19:22:51 +08:00
};
var circle4 = new HitCircle
{
StartTime = 646,
NewCombo = true,
2024-03-28 17:05:26 +08:00
Position = new Vector2(296, 240)
2024-03-27 19:22:51 +08:00
};
var circle5 = new HitCircle
{
StartTime = 846,
2024-03-28 17:05:26 +08:00
Position = new Vector2(392, 162)
2024-03-27 19:22:51 +08:00
};
var circle6 = new HitCircle
{
StartTime = 1046,
2024-03-28 17:05:26 +08:00
Position = new Vector2(296, 144)
2024-03-27 19:22:51 +08:00
};
EditorBeatmap.AddRange([circle1, circle2, circle3, circle4, circle5, circle6]);
});
2024-03-28 17:05:26 +08:00
AddStep("store objects & new combo data", () =>
2024-03-27 19:22:51 +08:00
{
2024-03-28 17:05:26 +08:00
objects = getObjects().ToArray();
newCombos = getObjectNewCombos().ToArray();
2024-03-27 19:22:51 +08:00
});
2024-03-28 17:05:26 +08:00
AddStep("Select circles", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
2024-03-27 19:22:51 +08:00
AddStep("Reverse selection", () =>
{
InputManager.PressKey(Key.LControl);
InputManager.Key(Key.G);
InputManager.ReleaseKey(Key.LControl);
});
2024-03-28 17:05:26 +08:00
AddAssert("objects reversed", getObjects, () => Is.EqualTo(objects.Reverse()));
AddAssert("new combo positions preserved", getObjectNewCombos, () => Is.EqualTo(newCombos));
2024-03-27 19:22:51 +08:00
}
2024-03-28 17:05:26 +08:00
private IEnumerable<OsuHitObject> getObjects() => EditorBeatmap.HitObjects.OfType<OsuHitObject>();
private IEnumerable<bool> getObjectNewCombos() => getObjects().Select(ho => ho.NewCombo);
2024-03-27 19:22:51 +08:00
}
}