1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 04:02:57 +08:00

Fix sliders being reversed incorrectly in the editor.

This commit is contained in:
Pasi4K5 2023-08-12 20:30:48 +02:00
parent 5b44124ecf
commit 8912a0e91e
2 changed files with 55 additions and 4 deletions

View File

@ -202,7 +202,7 @@ namespace osu.Game.Rulesets.Objects
{
ensureValid();
return segmentEnds.Select(i => cumulativeLength[i] / calculatedLength);
return segmentEnds.Select(i => cumulativeLength[Math.Clamp(i, 0, cumulativeLength.Count - 1)] / calculatedLength);
}
private void invalidate()

View File

@ -1,7 +1,10 @@
// 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 System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Utils;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Types;
using osuTK;
@ -26,10 +29,58 @@ namespace osu.Game.Rulesets.Objects
/// <param name="positionalOffset">The positional offset of the resulting path. It should be added to the start position of this path.</param>
public static void Reverse(this SliderPath sliderPath, out Vector2 positionalOffset)
{
var points = sliderPath.ControlPoints.ToArray();
var controlPoints = sliderPath.ControlPoints;
double[] segmentEnds = sliderPath.GetSegmentEnds().ToArray();
double[] distinctSegmentEnds = segmentEnds.Distinct().ToArray();
// Remove control points at the end which do not affect the visual slider path ("invisible" control points).
if (segmentEnds[^1] == segmentEnds[^2] && distinctSegmentEnds.Length > 1)
{
int numVisibleSegments = distinctSegmentEnds.Length - 2;
var nonInheritedControlPoints = controlPoints.Where(p => p.Type is not null).ToList();
var lastVisibleControlPoint = nonInheritedControlPoints[numVisibleSegments];
int lastVisibleControlPointIndex = controlPoints.IndexOf(lastVisibleControlPoint);
if (controlPoints.Count > lastVisibleControlPointIndex + 1)
{
// Make sure to include all inherited control points directly after the last visible non-inherited control point.
do
{
lastVisibleControlPointIndex++;
} while (lastVisibleControlPointIndex + 1 < controlPoints.Count && controlPoints[lastVisibleControlPointIndex].Type is null);
}
// Remove all control points after the first invisible non-inherited control point.
controlPoints.RemoveRange(lastVisibleControlPointIndex + 1, controlPoints.Count - lastVisibleControlPointIndex - 1);
}
// Recalculate perfect curve at the end of the slider path.
if (controlPoints.Count >= 3 && controlPoints[^3].Type == PathType.PerfectCurve && controlPoints[^2].Type is null && distinctSegmentEnds.Length > 1)
{
double lastSegmentStart = distinctSegmentEnds[^2];
double lastSegmentEnd = distinctSegmentEnds[^1];
var oldCircleArcPath = new List<Vector2>();
sliderPath.GetPathToProgress(oldCircleArcPath, lastSegmentStart / lastSegmentEnd, 1);
var newCircleArcPoints = new[]
{
oldCircleArcPath[0],
oldCircleArcPath[oldCircleArcPath.Count / 2],
oldCircleArcPath[^1]
};
var newCircleArcPath = PathApproximator.ApproximateCircularArc(newCircleArcPoints.AsSpan());
controlPoints[^2].Position = newCircleArcPath[newCircleArcPath.Count / 2];
}
// Reverse the control points.
var points = controlPoints.ToArray();
positionalOffset = sliderPath.PositionAt(1);
sliderPath.ControlPoints.Clear();
controlPoints.Clear();
PathType? lastType = null;
@ -47,7 +98,7 @@ namespace osu.Game.Rulesets.Objects
else if (p.Type != null)
(p.Type, lastType) = (lastType, p.Type);
sliderPath.ControlPoints.Insert(0, p);
controlPoints.Insert(0, p);
}
}
}