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

clean up SliderPathExtensions

This commit is contained in:
OliBomby 2024-10-12 12:27:42 +02:00
parent 76981737ff
commit 7a3bc731e0
3 changed files with 16 additions and 53 deletions

View File

@ -466,7 +466,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
ControlPointVisualiser?.EnsureValidPathTypes();
// Snap the slider to the current beat divisor before checking length validity.
HitObject.SnapTo(distanceSnapProvider, commandHandler);
Proxy.SnapTo(distanceSnapProvider);
// If there are 0 or 1 remaining control points, or the slider has an invalid length, it is in a degenerate form and should be deleted
if (controlPoints.Count <= 1 || !HitObject.Path.HasValidLength)

View File

@ -1,11 +1,8 @@
// 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;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Commands;
using osu.Game.Screens.Edit.Commands.Proxies;
using osuTK;
@ -16,25 +13,10 @@ namespace osu.Game.Rulesets.Objects
/// <summary>
/// Snaps the provided <paramref name="hitObject"/>'s duration using the <paramref name="snapProvider"/>.
/// </summary>
public static void SnapTo<THitObject>(this THitObject hitObject, IDistanceSnapProvider? snapProvider, EditorCommandHandler? commandHandler = null)
public static void SnapTo<THitObject>(this THitObject hitObject, IDistanceSnapProvider? snapProvider)
where THitObject : HitObject, IHasPath
{
double distance = snapProvider?.FindSnappedDistance(hitObject, (float)hitObject.Path.CalculatedDistance, DistanceSnapTarget.Start) ?? hitObject.Path.CalculatedDistance;
commandHandler.SafeSubmit(new SetExpectedDistanceCommand(hitObject.Path, distance));
}
/// <summary>
/// Snaps the provided <paramref name="proxy"/>'s duration using the <paramref name="snapProvider"/>.
/// </summary>
public static void SnapTo<THitObject>(this CommandProxy<THitObject> proxy, IDistanceSnapProvider? snapProvider)
where THitObject : HitObject, IHasPath
{
var hitObject = proxy.Target;
double distance = snapProvider?.FindSnappedDistance(hitObject, (float)hitObject.Path.CalculatedDistance, DistanceSnapTarget.Start) ?? hitObject.Path.CalculatedDistance;
proxy.Path().SetExpectedDistance(distance);
proxy.Path().ControlPoints();
hitObject.AsCommandProxy(null).SnapTo(snapProvider);
}
/// <summary>
@ -46,37 +28,5 @@ namespace osu.Game.Rulesets.Objects
{
sliderPath.AsCommandProxy(null).Reverse(out positionalOffset);
}
/// <summary>
/// Reverses the order of the provided <see cref="SliderPath"/>'s <see cref="PathControlPoint"/>s.
/// </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>
private static void reverseControlPoints(this SliderPath sliderPath, out Vector2 positionalOffset)
{
var points = sliderPath.ControlPoints.ToArray();
positionalOffset = sliderPath.PositionAt(1);
sliderPath.ControlPoints.Clear();
PathType? lastType = null;
for (int i = 0; i < points.Length; i++)
{
var p = points[i];
p.Position -= positionalOffset;
// propagate types forwards to last null type
if (i == points.Length - 1)
{
p.Type = lastType;
p.Position = Vector2.Zero;
}
else if (p.Type != null)
(p.Type, lastType) = (lastType, p.Type);
sliderPath.ControlPoints.Insert(0, p);
}
}
}
}

View File

@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osuTK;
@ -11,6 +12,18 @@ namespace osu.Game.Screens.Edit.Commands.Proxies
{
public static class SliderPathCommandProxyExtensions
{
/// <summary>
/// Snaps the provided <paramref name="proxy"/>'s duration using the <paramref name="snapProvider"/>.
/// </summary>
public static void SnapTo<THitObject>(this CommandProxy<THitObject> proxy, IDistanceSnapProvider? snapProvider)
where THitObject : HitObject, IHasPath
{
var hitObject = proxy.Target;
double distance = snapProvider?.FindSnappedDistance(hitObject, (float)hitObject.Path.CalculatedDistance, DistanceSnapTarget.Start) ?? hitObject.Path.CalculatedDistance;
proxy.Path().SetExpectedDistance(distance);
}
public static void Reverse(this CommandProxy<SliderPath> pathProxy, out Vector2 positionalOffset)
{
var sliderPath = pathProxy.Target;