mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
fix grid test
This commit is contained in:
parent
9796fcff52
commit
c5edf43283
@ -1,6 +1,7 @@
|
||||
// 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 System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Testing;
|
||||
@ -9,6 +10,7 @@ using osu.Game.Rulesets.Osu.Edit;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
using osu.Game.Tests.Visual;
|
||||
using osu.Game.Utils;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
@ -25,22 +27,22 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
||||
AddStep("select second object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.ElementAt(1)));
|
||||
|
||||
AddUntilStep("distance snap grid visible", () => this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
||||
rectangularGridActive(false);
|
||||
gridActive<RectangularPositionSnapGrid>(false);
|
||||
|
||||
AddStep("enable rectangular grid", () => InputManager.Key(Key.Y));
|
||||
|
||||
AddStep("select second object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.ElementAt(1)));
|
||||
AddUntilStep("distance snap grid still visible", () => this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
||||
rectangularGridActive(true);
|
||||
gridActive<RectangularPositionSnapGrid>(true);
|
||||
|
||||
AddStep("disable distance snap grid", () => InputManager.Key(Key.T));
|
||||
AddUntilStep("distance snap grid hidden", () => !this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
||||
AddStep("select second object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.ElementAt(1)));
|
||||
rectangularGridActive(true);
|
||||
gridActive<RectangularPositionSnapGrid>(true);
|
||||
|
||||
AddStep("disable rectangular grid", () => InputManager.Key(Key.Y));
|
||||
AddUntilStep("distance snap grid still hidden", () => !this.ChildrenOfType<OsuDistanceSnapGrid>().Any());
|
||||
rectangularGridActive(false);
|
||||
gridActive<RectangularPositionSnapGrid>(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -58,49 +60,69 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
|
||||
[Test]
|
||||
public void TestGridSnapMomentaryToggle()
|
||||
{
|
||||
rectangularGridActive(false);
|
||||
gridActive<RectangularPositionSnapGrid>(false);
|
||||
AddStep("hold shift", () => InputManager.PressKey(Key.ShiftLeft));
|
||||
rectangularGridActive(true);
|
||||
gridActive<RectangularPositionSnapGrid>(true);
|
||||
AddStep("release shift", () => InputManager.ReleaseKey(Key.ShiftLeft));
|
||||
rectangularGridActive(false);
|
||||
gridActive<RectangularPositionSnapGrid>(false);
|
||||
}
|
||||
|
||||
private void rectangularGridActive(bool active)
|
||||
private void gridActive<T>(bool active) where T : PositionSnapGrid
|
||||
{
|
||||
AddStep("choose placement tool", () => InputManager.Key(Key.Number2));
|
||||
AddStep("move cursor to (1, 1)", () =>
|
||||
AddStep("move cursor to spacing + (1, 1)", () =>
|
||||
{
|
||||
var composer = Editor.ChildrenOfType<RectangularPositionSnapGrid>().Single();
|
||||
InputManager.MoveMouseTo(composer.ToScreenSpace(new Vector2(1, 1)));
|
||||
var composer = Editor.ChildrenOfType<T>().Single();
|
||||
InputManager.MoveMouseTo(composer.ToScreenSpace(uniqueSnappingPosition(composer) + new Vector2(1, 1)));
|
||||
});
|
||||
|
||||
if (active)
|
||||
AddAssert("placement blueprint at (0, 0)", () => Precision.AlmostEquals(Editor.ChildrenOfType<HitCirclePlacementBlueprint>().Single().HitObject.Position, new Vector2(0, 0)));
|
||||
{
|
||||
AddAssert("placement blueprint at spacing + (0, 0)", () =>
|
||||
{
|
||||
var composer = Editor.ChildrenOfType<T>().Single();
|
||||
return Precision.AlmostEquals(Editor.ChildrenOfType<HitCirclePlacementBlueprint>().Single().HitObject.Position,
|
||||
uniqueSnappingPosition(composer));
|
||||
});
|
||||
}
|
||||
else
|
||||
AddAssert("placement blueprint at (1, 1)", () => Precision.AlmostEquals(Editor.ChildrenOfType<HitCirclePlacementBlueprint>().Single().HitObject.Position, new Vector2(1, 1)));
|
||||
{
|
||||
AddAssert("placement blueprint at spacing + (1, 1)", () =>
|
||||
{
|
||||
var composer = Editor.ChildrenOfType<T>().Single();
|
||||
return Precision.AlmostEquals(Editor.ChildrenOfType<HitCirclePlacementBlueprint>().Single().HitObject.Position,
|
||||
uniqueSnappingPosition(composer) + new Vector2(1, 1));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private Vector2 uniqueSnappingPosition(PositionSnapGrid grid)
|
||||
{
|
||||
return grid switch
|
||||
{
|
||||
RectangularPositionSnapGrid rectangular => rectangular.StartPosition.Value + GeometryUtils.RotateVector(rectangular.Spacing.Value, -rectangular.GridLineRotation.Value),
|
||||
TriangularPositionSnapGrid triangular => triangular.StartPosition.Value + GeometryUtils.RotateVector(new Vector2(triangular.Spacing.Value / 2, triangular.Spacing.Value / 2 * MathF.Sqrt(3)), -triangular.GridLineRotation.Value),
|
||||
CircularPositionSnapGrid circular => circular.StartPosition.Value + GeometryUtils.RotateVector(new Vector2(circular.Spacing.Value, 0), -45),
|
||||
_ => Vector2.Zero
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGridSizeToggling()
|
||||
public void TestGridTypeToggling()
|
||||
{
|
||||
AddStep("enable rectangular grid", () => InputManager.Key(Key.Y));
|
||||
AddUntilStep("rectangular grid visible", () => this.ChildrenOfType<RectangularPositionSnapGrid>().Any());
|
||||
gridSizeIs(4);
|
||||
gridActive<RectangularPositionSnapGrid>(true);
|
||||
|
||||
nextGridSizeIs(8);
|
||||
nextGridSizeIs(16);
|
||||
nextGridSizeIs(32);
|
||||
nextGridSizeIs(4);
|
||||
nextGridTypeIs<TriangularPositionSnapGrid>();
|
||||
nextGridTypeIs<CircularPositionSnapGrid>();
|
||||
nextGridTypeIs<RectangularPositionSnapGrid>();
|
||||
}
|
||||
|
||||
private void nextGridSizeIs(int size)
|
||||
private void nextGridTypeIs<T>() where T : PositionSnapGrid
|
||||
{
|
||||
AddStep("toggle to next grid size", () => InputManager.Key(Key.G));
|
||||
gridSizeIs(size);
|
||||
AddStep("toggle to next grid type", () => InputManager.Key(Key.G));
|
||||
gridActive<T>(true);
|
||||
}
|
||||
|
||||
private void gridSizeIs(int size)
|
||||
=> AddAssert($"grid size is {size}", () => this.ChildrenOfType<RectangularPositionSnapGrid>().Single().Spacing.Value == new Vector2(size)
|
||||
&& EditorBeatmap.BeatmapInfo.GridSize == size);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user