mirror of
https://github.com/osukey/osukey.git
synced 2025-05-05 21:57:24 +09:00
Make expected distance a bindable
This commit is contained in:
parent
2702edfa55
commit
986ac1cee4
@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Objects
|
|||||||
/// The user-set distance of the path. If non-null, <see cref="Distance"/> will match this value,
|
/// The user-set distance of the path. If non-null, <see cref="Distance"/> will match this value,
|
||||||
/// and the path will be shortened/lengthened to match this length.
|
/// and the path will be shortened/lengthened to match this length.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly double? ExpectedDistance;
|
public readonly Bindable<double?> ExpectedDistance = new Bindable<double?>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The control points of the path.
|
/// The control points of the path.
|
||||||
@ -43,7 +43,8 @@ namespace osu.Game.Rulesets.Objects
|
|||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public SliderPath(PathControlPoint[] controlPoints = null, double? expectedDistance = null)
|
public SliderPath(PathControlPoint[] controlPoints = null, double? expectedDistance = null)
|
||||||
{
|
{
|
||||||
ExpectedDistance = expectedDistance;
|
ExpectedDistance.Value = expectedDistance;
|
||||||
|
ExpectedDistance.ValueChanged += _ => pathCache.Invalidate();
|
||||||
|
|
||||||
ControlPoints.ItemsAdded += items =>
|
ControlPoints.ItemsAdded += items =>
|
||||||
{
|
{
|
||||||
@ -205,18 +206,20 @@ namespace osu.Game.Rulesets.Objects
|
|||||||
cumulativeLength.Clear();
|
cumulativeLength.Clear();
|
||||||
cumulativeLength.Add(l);
|
cumulativeLength.Add(l);
|
||||||
|
|
||||||
|
double? expectedDistance = ExpectedDistance.Value;
|
||||||
|
|
||||||
for (int i = 0; i < calculatedPath.Count - 1; ++i)
|
for (int i = 0; i < calculatedPath.Count - 1; ++i)
|
||||||
{
|
{
|
||||||
Vector2 diff = calculatedPath[i + 1] - calculatedPath[i];
|
Vector2 diff = calculatedPath[i + 1] - calculatedPath[i];
|
||||||
double d = diff.Length;
|
double d = diff.Length;
|
||||||
|
|
||||||
// Shorted slider paths that are too long compared to the expected distance
|
// Shorted slider paths that are too long compared to the expected distance
|
||||||
if (ExpectedDistance.HasValue && ExpectedDistance - l < d)
|
if (expectedDistance.HasValue && expectedDistance - l < d)
|
||||||
{
|
{
|
||||||
calculatedPath[i + 1] = calculatedPath[i] + diff * (float)((ExpectedDistance - l) / d);
|
calculatedPath[i + 1] = calculatedPath[i] + diff * (float)((expectedDistance - l) / d);
|
||||||
calculatedPath.RemoveRange(i + 2, calculatedPath.Count - 2 - i);
|
calculatedPath.RemoveRange(i + 2, calculatedPath.Count - 2 - i);
|
||||||
|
|
||||||
l = ExpectedDistance.Value;
|
l = expectedDistance.Value;
|
||||||
cumulativeLength.Add(l);
|
cumulativeLength.Add(l);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -226,7 +229,7 @@ namespace osu.Game.Rulesets.Objects
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lengthen slider paths that are too short compared to the expected distance
|
// Lengthen slider paths that are too short compared to the expected distance
|
||||||
if (ExpectedDistance.HasValue && l < ExpectedDistance && calculatedPath.Count > 1)
|
if (expectedDistance.HasValue && l < expectedDistance && calculatedPath.Count > 1)
|
||||||
{
|
{
|
||||||
Vector2 diff = calculatedPath[calculatedPath.Count - 1] - calculatedPath[calculatedPath.Count - 2];
|
Vector2 diff = calculatedPath[calculatedPath.Count - 1] - calculatedPath[calculatedPath.Count - 2];
|
||||||
double d = diff.Length;
|
double d = diff.Length;
|
||||||
@ -234,8 +237,8 @@ namespace osu.Game.Rulesets.Objects
|
|||||||
if (d <= 0)
|
if (d <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
calculatedPath[calculatedPath.Count - 1] += diff * (float)((ExpectedDistance - l) / d);
|
calculatedPath[calculatedPath.Count - 1] += diff * (float)((expectedDistance - l) / d);
|
||||||
cumulativeLength[calculatedPath.Count - 1] = ExpectedDistance.Value;
|
cumulativeLength[calculatedPath.Count - 1] = expectedDistance.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user