1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-21 11:22:55 +08:00

Also add test coverage of adjsuting the distance spacing multiplier

This commit is contained in:
Dean Herbert 2022-05-05 18:41:25 +09:00
parent 4fe23bced2
commit 9fd98b8060

View File

@ -7,7 +7,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; using osu.Framework.Input;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
{ {
public class TestSceneOsuDistanceSnapGrid : OsuManualInputManagerTestScene public class TestSceneOsuDistanceSnapGrid : OsuManualInputManagerTestScene
{ {
private const double beat_length = 100; private const float beat_length = 100;
private static readonly Vector2 grid_position = new Vector2(512, 384); private static readonly Vector2 grid_position = new Vector2(512, 384);
@ -119,15 +119,27 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
[Test] [Test]
public void TestCursorBeforeMovementPoint() public void TestCursorBeforeMovementPoint()
{ {
AddStep("move mouse to just before movement point", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position + new Vector2((float)beat_length, 0) * 1.45f))); AddStep("move mouse to just before movement point", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position + new Vector2(beat_length, 0) * 1.45f)));
assertSnappedDistance((float)beat_length); assertSnappedDistance(beat_length);
} }
[Test] [Test]
public void TestCursorAfterMovementPoint() public void TestCursorAfterMovementPoint()
{ {
AddStep("move mouse to just after movement point", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position + new Vector2((float)beat_length, 0) * 1.55f))); AddStep("move mouse to just after movement point", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position + new Vector2(beat_length, 0) * 1.55f)));
assertSnappedDistance((float)beat_length * 2); assertSnappedDistance(beat_length * 2);
}
[TestCase(0.5f, beat_length * 2)]
[TestCase(1, beat_length * 2)]
[TestCase(1.5f, beat_length * 1.5f)]
[TestCase(2f, beat_length * 2)]
public void TestDistanceSpacingAdjust(float multiplier, float expectedDistance)
{
AddStep($"Set distance spacing to {multiplier}", () => snapProvider.DistanceSpacingMultiplier.Value = multiplier);
AddStep("move mouse to point", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position + new Vector2(beat_length, 0) * 2)));
assertSnappedDistance(expectedDistance);
} }
[Test] [Test]
@ -147,8 +159,8 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
}; };
}); });
AddStep("move mouse outside grid", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position + new Vector2((float)beat_length, 0) * 3f))); AddStep("move mouse outside grid", () => InputManager.MoveMouseTo(grid.ToScreenSpace(grid_position + new Vector2(beat_length, 0) * 3f)));
assertSnappedDistance((float)beat_length * 2); assertSnappedDistance(beat_length * 2);
} }
private void assertSnappedDistance(float expectedDistance) => AddAssert($"snap distance = {expectedDistance}", () => private void assertSnappedDistance(float expectedDistance) => AddAssert($"snap distance = {expectedDistance}", () =>
@ -164,6 +176,10 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
private readonly Drawable cursor; private readonly Drawable cursor;
private InputManager inputManager;
public override bool HandlePositionalInput => true;
public SnappingCursorContainer() public SnappingCursorContainer()
{ {
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
@ -180,20 +196,13 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
{ {
base.LoadComplete(); base.LoadComplete();
updatePosition(GetContainingInputManager().CurrentState.Mouse.Position); inputManager = GetContainingInputManager();
} }
protected override bool OnMouseMove(MouseMoveEvent e) protected override void Update()
{ {
base.OnMouseMove(e); base.Update();
cursor.Position = GetSnapPosition.Invoke(inputManager.CurrentState.Mouse.Position);
updatePosition(e.ScreenSpaceMousePosition);
return true;
}
private void updatePosition(Vector2 screenSpacePosition)
{
cursor.Position = GetSnapPosition.Invoke(screenSpacePosition);
} }
} }
} }