Skip to content

Commit

Permalink
Remove no longer required nested object reposition hacks
Browse files Browse the repository at this point in the history
As touched on in
ppy#30237 (comment), these
types of maneouvers are no longer required after
ppy#30021 - although as it turns out on
closer inspection, these things being there still *did not actually
break anything*, because the `slider.Path` mutation at the end of
`modifySlider()` causes `updateNestedPositions()` to be called
eventually anyway. So this is at mostly a code quality upgrade.
  • Loading branch information
bdach committed Oct 14, 2024
1 parent 6e4438a commit f629be8
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions osu.Game.Rulesets.Osu/Utils/OsuHitObjectGenerationUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Beatmaps;
Expand Down Expand Up @@ -117,10 +116,9 @@ public static void ReflectHorizontallyAlongPlayfield(OsuHitObject osuObject)
if (osuObject is not Slider slider)
return;

void reflectNestedObject(OsuHitObject nested) => nested.Position = new Vector2(OsuPlayfield.BASE_SIZE.X - nested.Position.X, nested.Position.Y);
static void reflectControlPoint(PathControlPoint point) => point.Position = new Vector2(-point.Position.X, point.Position.Y);

modifySlider(slider, reflectNestedObject, reflectControlPoint);
modifySlider(slider, reflectControlPoint);
}

/// <summary>
Expand All @@ -134,10 +132,9 @@ public static void ReflectVerticallyAlongPlayfield(OsuHitObject osuObject)
if (osuObject is not Slider slider)
return;

void reflectNestedObject(OsuHitObject nested) => nested.Position = new Vector2(nested.Position.X, OsuPlayfield.BASE_SIZE.Y - nested.Position.Y);
static void reflectControlPoint(PathControlPoint point) => point.Position = new Vector2(point.Position.X, -point.Position.Y);

modifySlider(slider, reflectNestedObject, reflectControlPoint);
modifySlider(slider, reflectControlPoint);
}

/// <summary>
Expand All @@ -146,10 +143,9 @@ public static void ReflectVerticallyAlongPlayfield(OsuHitObject osuObject)
/// <param name="slider">The slider to be flipped.</param>
public static void FlipSliderInPlaceHorizontally(Slider slider)
{
void flipNestedObject(OsuHitObject nested) => nested.Position = new Vector2(slider.X - (nested.X - slider.X), nested.Y);
static void flipControlPoint(PathControlPoint point) => point.Position = new Vector2(-point.Position.X, point.Position.Y);

modifySlider(slider, flipNestedObject, flipControlPoint);
modifySlider(slider, flipControlPoint);
}

/// <summary>
Expand All @@ -159,18 +155,13 @@ public static void FlipSliderInPlaceHorizontally(Slider slider)
/// <param name="rotation">The angle, measured in radians, to rotate the slider by.</param>
public static void RotateSlider(Slider slider, float rotation)
{
void rotateNestedObject(OsuHitObject nested) => nested.Position = rotateVector(nested.Position - slider.Position, rotation) + slider.Position;
void rotateControlPoint(PathControlPoint point) => point.Position = rotateVector(point.Position, rotation);

modifySlider(slider, rotateNestedObject, rotateControlPoint);
modifySlider(slider, rotateControlPoint);
}

private static void modifySlider(Slider slider, Action<OsuHitObject> modifyNestedObject, Action<PathControlPoint> modifyControlPoint)
private static void modifySlider(Slider slider, Action<PathControlPoint> modifyControlPoint)
{
// No need to update the head and tail circles, since slider handles that when the new slider path is set
slider.NestedHitObjects.OfType<SliderTick>().ForEach(modifyNestedObject);
slider.NestedHitObjects.OfType<SliderRepeat>().ForEach(modifyNestedObject);

var controlPoints = slider.Path.ControlPoints.Select(p => new PathControlPoint(p.Position, p.Type)).ToArray();
foreach (var point in controlPoints)
modifyControlPoint(point);
Expand Down

0 comments on commit f629be8

Please sign in to comment.