2021-07-22 15:14:43 +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.
|
|
|
|
|
|
|
|
using System.Linq;
|
2022-01-07 22:11:38 +08:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2021-07-22 15:14:43 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Objects
|
|
|
|
{
|
|
|
|
public static class SliderPathExtensions
|
|
|
|
{
|
2022-01-07 22:11:38 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Snaps the provided <paramref name="hitObject"/>'s duration using the <paramref name="snapProvider"/>.
|
|
|
|
/// </summary>
|
2022-04-28 10:48:45 +08:00
|
|
|
public static void SnapTo<THitObject>(this THitObject hitObject, IDistanceSnapProvider? snapProvider)
|
2022-01-07 22:11:38 +08:00
|
|
|
where THitObject : HitObject, IHasPath
|
|
|
|
{
|
2022-05-05 15:25:05 +08:00
|
|
|
hitObject.Path.ExpectedDistance.Value = snapProvider?.FindSnappedDistance(hitObject, (float)hitObject.Path.CalculatedDistance) ?? hitObject.Path.CalculatedDistance;
|
2022-01-07 22:11:38 +08:00
|
|
|
}
|
|
|
|
|
2021-07-22 15:14:43 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Reverse the direction of this path.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="sliderPath">The <see cref="SliderPath"/>.</param>
|
|
|
|
/// <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();
|
2021-10-26 12:05:46 +08:00
|
|
|
positionalOffset = sliderPath.PositionAt(1);
|
2021-07-22 15:14:43 +08:00
|
|
|
|
|
|
|
sliderPath.ControlPoints.Clear();
|
|
|
|
|
|
|
|
PathType? lastType = null;
|
|
|
|
|
2021-10-27 12:04:41 +08:00
|
|
|
for (int i = 0; i < points.Length; i++)
|
2021-07-22 15:14:43 +08:00
|
|
|
{
|
|
|
|
var p = points[i];
|
2021-08-26 00:42:57 +08:00
|
|
|
p.Position -= positionalOffset;
|
2021-07-22 15:14:43 +08:00
|
|
|
|
|
|
|
// propagate types forwards to last null type
|
|
|
|
if (i == points.Length - 1)
|
2021-10-26 12:05:46 +08:00
|
|
|
{
|
2021-08-26 00:42:57 +08:00
|
|
|
p.Type = lastType;
|
2021-10-26 12:05:46 +08:00
|
|
|
p.Position = Vector2.Zero;
|
|
|
|
}
|
2021-08-26 00:42:57 +08:00
|
|
|
else if (p.Type != null)
|
|
|
|
(p.Type, lastType) = (lastType, p.Type);
|
2021-07-22 15:14:43 +08:00
|
|
|
|
|
|
|
sliderPath.ControlPoints.Insert(0, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|