mirror of
https://github.com/ppy/osu
synced 2025-02-20 04:17:06 +00:00
Fixed 0 length merge being allowed
This commit is contained in:
parent
cf6bb3b030
commit
16e0ec2f88
@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Rulesets.Objects.Types;
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
|
using osu.Game.Rulesets.Osu.Edit;
|
||||||
using osu.Game.Rulesets.Osu.Objects;
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
@ -14,6 +16,8 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
|||||||
{
|
{
|
||||||
public class TestSceneObjectMerging : TestSceneOsuEditor
|
public class TestSceneObjectMerging : TestSceneOsuEditor
|
||||||
{
|
{
|
||||||
|
private OsuSelectionHandler selectionHandler => Editor.ChildrenOfType<OsuSelectionHandler>().First();
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestSimpleMerge()
|
public void TestSimpleMerge()
|
||||||
{
|
{
|
||||||
@ -29,6 +33,9 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
|||||||
EditorBeatmap.SelectedHitObjects.Add(circle2);
|
EditorBeatmap.SelectedHitObjects.Add(circle2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
moveMouseToHitObject(1);
|
||||||
|
AddAssert("merge option available", () => selectionHandler.ContextMenuItems.Any(o => o.Text.Value == "Merge selection"));
|
||||||
|
|
||||||
mergeSelection();
|
mergeSelection();
|
||||||
|
|
||||||
AddAssert("slider created", () => circle1 is not null && circle2 is not null && sliderCreatedFor(
|
AddAssert("slider created", () => circle1 is not null && circle2 is not null && sliderCreatedFor(
|
||||||
@ -174,6 +181,30 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
|||||||
AddAssert("spinner not merged", () => EditorBeatmap.HitObjects.Contains(spinner));
|
AddAssert("spinner not merged", () => EditorBeatmap.HitObjects.Contains(spinner));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestIllegalMerge()
|
||||||
|
{
|
||||||
|
HitCircle? circle1 = null;
|
||||||
|
HitCircle? circle2 = null;
|
||||||
|
|
||||||
|
AddStep("add two circles on the same position", () =>
|
||||||
|
{
|
||||||
|
circle1 = new HitCircle();
|
||||||
|
circle2 = new HitCircle { Position = circle1.Position + Vector2.UnitX, StartTime = 1 };
|
||||||
|
EditorClock.Seek(0);
|
||||||
|
EditorBeatmap.Add(circle1);
|
||||||
|
EditorBeatmap.Add(circle2);
|
||||||
|
EditorBeatmap.SelectedHitObjects.Add(circle1);
|
||||||
|
EditorBeatmap.SelectedHitObjects.Add(circle2);
|
||||||
|
});
|
||||||
|
|
||||||
|
moveMouseToHitObject(1);
|
||||||
|
AddAssert("merge option not available", () => selectionHandler.ContextMenuItems.Length > 0 && selectionHandler.ContextMenuItems.All(o => o.Text.Value != "Merge selection"));
|
||||||
|
mergeSelection();
|
||||||
|
AddAssert("circles not merged", () => circle1 is not null && circle2 is not null
|
||||||
|
&& EditorBeatmap.HitObjects.Contains(circle1) && EditorBeatmap.HitObjects.Contains(circle2));
|
||||||
|
}
|
||||||
|
|
||||||
private void mergeSelection()
|
private void mergeSelection()
|
||||||
{
|
{
|
||||||
AddStep("merge selection", () =>
|
AddStep("merge selection", () =>
|
||||||
@ -225,5 +256,17 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
|||||||
|
|
||||||
return mergedSlider.Samples[0] is not null;
|
return mergedSlider.Samples[0] is not null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void moveMouseToHitObject(int index)
|
||||||
|
{
|
||||||
|
AddStep($"hover mouse over hit object {index}", () =>
|
||||||
|
{
|
||||||
|
if (EditorBeatmap.HitObjects.Count <= index)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Vector2 position = ((OsuHitObject)EditorBeatmap.HitObjects[index]).Position;
|
||||||
|
InputManager.MoveMouseTo(selectionHandler.ToScreenSpace(position));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -358,7 +358,8 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
{
|
{
|
||||||
var mergeableObjects = selectedMergeableObjects;
|
var mergeableObjects = selectedMergeableObjects;
|
||||||
|
|
||||||
if (mergeableObjects.Length < 2)
|
if (mergeableObjects.Length < 2 || (mergeableObjects.All(h => h is not Slider)
|
||||||
|
&& Precision.AlmostBigger(1, Vector2.DistanceSquared(mergeableObjects[0].Position, mergeableObjects[1].Position))))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ChangeHandler?.BeginChange();
|
ChangeHandler?.BeginChange();
|
||||||
@ -445,7 +446,9 @@ namespace osu.Game.Rulesets.Osu.Edit
|
|||||||
foreach (var item in base.GetContextMenuItemsForSelection(selection))
|
foreach (var item in base.GetContextMenuItemsForSelection(selection))
|
||||||
yield return item;
|
yield return item;
|
||||||
|
|
||||||
if (selectedMergeableObjects.Length > 1)
|
var mergeableObjects = selectedMergeableObjects;
|
||||||
|
if (mergeableObjects.Length > 1 && (mergeableObjects.Any(h => h is Slider)
|
||||||
|
|| Precision.DefinitelyBigger(Vector2.DistanceSquared(mergeableObjects[0].Position, mergeableObjects[1].Position), 1)))
|
||||||
yield return new OsuMenuItem("Merge selection", MenuItemType.Destructive, mergeSelection);
|
yield return new OsuMenuItem("Merge selection", MenuItemType.Destructive, mergeSelection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user