1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 12:42:54 +08:00

Merge pull request #9977 from peppy/fix-slider-path-placement-length-limit

Fix snapped distances potentially exceeding the source distance
This commit is contained in:
Dan Balasescu 2020-08-25 21:27:50 +09:00 committed by GitHub
commit 4806dd8648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 9 deletions

View File

@ -169,17 +169,17 @@ namespace osu.Game.Tests.Editing
[Test]
public void GetSnappedDistanceFromDistance()
{
assertSnappedDistance(50, 100);
assertSnappedDistance(50, 0);
assertSnappedDistance(100, 100);
assertSnappedDistance(150, 200);
assertSnappedDistance(150, 100);
assertSnappedDistance(200, 200);
assertSnappedDistance(250, 300);
assertSnappedDistance(250, 200);
AddStep("set slider multiplier = 2", () => composer.EditorBeatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier = 2);
assertSnappedDistance(50, 0);
assertSnappedDistance(100, 200);
assertSnappedDistance(150, 200);
assertSnappedDistance(100, 0);
assertSnappedDistance(150, 0);
assertSnappedDistance(200, 200);
assertSnappedDistance(250, 200);
@ -190,8 +190,8 @@ namespace osu.Game.Tests.Editing
});
assertSnappedDistance(50, 0);
assertSnappedDistance(100, 200);
assertSnappedDistance(150, 200);
assertSnappedDistance(100, 0);
assertSnappedDistance(150, 0);
assertSnappedDistance(200, 200);
assertSnappedDistance(250, 200);
assertSnappedDistance(400, 400);

View File

@ -25,7 +25,7 @@ using osu.Game.Screens.Edit.Components.RadioButtons;
using osu.Game.Screens.Edit.Compose;
using osu.Game.Screens.Edit.Compose.Components;
using osuTK;
using Key = osuTK.Input.Key;
using osuTK.Input;
namespace osu.Game.Rulesets.Edit
{
@ -293,7 +293,16 @@ namespace osu.Game.Rulesets.Edit
public override float GetSnappedDistanceFromDistance(double referenceTime, float distance)
{
var snappedEndTime = BeatSnapProvider.SnapTime(referenceTime + DistanceToDuration(referenceTime, distance), referenceTime);
double actualDuration = referenceTime + DistanceToDuration(referenceTime, distance);
double snappedEndTime = BeatSnapProvider.SnapTime(actualDuration, referenceTime);
double beatLength = BeatSnapProvider.GetBeatLengthAtTime(referenceTime);
// we don't want to exceed the actual duration and snap to a point in the future.
// as we are snapping to beat length via SnapTime (which will round-to-nearest), check for snapping in the forward direction and reverse it.
if (snappedEndTime > actualDuration + 1)
snappedEndTime -= beatLength;
return DurationToDistance(referenceTime, snappedEndTime - referenceTime);
}

View File

@ -47,6 +47,7 @@ namespace osu.Game.Rulesets.Edit
/// <summary>
/// Converts an unsnapped distance to a snapped distance.
/// The returned distance will always be floored (as to never exceed the provided <paramref name="distance"/>.
/// </summary>
/// <param name="referenceTime">The time of the timing point which <paramref name="distance"/> resides in.</param>
/// <param name="distance">The distance to convert.</param>