1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 10:32:55 +08:00
osu-lazer/osu.Game.Tests/Visual/Editing/TestSceneDistanceSnapGrid.cs

173 lines
6.1 KiB
C#
Raw Normal View History

// 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 NUnit.Framework;
using osu.Framework.Allocation;
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;
using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Compose.Components;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Tests.Visual.Editing
{
public class TestSceneDistanceSnapGrid : EditorClockTestScene
{
private const double beat_length = 100;
private static readonly Vector2 grid_position = new Vector2(512, 384);
[Cached(typeof(EditorBeatmap))]
2019-12-27 18:39:30 +08:00
private readonly EditorBeatmap editorBeatmap;
[Cached(typeof(IPositionSnapProvider))]
2019-10-25 16:25:46 +08:00
private readonly SnapProvider snapProvider = new SnapProvider();
public TestSceneDistanceSnapGrid()
{
2019-12-27 18:39:30 +08:00
editorBeatmap = new EditorBeatmap(new OsuBeatmap());
2019-10-25 18:48:01 +08:00
editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = beat_length });
2019-11-06 15:20:13 +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
},
new TestDistanceSnapGrid()
2019-10-25 16:25:46 +08:00
};
2019-11-06 15:20:13 +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)
{
AddStep($"set beat divisor = {divisor}", () => BeatDivisor.Value = divisor);
}
2019-11-06 15:20:13 +08:00
[Test]
public void TestLimitedDistance()
{
AddStep("create limited grid", () =>
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.SlateGray
},
new TestDistanceSnapGrid(100)
2019-11-06 15:20:13 +08:00
};
});
}
private class TestDistanceSnapGrid : DistanceSnapGrid
{
public new float DistanceSpacing => base.DistanceSpacing;
public TestDistanceSnapGrid(double? endTime = null)
: base(grid_position, 0, endTime)
{
}
protected override void CreateContent()
{
AddInternal(new Circle
{
Origin = Anchor.Centre,
Size = new Vector2(5),
Position = StartPosition
});
int indexFromPlacement = 0;
for (float s = StartPosition.X + DistanceSpacing; s <= DrawWidth && indexFromPlacement < MaxIntervals; s += DistanceSpacing, indexFromPlacement++)
{
AddInternal(new Circle
{
Origin = Anchor.Centre,
Size = new Vector2(5, 10),
Position = new Vector2(s, StartPosition.Y),
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
});
}
indexFromPlacement = 0;
for (float s = StartPosition.X - DistanceSpacing; s >= 0 && indexFromPlacement < MaxIntervals; s -= DistanceSpacing, indexFromPlacement++)
{
AddInternal(new Circle
{
Origin = Anchor.Centre,
Size = new Vector2(5, 10),
Position = new Vector2(s, StartPosition.Y),
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
});
}
indexFromPlacement = 0;
for (float s = StartPosition.Y + DistanceSpacing; s <= DrawHeight && indexFromPlacement < MaxIntervals; s += DistanceSpacing, indexFromPlacement++)
{
AddInternal(new Circle
{
Origin = Anchor.Centre,
Size = new Vector2(10, 5),
Position = new Vector2(StartPosition.X, s),
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
});
}
indexFromPlacement = 0;
for (float s = StartPosition.Y - DistanceSpacing; s >= 0 && indexFromPlacement < MaxIntervals; s -= DistanceSpacing, indexFromPlacement++)
{
AddInternal(new Circle
{
Origin = Anchor.Centre,
Size = new Vector2(10, 5),
Position = new Vector2(StartPosition.X, s),
Colour = GetColourForIndexFromPlacement(indexFromPlacement)
});
}
}
public override (Vector2 position, double time) GetSnappedPosition(Vector2 screenSpacePosition)
=> (Vector2.Zero, 0);
}
2019-10-25 16:25:46 +08:00
private class SnapProvider : IPositionSnapProvider
2019-10-25 16:25:46 +08:00
{
public SnapResult SnapScreenSpacePositionToValidPosition(Vector2 screenSpacePosition) =>
new SnapResult(screenSpacePosition, null);
public SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition) => new SnapResult(screenSpacePosition, 0);
2019-10-25 16:25:46 +08:00
public float GetBeatSnapDistanceAt(double referenceTime) => 10;
2019-11-06 15:20:13 +08:00
public float DurationToDistance(double referenceTime, double duration) => (float)duration;
2019-10-25 16:25:46 +08:00
2019-11-06 15:20:13 +08:00
public double DistanceToDuration(double referenceTime, float distance) => distance;
2019-10-25 16:25:46 +08:00
public double GetSnappedDurationFromDistance(double referenceTime, float distance) => 0;
2019-10-25 16:25:46 +08:00
public float GetSnappedDistanceFromDistance(double referenceTime, float distance) => 0;
}
}
}