1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 07:53:38 +08:00
osu-lazer/osu.Game.Rulesets.Mania.Tests/Editor/TestSceneManiaHitObjectComposer.cs

219 lines
8.9 KiB
C#
Raw Normal View History

2020-04-28 13:47:52 +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.
2020-04-28 17:35:37 +08:00
using System.Linq;
2020-04-28 13:47:52 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
2020-04-28 17:35:37 +08:00
using osu.Framework.Bindables;
2020-04-28 13:47:52 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-04-28 17:35:37 +08:00
using osu.Framework.Testing;
2020-05-08 17:50:06 +08:00
using osu.Framework.Utils;
2020-04-28 13:47:52 +08:00
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Edit;
2020-05-08 17:50:06 +08:00
using osu.Game.Rulesets.Mania.Edit.Blueprints;
2020-04-28 13:47:52 +08:00
using osu.Game.Rulesets.Mania.Objects;
2020-05-08 17:50:06 +08:00
using osu.Game.Rulesets.Mania.Objects.Drawables;
2020-12-07 11:32:52 +08:00
using osu.Game.Rulesets.Mania.Skinning.Default;
2020-04-28 17:35:37 +08:00
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling;
2020-04-28 13:47:52 +08:00
using osu.Game.Screens.Edit;
using osu.Game.Tests.Visual;
2020-04-28 17:35:37 +08:00
using osuTK;
using osuTK.Input;
2020-04-28 13:47:52 +08:00
namespace osu.Game.Rulesets.Mania.Tests.Editor
2020-04-28 13:47:52 +08:00
{
public class TestSceneManiaHitObjectComposer : EditorClockTestScene
{
2020-04-28 17:35:37 +08:00
private TestComposer composer;
2020-04-28 13:47:52 +08:00
2020-04-28 17:35:37 +08:00
[SetUp]
public void Setup() => Schedule(() =>
{
BeatDivisor.Value = 8;
Clock.Seek(0);
2020-04-28 13:47:52 +08:00
2020-04-28 17:35:37 +08:00
Child = composer = new TestComposer { RelativeSizeAxes = Axes.Both };
});
[Test]
public void TestDragOffscreenSelectionVerticallyUpScroll()
2020-04-28 13:47:52 +08:00
{
2020-04-28 17:35:37 +08:00
DrawableHitObject lastObject = null;
2020-05-21 12:04:35 +08:00
double originalTime = 0;
2020-04-28 17:35:37 +08:00
Vector2 originalPosition = Vector2.Zero;
2020-05-08 17:50:06 +08:00
setScrollStep(ScrollingDirection.Up);
2020-04-28 17:35:37 +08:00
AddStep("seek to last object", () =>
2020-04-28 13:47:52 +08:00
{
2020-04-28 17:35:37 +08:00
lastObject = this.ChildrenOfType<DrawableHitObject>().Single(d => d.HitObject == composer.EditorBeatmap.HitObjects.Last());
2020-05-21 12:04:35 +08:00
originalTime = lastObject.HitObject.StartTime;
2020-04-28 17:35:37 +08:00
Clock.Seek(composer.EditorBeatmap.HitObjects.Last().StartTime);
2020-04-28 13:47:52 +08:00
});
2020-04-28 17:35:37 +08:00
AddStep("select all objects", () => composer.EditorBeatmap.SelectedHitObjects.AddRange(composer.EditorBeatmap.HitObjects));
AddStep("click last object", () =>
2020-04-28 13:47:52 +08:00
{
2020-04-28 17:35:37 +08:00
originalPosition = lastObject.DrawPosition;
InputManager.MoveMouseTo(lastObject);
InputManager.PressButton(MouseButton.Left);
});
AddStep("move mouse downwards", () =>
{
2020-05-21 14:47:12 +08:00
InputManager.MoveMouseTo(lastObject, new Vector2(0, lastObject.ScreenSpaceDrawQuad.Height * 4));
2020-04-28 17:35:37 +08:00
InputManager.ReleaseButton(MouseButton.Left);
});
AddAssert("hitobjects not moved columns", () => composer.EditorBeatmap.HitObjects.All(h => ((ManiaHitObject)h).Column == 0));
AddAssert("hitobjects moved downwards", () => lastObject.DrawPosition.Y - originalPosition.Y > 0);
2020-05-21 12:04:35 +08:00
AddAssert("hitobject has moved time", () => lastObject.HitObject.StartTime == originalTime + 125);
2020-04-28 13:47:52 +08:00
}
2020-04-28 17:35:37 +08:00
[Test]
public void TestDragOffscreenSelectionVerticallyDownScroll()
2020-04-28 13:47:52 +08:00
{
2020-04-28 17:35:37 +08:00
DrawableHitObject lastObject = null;
2020-05-21 12:04:35 +08:00
double originalTime = 0;
2020-04-28 17:35:37 +08:00
Vector2 originalPosition = Vector2.Zero;
2020-05-08 17:50:06 +08:00
setScrollStep(ScrollingDirection.Down);
2020-04-28 17:35:37 +08:00
AddStep("seek to last object", () =>
2020-04-28 13:47:52 +08:00
{
2020-04-28 17:35:37 +08:00
lastObject = this.ChildrenOfType<DrawableHitObject>().Single(d => d.HitObject == composer.EditorBeatmap.HitObjects.Last());
2020-05-21 12:04:35 +08:00
originalTime = lastObject.HitObject.StartTime;
2020-04-28 17:35:37 +08:00
Clock.Seek(composer.EditorBeatmap.HitObjects.Last().StartTime);
});
2020-04-28 13:47:52 +08:00
2020-04-28 17:35:37 +08:00
AddStep("select all objects", () => composer.EditorBeatmap.SelectedHitObjects.AddRange(composer.EditorBeatmap.HitObjects));
AddStep("click last object", () =>
{
originalPosition = lastObject.DrawPosition;
InputManager.MoveMouseTo(lastObject);
InputManager.PressButton(MouseButton.Left);
});
AddStep("move mouse upwards", () =>
{
2020-05-21 14:47:12 +08:00
InputManager.MoveMouseTo(lastObject, new Vector2(0, -lastObject.ScreenSpaceDrawQuad.Height * 4));
2020-04-28 17:35:37 +08:00
InputManager.ReleaseButton(MouseButton.Left);
});
AddAssert("hitobjects not moved columns", () => composer.EditorBeatmap.HitObjects.All(h => ((ManiaHitObject)h).Column == 0));
AddAssert("hitobjects moved upwards", () => originalPosition.Y - lastObject.DrawPosition.Y > 0);
2020-05-21 12:04:35 +08:00
AddAssert("hitobject has moved time", () => lastObject.HitObject.StartTime == originalTime + 125);
2020-04-28 17:35:37 +08:00
}
[Test]
public void TestDragOffscreenSelectionHorizontally()
{
DrawableHitObject lastObject = null;
Vector2 originalPosition = Vector2.Zero;
2020-05-08 17:50:06 +08:00
setScrollStep(ScrollingDirection.Down);
2020-04-28 17:35:37 +08:00
AddStep("seek to last object", () =>
{
lastObject = this.ChildrenOfType<DrawableHitObject>().Single(d => d.HitObject == composer.EditorBeatmap.HitObjects.Last());
Clock.Seek(composer.EditorBeatmap.HitObjects.Last().StartTime);
});
AddStep("select all objects", () => composer.EditorBeatmap.SelectedHitObjects.AddRange(composer.EditorBeatmap.HitObjects));
AddStep("click last object", () =>
{
2020-04-28 19:15:56 +08:00
originalPosition = lastObject.DrawPosition;
2020-04-28 17:35:37 +08:00
InputManager.MoveMouseTo(lastObject);
InputManager.PressButton(MouseButton.Left);
});
AddStep("move mouse right", () =>
{
2020-04-28 19:15:56 +08:00
var firstColumn = composer.Composer.Playfield.GetColumn(0);
var secondColumn = composer.Composer.Playfield.GetColumn(1);
InputManager.MoveMouseTo(lastObject, new Vector2(secondColumn.ScreenSpaceDrawQuad.Centre.X - firstColumn.ScreenSpaceDrawQuad.Centre.X + 1, 0));
2020-04-28 17:35:37 +08:00
InputManager.ReleaseButton(MouseButton.Left);
});
AddAssert("hitobjects moved columns", () => composer.EditorBeatmap.HitObjects.All(h => ((ManiaHitObject)h).Column == 1));
2020-04-28 17:53:30 +08:00
// Todo: They'll move vertically by the height of a note since there's no snapping and the selection point is the middle of the note.
AddAssert("hitobjects not moved vertically", () => lastObject.DrawPosition.Y - originalPosition.Y <= DefaultNotePiece.NOTE_HEIGHT);
2020-04-28 17:35:37 +08:00
}
2020-05-08 17:50:06 +08:00
[Test]
public void TestDragHoldNoteSelectionVertically()
{
setScrollStep(ScrollingDirection.Down);
AddStep("setup beatmap", () =>
{
composer.EditorBeatmap.Clear();
composer.EditorBeatmap.Add(new HoldNote
{
Column = 1,
EndTime = 200
});
});
DrawableHoldNote holdNote = null;
AddStep("grab hold note", () =>
{
holdNote = this.ChildrenOfType<DrawableHoldNote>().Single();
2020-05-08 17:50:06 +08:00
InputManager.MoveMouseTo(holdNote);
InputManager.PressButton(MouseButton.Left);
});
AddStep("move drag upwards", () =>
{
InputManager.MoveMouseTo(holdNote, new Vector2(0, -100));
InputManager.ReleaseButton(MouseButton.Left);
});
AddAssert("head note positioned correctly", () => Precision.AlmostEquals(holdNote.ScreenSpaceDrawQuad.BottomLeft, holdNote.Head.ScreenSpaceDrawQuad.BottomLeft));
AddAssert("tail note positioned correctly", () => Precision.AlmostEquals(holdNote.ScreenSpaceDrawQuad.TopLeft, holdNote.Tail.ScreenSpaceDrawQuad.BottomLeft));
AddAssert("head blueprint positioned correctly", () => this.ChildrenOfType<HoldNoteNoteOverlay>().ElementAt(0).DrawPosition == holdNote.Head.DrawPosition);
AddAssert("tail blueprint positioned correctly", () => this.ChildrenOfType<HoldNoteNoteOverlay>().ElementAt(1).DrawPosition == holdNote.Tail.DrawPosition);
2020-05-08 17:50:06 +08:00
}
private void setScrollStep(ScrollingDirection direction)
=> AddStep($"set scroll direction = {direction}", () => ((Bindable<ScrollingDirection>)composer.Composer.ScrollingInfo.Direction).Value = direction);
2020-04-28 17:35:37 +08:00
private class TestComposer : CompositeDrawable
{
[Cached(typeof(EditorBeatmap))]
[Cached(typeof(IBeatSnapProvider))]
public readonly EditorBeatmap EditorBeatmap;
public readonly ManiaHitObjectComposer Composer;
public TestComposer()
{
InternalChildren = new Drawable[]
{
EditorBeatmap = new EditorBeatmap(new ManiaBeatmap(new StageDefinition { Columns = 4 }))
{
BeatmapInfo = { Ruleset = new ManiaRuleset().RulesetInfo }
},
Composer = new ManiaHitObjectComposer(new ManiaRuleset())
};
for (int i = 0; i < 10; i++)
2020-05-21 12:04:35 +08:00
EditorBeatmap.Add(new Note { StartTime = 125 * i });
2020-04-28 17:35:37 +08:00
}
}
2020-04-28 13:47:52 +08:00
}
}