2019-10-25 09:19:26 +00: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 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2019-10-25 09:19:26 +00:00
|
|
|
using NUnit.Framework;
|
2020-01-01 15:41:06 +00:00
|
|
|
using osu.Framework.Allocation;
|
2022-04-28 03:46:20 +00:00
|
|
|
using osu.Framework.Bindables;
|
2020-02-05 08:32:33 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-10-25 09:19:26 +00:00
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2020-01-23 05:39:56 +00:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2021-09-01 09:05:10 +00:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2019-10-25 09:19:26 +00:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2020-01-01 15:41:06 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
2019-10-25 09:19:26 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Edit;
|
|
|
|
using osu.Game.Screens.Edit;
|
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
|
2020-04-23 08:07:55 +00:00
|
|
|
namespace osu.Game.Tests.Editing
|
2019-10-25 09:19:26 +00:00
|
|
|
{
|
|
|
|
[HeadlessTest]
|
|
|
|
public class TestSceneHitObjectComposerDistanceSnapping : EditorClockTestScene
|
|
|
|
{
|
|
|
|
private TestHitObjectComposer composer;
|
|
|
|
|
2020-01-01 15:41:06 +00:00
|
|
|
[Cached(typeof(EditorBeatmap))]
|
2020-01-23 05:39:56 +00:00
|
|
|
[Cached(typeof(IBeatSnapProvider))]
|
|
|
|
private readonly EditorBeatmap editorBeatmap;
|
|
|
|
|
2020-02-05 08:32:33 +00:00
|
|
|
protected override Container<Drawable> Content { get; }
|
|
|
|
|
2020-01-23 05:39:56 +00:00
|
|
|
public TestSceneHitObjectComposerDistanceSnapping()
|
|
|
|
{
|
2020-02-05 08:32:33 +00:00
|
|
|
base.Content.Add(new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-01-12 14:17:35 +00:00
|
|
|
editorBeatmap = new EditorBeatmap(new OsuBeatmap
|
|
|
|
{
|
|
|
|
BeatmapInfo =
|
|
|
|
{
|
|
|
|
Ruleset = new OsuRuleset().RulesetInfo,
|
|
|
|
},
|
|
|
|
}),
|
2020-02-05 08:32:33 +00:00
|
|
|
Content = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2020-01-23 05:39:56 +00:00
|
|
|
}
|
2020-01-01 15:41:06 +00:00
|
|
|
|
2019-10-25 09:19:26 +00:00
|
|
|
[SetUp]
|
|
|
|
public void Setup() => Schedule(() =>
|
|
|
|
{
|
2020-02-05 08:32:33 +00:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
composer = new TestHitObjectComposer()
|
|
|
|
};
|
2019-10-25 09:19:26 +00:00
|
|
|
|
|
|
|
BeatDivisor.Value = 1;
|
|
|
|
|
2021-10-02 03:34:29 +00:00
|
|
|
composer.EditorBeatmap.Difficulty.SliderMultiplier = 1;
|
2019-10-28 02:52:04 +00:00
|
|
|
composer.EditorBeatmap.ControlPointInfo.Clear();
|
|
|
|
composer.EditorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = 1000 });
|
2019-10-25 09:19:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
[TestCase(1)]
|
|
|
|
[TestCase(2)]
|
|
|
|
public void TestSliderMultiplier(float multiplier)
|
|
|
|
{
|
2022-04-28 03:46:20 +00:00
|
|
|
AddStep($"set slider multiplier = {multiplier}", () => composer.EditorBeatmap.Difficulty.SliderMultiplier = multiplier);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
|
|
|
assertSnapDistance(100 * multiplier);
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(1)]
|
|
|
|
[TestCase(2)]
|
|
|
|
public void TestSpeedMultiplier(float multiplier)
|
|
|
|
{
|
2021-09-02 10:42:41 +00:00
|
|
|
assertSnapDistance(100 * multiplier, new HitObject
|
2019-10-25 09:19:26 +00:00
|
|
|
{
|
2021-09-02 10:42:41 +00:00
|
|
|
DifficultyControlPoint = new DifficultyControlPoint
|
|
|
|
{
|
|
|
|
SliderVelocity = multiplier
|
|
|
|
}
|
2019-10-25 09:19:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[TestCase(1)]
|
|
|
|
[TestCase(2)]
|
|
|
|
public void TestBeatDivisor(int divisor)
|
|
|
|
{
|
|
|
|
AddStep($"set divisor = {divisor}", () => BeatDivisor.Value = divisor);
|
|
|
|
|
|
|
|
assertSnapDistance(100f / divisor);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestConvertDurationToDistance()
|
|
|
|
{
|
|
|
|
assertDurationToDistance(500, 50);
|
|
|
|
assertDurationToDistance(1000, 100);
|
|
|
|
|
2021-10-02 03:34:29 +00:00
|
|
|
AddStep("set slider multiplier = 2", () => composer.EditorBeatmap.Difficulty.SliderMultiplier = 2);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
|
|
|
assertDurationToDistance(500, 100);
|
|
|
|
assertDurationToDistance(1000, 200);
|
|
|
|
|
|
|
|
AddStep("set beat length = 500", () =>
|
|
|
|
{
|
2019-10-28 02:52:04 +00:00
|
|
|
composer.EditorBeatmap.ControlPointInfo.Clear();
|
|
|
|
composer.EditorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = 500 });
|
2019-10-25 09:19:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assertDurationToDistance(500, 200);
|
|
|
|
assertDurationToDistance(1000, 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestConvertDistanceToDuration()
|
|
|
|
{
|
|
|
|
assertDistanceToDuration(50, 500);
|
|
|
|
assertDistanceToDuration(100, 1000);
|
|
|
|
|
2021-10-02 03:34:29 +00:00
|
|
|
AddStep("set slider multiplier = 2", () => composer.EditorBeatmap.Difficulty.SliderMultiplier = 2);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
|
|
|
assertDistanceToDuration(100, 500);
|
|
|
|
assertDistanceToDuration(200, 1000);
|
|
|
|
|
|
|
|
AddStep("set beat length = 500", () =>
|
|
|
|
{
|
2019-10-28 02:52:04 +00:00
|
|
|
composer.EditorBeatmap.ControlPointInfo.Clear();
|
|
|
|
composer.EditorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = 500 });
|
2019-10-25 09:19:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assertDistanceToDuration(200, 500);
|
|
|
|
assertDistanceToDuration(400, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestGetSnappedDurationFromDistance()
|
|
|
|
{
|
2020-01-28 04:42:22 +00:00
|
|
|
assertSnappedDuration(0, 0);
|
|
|
|
assertSnappedDuration(50, 1000);
|
2019-10-25 09:19:26 +00:00
|
|
|
assertSnappedDuration(100, 1000);
|
2020-01-28 04:42:22 +00:00
|
|
|
assertSnappedDuration(150, 2000);
|
2019-10-25 09:19:26 +00:00
|
|
|
assertSnappedDuration(200, 2000);
|
2020-01-28 04:42:22 +00:00
|
|
|
assertSnappedDuration(250, 3000);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
2021-10-02 03:34:29 +00:00
|
|
|
AddStep("set slider multiplier = 2", () => composer.EditorBeatmap.Difficulty.SliderMultiplier = 2);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
2020-01-28 04:42:22 +00:00
|
|
|
assertSnappedDuration(0, 0);
|
2019-10-25 09:19:26 +00:00
|
|
|
assertSnappedDuration(50, 0);
|
2020-01-28 04:42:22 +00:00
|
|
|
assertSnappedDuration(100, 1000);
|
|
|
|
assertSnappedDuration(150, 1000);
|
2019-10-25 09:19:26 +00:00
|
|
|
assertSnappedDuration(200, 1000);
|
|
|
|
assertSnappedDuration(250, 1000);
|
|
|
|
|
|
|
|
AddStep("set beat length = 500", () =>
|
|
|
|
{
|
2019-10-28 02:52:04 +00:00
|
|
|
composer.EditorBeatmap.ControlPointInfo.Clear();
|
|
|
|
composer.EditorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = 500 });
|
2019-10-25 09:19:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assertSnappedDuration(50, 0);
|
2020-01-28 04:42:22 +00:00
|
|
|
assertSnappedDuration(100, 500);
|
|
|
|
assertSnappedDuration(150, 500);
|
2019-10-25 09:19:26 +00:00
|
|
|
assertSnappedDuration(200, 500);
|
|
|
|
assertSnappedDuration(250, 500);
|
|
|
|
assertSnappedDuration(400, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetSnappedDistanceFromDistance()
|
|
|
|
{
|
2020-08-25 09:56:15 +00:00
|
|
|
assertSnappedDistance(50, 0);
|
2019-10-25 09:19:26 +00:00
|
|
|
assertSnappedDistance(100, 100);
|
2020-08-25 09:56:15 +00:00
|
|
|
assertSnappedDistance(150, 100);
|
2019-10-25 09:19:26 +00:00
|
|
|
assertSnappedDistance(200, 200);
|
2020-08-25 09:56:15 +00:00
|
|
|
assertSnappedDistance(250, 200);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
2021-10-02 03:34:29 +00:00
|
|
|
AddStep("set slider multiplier = 2", () => composer.EditorBeatmap.Difficulty.SliderMultiplier = 2);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
|
|
|
assertSnappedDistance(50, 0);
|
2020-08-25 09:56:15 +00:00
|
|
|
assertSnappedDistance(100, 0);
|
|
|
|
assertSnappedDistance(150, 0);
|
2019-10-25 09:19:26 +00:00
|
|
|
assertSnappedDistance(200, 200);
|
|
|
|
assertSnappedDistance(250, 200);
|
|
|
|
|
|
|
|
AddStep("set beat length = 500", () =>
|
|
|
|
{
|
2019-10-28 02:52:04 +00:00
|
|
|
composer.EditorBeatmap.ControlPointInfo.Clear();
|
|
|
|
composer.EditorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = 500 });
|
2019-10-25 09:19:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assertSnappedDistance(50, 0);
|
2020-08-25 09:56:15 +00:00
|
|
|
assertSnappedDistance(100, 0);
|
|
|
|
assertSnappedDistance(150, 0);
|
2019-10-25 09:19:26 +00:00
|
|
|
assertSnappedDistance(200, 200);
|
|
|
|
assertSnappedDistance(250, 200);
|
|
|
|
assertSnappedDistance(400, 400);
|
|
|
|
}
|
|
|
|
|
2021-09-02 10:42:41 +00:00
|
|
|
private void assertSnapDistance(float expectedDistance, HitObject hitObject = null)
|
|
|
|
=> AddAssert($"distance is {expectedDistance}", () => composer.GetBeatSnapDistanceAt(hitObject ?? new HitObject()) == expectedDistance);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
|
|
|
private void assertDurationToDistance(double duration, float expectedDistance)
|
2021-09-01 09:05:10 +00:00
|
|
|
=> AddAssert($"duration = {duration} -> distance = {expectedDistance}", () => composer.DurationToDistance(new HitObject(), duration) == expectedDistance);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
|
|
|
private void assertDistanceToDuration(float distance, double expectedDuration)
|
2021-09-01 09:05:10 +00:00
|
|
|
=> AddAssert($"distance = {distance} -> duration = {expectedDuration}", () => composer.DistanceToDuration(new HitObject(), distance) == expectedDuration);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
|
|
|
private void assertSnappedDuration(float distance, double expectedDuration)
|
2022-05-05 07:25:05 +00:00
|
|
|
=> AddAssert($"distance = {distance} -> duration = {expectedDuration} (snapped)", () => composer.FindSnappedDuration(new HitObject(), distance) == expectedDuration);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
|
|
|
private void assertSnappedDistance(float distance, float expectedDistance)
|
2022-05-05 07:25:05 +00:00
|
|
|
=> AddAssert($"distance = {distance} -> distance = {expectedDistance} (snapped)", () => composer.FindSnappedDistance(new HitObject(), distance) == expectedDistance);
|
2019-10-25 09:19:26 +00:00
|
|
|
|
|
|
|
private class TestHitObjectComposer : OsuHitObjectComposer
|
|
|
|
{
|
2019-12-27 10:39:30 +00:00
|
|
|
public new EditorBeatmap EditorBeatmap => base.EditorBeatmap;
|
2019-10-25 09:19:26 +00:00
|
|
|
|
2022-04-29 05:02:07 +00:00
|
|
|
public new Bindable<double> DistanceSpacingMultiplier => base.DistanceSpacingMultiplier;
|
2022-04-28 03:46:20 +00:00
|
|
|
|
2019-10-25 09:19:26 +00:00
|
|
|
public TestHitObjectComposer()
|
|
|
|
: base(new OsuRuleset())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|