2019-10-10 20:55:48 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2019-10-10 20:55:48 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2022-01-18 20:25:32 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-10-10 20:55:48 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2019-10-25 16:25:46 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2021-09-01 17:05:10 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2022-01-12 22:17:35 +08:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2019-10-10 20:55:48 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
|
|
|
using osu.Game.Screens.Edit;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2020-04-23 16:07:55 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Editing
|
2019-10-10 20:55:48 +08:00
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TestSceneDistanceSnapGrid : EditorClockTestScene
|
2019-10-10 20:55:48 +08:00
|
|
|
{
|
|
|
|
private const double beat_length = 100;
|
2022-05-05 16:42:50 +08:00
|
|
|
private const int beat_snap_distance = 10;
|
|
|
|
|
2019-10-10 20:55:48 +08:00
|
|
|
private static readonly Vector2 grid_position = new Vector2(512, 384);
|
|
|
|
|
2022-05-05 16:42:50 +08:00
|
|
|
private TestDistanceSnapGrid grid;
|
|
|
|
|
2019-12-27 18:46:33 +08:00
|
|
|
[Cached(typeof(EditorBeatmap))]
|
2019-12-27 18:39:30 +08:00
|
|
|
private readonly EditorBeatmap editorBeatmap;
|
2019-10-10 20:55:48 +08:00
|
|
|
|
2022-04-24 12:08:53 +08:00
|
|
|
[Cached(typeof(IDistanceSnapProvider))]
|
2019-10-25 16:25:46 +08:00
|
|
|
private readonly SnapProvider snapProvider = new SnapProvider();
|
2019-10-10 20:55:48 +08:00
|
|
|
|
2019-10-17 14:32:02 +08:00
|
|
|
public TestSceneDistanceSnapGrid()
|
2019-10-10 20:55:48 +08:00
|
|
|
{
|
2022-01-12 22:17:35 +08:00
|
|
|
editorBeatmap = new EditorBeatmap(new OsuBeatmap
|
|
|
|
{
|
|
|
|
BeatmapInfo =
|
|
|
|
{
|
|
|
|
Ruleset = new OsuRuleset().RulesetInfo
|
|
|
|
}
|
|
|
|
});
|
2019-10-25 18:48:01 +08:00
|
|
|
editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = beat_length });
|
2022-05-05 16:42:50 +08:00
|
|
|
editorBeatmap.Difficulty.SliderMultiplier = 1;
|
2019-11-06 15:20:13 +08:00
|
|
|
}
|
2019-10-11 16:17:08 +08:00
|
|
|
|
2019-11-06 15:20:13 +08:00
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
|
|
|
{
|
2019-10-25 16:25:46 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.SlateGray
|
|
|
|
},
|
2022-05-05 16:42:50 +08:00
|
|
|
grid = new TestDistanceSnapGrid()
|
2019-10-25 16:25:46 +08:00
|
|
|
};
|
2019-11-06 15:20:13 +08:00
|
|
|
});
|
2019-10-10 20:55:48 +08:00
|
|
|
|
|
|
|
[TestCase(1)]
|
|
|
|
[TestCase(2)]
|
|
|
|
[TestCase(3)]
|
|
|
|
[TestCase(4)]
|
|
|
|
[TestCase(6)]
|
|
|
|
[TestCase(8)]
|
|
|
|
[TestCase(12)]
|
|
|
|
[TestCase(16)]
|
2019-10-25 16:25:46 +08:00
|
|
|
public void TestBeatDivisor(int divisor)
|
2019-10-10 20:55:48 +08:00
|
|
|
{
|
|
|
|
AddStep($"set beat divisor = {divisor}", () => BeatDivisor.Value = divisor);
|
|
|
|
}
|
|
|
|
|
2022-05-05 16:42:50 +08:00
|
|
|
[TestCase(1.0)]
|
|
|
|
[TestCase(2.0)]
|
|
|
|
[TestCase(0.5)]
|
|
|
|
public void TestDistanceSpacing(double multiplier)
|
|
|
|
{
|
|
|
|
AddStep($"set distance spacing = {multiplier}", () => snapProvider.DistanceSpacingMultiplier.Value = multiplier);
|
2022-05-06 14:45:36 +08:00
|
|
|
AddAssert("distance spacing matches multiplier", () => grid.DistanceBetweenTicks == beat_snap_distance * multiplier);
|
2022-05-05 16:42:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(1.0)]
|
|
|
|
[TestCase(2.0)]
|
|
|
|
[TestCase(0.5)]
|
|
|
|
public void TestLimitedDistance(double multiplier)
|
2019-11-06 15:20:13 +08:00
|
|
|
{
|
2022-05-05 16:42:50 +08:00
|
|
|
const int end_time = 100;
|
|
|
|
|
2019-11-06 15:20:13 +08:00
|
|
|
AddStep("create limited grid", () =>
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Color4.SlateGray
|
|
|
|
},
|
2022-05-05 16:42:50 +08:00
|
|
|
grid = new TestDistanceSnapGrid(end_time)
|
2019-11-06 15:20:13 +08:00
|
|
|
};
|
|
|
|
});
|
2022-05-05 16:42:50 +08:00
|
|
|
|
|
|
|
AddStep($"set distance spacing = {multiplier}", () => snapProvider.DistanceSpacingMultiplier.Value = multiplier);
|
2022-05-06 17:44:25 +08:00
|
|
|
AddStep("check correct interval count", () => Assert.That((end_time / grid.DistanceBetweenTicks) * multiplier, Is.EqualTo(grid.MaxIntervals)));
|
2019-11-06 15:20:13 +08:00
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
private partial class TestDistanceSnapGrid : DistanceSnapGrid
|
2019-10-10 20:55:48 +08:00
|
|
|
{
|
2022-05-06 14:45:36 +08:00
|
|
|
public new float DistanceBetweenTicks => base.DistanceBetweenTicks;
|
2019-10-10 20:55:48 +08:00
|
|
|
|
2022-05-05 16:42:50 +08:00
|
|
|
public new int MaxIntervals => base.MaxIntervals;
|
|
|
|
|
2019-12-10 15:00:09 +08:00
|
|
|
public TestDistanceSnapGrid(double? endTime = null)
|
2021-09-01 17:05:10 +08:00
|
|
|
: base(new HitObject(), grid_position, 0, endTime)
|
2019-10-10 20:55:48 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-01-28 10:59:21 +08:00
|
|
|
protected override void CreateContent()
|
2019-10-10 20:55:48 +08:00
|
|
|
{
|
|
|
|
AddInternal(new Circle
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(5),
|
2020-01-28 10:59:21 +08:00
|
|
|
Position = StartPosition
|
2019-10-10 20:55:48 +08:00
|
|
|
});
|
|
|
|
|
2020-01-28 10:59:21 +08:00
|
|
|
int indexFromPlacement = 0;
|
2019-10-10 20:55:48 +08:00
|
|
|
|
2022-05-06 14:45:36 +08:00
|
|
|
for (float s = StartPosition.X + DistanceBetweenTicks; s <= DrawWidth && indexFromPlacement < MaxIntervals; s += DistanceBetweenTicks, indexFromPlacement++)
|
2019-10-10 20:55:48 +08:00
|
|
|
{
|
|
|
|
AddInternal(new Circle
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(5, 10),
|
2020-01-28 10:59:21 +08:00
|
|
|
Position = new Vector2(s, StartPosition.Y),
|
|
|
|
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
|
2019-10-10 20:55:48 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-28 10:59:21 +08:00
|
|
|
indexFromPlacement = 0;
|
2019-10-10 20:55:48 +08:00
|
|
|
|
2022-05-06 14:45:36 +08:00
|
|
|
for (float s = StartPosition.X - DistanceBetweenTicks; s >= 0 && indexFromPlacement < MaxIntervals; s -= DistanceBetweenTicks, indexFromPlacement++)
|
2019-10-10 20:55:48 +08:00
|
|
|
{
|
|
|
|
AddInternal(new Circle
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(5, 10),
|
2020-01-28 10:59:21 +08:00
|
|
|
Position = new Vector2(s, StartPosition.Y),
|
|
|
|
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
|
2019-10-10 20:55:48 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-28 10:59:21 +08:00
|
|
|
indexFromPlacement = 0;
|
2019-10-10 20:55:48 +08:00
|
|
|
|
2022-05-06 14:45:36 +08:00
|
|
|
for (float s = StartPosition.Y + DistanceBetweenTicks; s <= DrawHeight && indexFromPlacement < MaxIntervals; s += DistanceBetweenTicks, indexFromPlacement++)
|
2019-10-10 20:55:48 +08:00
|
|
|
{
|
|
|
|
AddInternal(new Circle
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(10, 5),
|
2020-01-28 10:59:21 +08:00
|
|
|
Position = new Vector2(StartPosition.X, s),
|
|
|
|
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
|
2019-10-10 20:55:48 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-28 10:59:21 +08:00
|
|
|
indexFromPlacement = 0;
|
2019-10-10 20:55:48 +08:00
|
|
|
|
2022-05-06 14:45:36 +08:00
|
|
|
for (float s = StartPosition.Y - DistanceBetweenTicks; s >= 0 && indexFromPlacement < MaxIntervals; s -= DistanceBetweenTicks, indexFromPlacement++)
|
2019-10-10 20:55:48 +08:00
|
|
|
{
|
|
|
|
AddInternal(new Circle
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(10, 5),
|
2020-01-28 10:59:21 +08:00
|
|
|
Position = new Vector2(StartPosition.X, s),
|
|
|
|
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
|
2019-10-10 20:55:48 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 11:34:49 +08:00
|
|
|
public override (Vector2 position, double time) GetSnappedPosition(Vector2 screenSpacePosition)
|
|
|
|
=> (Vector2.Zero, 0);
|
2019-10-10 20:55:48 +08:00
|
|
|
}
|
2019-10-25 16:25:46 +08:00
|
|
|
|
2022-04-24 12:08:53 +08:00
|
|
|
private class SnapProvider : IDistanceSnapProvider
|
2019-10-25 16:25:46 +08:00
|
|
|
{
|
2023-05-25 20:41:19 +08:00
|
|
|
public SnapResult FindSnappedPositionAndTime(Vector2 screenSpacePosition, SnapType snapType = SnapType.AllGrids) => new SnapResult(screenSpacePosition, 0);
|
2019-10-25 16:25:46 +08:00
|
|
|
|
2022-05-05 16:42:50 +08:00
|
|
|
public Bindable<double> DistanceSpacingMultiplier { get; } = new BindableDouble(1);
|
|
|
|
|
|
|
|
IBindable<double> IDistanceSnapProvider.DistanceSpacingMultiplier => DistanceSpacingMultiplier;
|
2022-01-18 20:25:32 +08:00
|
|
|
|
2022-11-01 14:00:23 +08:00
|
|
|
public float GetBeatSnapDistanceAt(HitObject referenceObject, bool useReferenceSliderVelocity = true) => beat_snap_distance;
|
2019-10-25 16:25:46 +08:00
|
|
|
|
2021-09-01 17:05:10 +08:00
|
|
|
public float DurationToDistance(HitObject referenceObject, double duration) => (float)duration;
|
2019-10-25 16:25:46 +08:00
|
|
|
|
2021-09-01 17:05:10 +08:00
|
|
|
public double DistanceToDuration(HitObject referenceObject, float distance) => distance;
|
2019-10-25 16:25:46 +08:00
|
|
|
|
2022-05-05 15:25:05 +08:00
|
|
|
public double FindSnappedDuration(HitObject referenceObject, float distance) => 0;
|
2019-10-10 20:55:48 +08:00
|
|
|
|
2022-05-05 15:25:05 +08:00
|
|
|
public float FindSnappedDistance(HitObject referenceObject, float distance) => 0;
|
2019-10-10 20:55:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|