1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 19:03:08 +08:00
This commit is contained in:
cs 2023-11-11 15:02:06 +01:00
parent 3f85aa79c5
commit 54b8244a18
11 changed files with 37 additions and 38 deletions

View File

@ -261,17 +261,17 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
switch (pathType)
{
case { SplineType: SplineType.Catmull }:
case { Type: SplineType.Catmull }:
return colours.SeaFoam;
case { SplineType: SplineType.BSpline, Degree: null }:
case { Type: SplineType.BSpline, Degree: null }:
return colours.PinkLighter;
case { SplineType: SplineType.BSpline, Degree: >= 1 }:
case { Type: SplineType.BSpline, Degree: >= 1 }:
int idx = Math.Clamp(pathType.Degree.Value, 0, 3);
return new[] { colours.PinkDarker, colours.PinkDark, colours.Pink, colours.PinkLight }[idx];
case { SplineType: SplineType.PerfectCurve }:
case { Type: SplineType.PerfectCurve }:
return colours.PurpleDark;
default:

View File

@ -242,7 +242,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
{
int indexInSegment = piece.PointsInSegment.IndexOf(piece.ControlPoint);
if (type.HasValue && type.Value.SplineType == SplineType.PerfectCurve)
if (type.HasValue && type.Value.Type == SplineType.PerfectCurve)
{
// Can't always create a circular arc out of 4 or more points,
// so we split the segment into one 3-point circular arc segment

View File

@ -173,9 +173,11 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
setState(SliderPlacementState.Drawing);
return true;
}
return false;
}
}
return base.OnDragStart(e);
}

View File

@ -19,7 +19,7 @@ namespace osu.Game.Rulesets.Osu.Edit
Precision = 0.01f
};
private BindableInt sliderTolerance = new BindableInt(10)
private readonly BindableInt sliderTolerance = new BindableInt(10)
{
MinValue = 5,
MaxValue = 100
@ -27,8 +27,6 @@ namespace osu.Game.Rulesets.Osu.Edit
private ExpandableSlider<int> toleranceSlider = null!;
private EditorToolboxGroup? toolboxGroup;
public OsuSliderDrawingSettingsProvider()
{
sliderTolerance.BindValueChanged(v =>
@ -47,7 +45,7 @@ namespace osu.Game.Rulesets.Osu.Edit
public void AttachToToolbox(ExpandingToolboxContainer toolboxContainer)
{
toolboxContainer.Add(toolboxGroup = new EditorToolboxGroup("drawing")
toolboxContainer.Add(new EditorToolboxGroup("drawing")
{
Children = new Drawable[]
{
@ -60,8 +58,8 @@ namespace osu.Game.Rulesets.Osu.Edit
sliderTolerance.BindValueChanged(e =>
{
toleranceSlider.ContractedLabelText = $"Tolerance: {e.NewValue:N0}";
toleranceSlider.ExpandedLabelText = $"Tolerance: {e.NewValue:N0}";
toleranceSlider.ContractedLabelText = $"C. P. S.: {e.NewValue:N0}";
toleranceSlider.ExpandedLabelText = $"Control Point Spacing: {e.NewValue:N0}";
}, true);
}
}

View File

@ -120,7 +120,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[TestCase(SplineType.Catmull, null)]
[TestCase(SplineType.PerfectCurve, null)]
public void TestSingleSegment(SplineType splineType, int? degree)
=> AddStep("create path", () => path.ControlPoints.AddRange(createSegment(new PathType { SplineType = splineType, Degree = degree }, Vector2.Zero, new Vector2(0, 100), new Vector2(100))));
=> AddStep("create path", () => path.ControlPoints.AddRange(createSegment(new PathType { Type = splineType, Degree = degree }, Vector2.Zero, new Vector2(0, 100), new Vector2(100))));
[TestCase(SplineType.Linear, null)]
[TestCase(SplineType.BSpline, null)]
@ -132,7 +132,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("create path", () =>
{
path.ControlPoints.AddRange(createSegment(PathType.LINEAR, Vector2.Zero));
path.ControlPoints.AddRange(createSegment(new PathType { SplineType = splineType, Degree = degree }, new Vector2(0, 100), new Vector2(100), Vector2.Zero));
path.ControlPoints.AddRange(createSegment(new PathType { Type = splineType, Degree = degree }, new Vector2(0, 100), new Vector2(100), Vector2.Zero));
});
}

View File

@ -59,7 +59,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[TestCase(SplineType.PerfectCurve, null)]
public void TestSingleSegment(SplineType splineType, int? degree)
=> AddStep("create path", () => path.ControlPoints.AddRange(createSegment(
new PathType { SplineType = splineType, Degree = degree },
new PathType { Type = splineType, Degree = degree },
Vector2.Zero,
new Vector2(0, 100),
new Vector2(100),
@ -77,7 +77,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("create path", () =>
{
path.ControlPoints.AddRange(createSegment(PathType.LINEAR, Vector2.Zero));
path.ControlPoints.AddRange(createSegment(new PathType { SplineType = splineType, Degree = degree }, new Vector2(0, 100), new Vector2(100), Vector2.Zero));
path.ControlPoints.AddRange(createSegment(new PathType { Type = splineType, Degree = degree }, new Vector2(0, 100), new Vector2(100), Vector2.Zero));
});
}

View File

@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
@ -456,23 +455,23 @@ namespace osu.Game.Beatmaps.Formats
{
switch (point.Type)
{
case { SplineType: SplineType.BSpline, Degree: > 0 }:
case { Type: SplineType.BSpline, Degree: > 0 }:
writer.Write($"B{point.Type.Value.Degree}|");
break;
case { SplineType: SplineType.BSpline, Degree: <= 0 }:
case { Type: SplineType.BSpline, Degree: <= 0 }:
writer.Write("B|");
break;
case { SplineType: SplineType.Catmull }:
case { Type: SplineType.Catmull }:
writer.Write("C|");
break;
case { SplineType: SplineType.PerfectCurve }:
case { Type: SplineType.PerfectCurve }:
writer.Write("P|");
break;
case { SplineType: SplineType.Linear }:
case { Type: SplineType.Linear }:
writer.Write("L|");
break;
}

View File

@ -72,15 +72,15 @@ namespace osu.Game.Rulesets.Objects
switch (segmentType)
{
case { SplineType: SplineType.Catmull }:
case { Type: SplineType.Catmull }:
result.AddRange(from segment in ConvertCatmullToBezierAnchors(segmentVertices) from v in segment select v + position);
break;
case { SplineType: SplineType.Linear }:
case { Type: SplineType.Linear }:
result.AddRange(from segment in ConvertLinearToBezierAnchors(segmentVertices) from v in segment select v + position);
break;
case { SplineType: SplineType.PerfectCurve }:
case { Type: SplineType.PerfectCurve }:
result.AddRange(ConvertCircleToBezierAnchors(segmentVertices).Select(v => v + position));
break;
@ -128,7 +128,7 @@ namespace osu.Game.Rulesets.Objects
switch (segmentType)
{
case { SplineType: SplineType.Catmull }:
case { Type: SplineType.Catmull }:
foreach (var segment in ConvertCatmullToBezierAnchors(segmentVertices))
{
for (int j = 0; j < segment.Length - 1; j++)
@ -139,7 +139,7 @@ namespace osu.Game.Rulesets.Objects
break;
case { SplineType: SplineType.Linear }:
case { Type: SplineType.Linear }:
foreach (var segment in ConvertLinearToBezierAnchors(segmentVertices))
{
for (int j = 0; j < segment.Length - 1; j++)
@ -150,7 +150,7 @@ namespace osu.Game.Rulesets.Objects
break;
case { SplineType: SplineType.PerfectCurve }:
case { Type: SplineType.PerfectCurve }:
var circleResult = ConvertCircleToBezierAnchors(segmentVertices);
for (int j = 0; j < circleResult.Length - 1; j++)

View File

@ -228,7 +228,8 @@ namespace osu.Game.Rulesets.Objects.Legacy
case 'B':
if (input.Length > 1 && int.TryParse(input.Substring(1), out int degree) && degree > 0)
return new PathType { SplineType = SplineType.BSpline, Degree = degree };
return new PathType { Type = SplineType.BSpline, Degree = degree };
return new PathType(SplineType.BSpline);
case 'L':

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using Microsoft.Toolkit.HighPerformance;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Framework.Caching;
@ -289,7 +288,7 @@ namespace osu.Game.Rulesets.Objects
private List<Vector2> calculateSubPath(ReadOnlySpan<Vector2> subControlPoints, PathType type)
{
switch (type.SplineType)
switch (type.Type)
{
case SplineType.Linear:
return PathApproximator.LinearToPiecewiseLinear(subControlPoints);

View File

@ -14,7 +14,7 @@ namespace osu.Game.Rulesets.Objects.Types
PerfectCurve
}
public struct PathType
public readonly struct PathType
{
public static readonly PathType CATMULL = new PathType(SplineType.Catmull);
public static readonly PathType BEZIER = new PathType(SplineType.BSpline);
@ -24,36 +24,36 @@ namespace osu.Game.Rulesets.Objects.Types
/// <summary>
/// The type of the spline that should be used to interpret the control points of the path.
/// </summary>
public SplineType SplineType { get; init; }
public SplineType Type { get; init; }
/// <summary>
/// The degree of a BSpline. Unused if <see cref="SplineType"/> is not <see cref="SplineType.BSpline"/>.
/// The degree of a BSpline. Unused if <see cref="Type"/> is not <see cref="SplineType.BSpline"/>.
/// Null means the degree is equal to the number of control points, 1 means linear, 2 means quadratic, etc.
/// </summary>
public int? Degree { get; init; }
public PathType(SplineType splineType)
{
SplineType = splineType;
Type = splineType;
Degree = null;
}
public override int GetHashCode()
=> HashCode.Combine(SplineType, Degree);
=> HashCode.Combine(Type, Degree);
public override bool Equals(object? obj)
=> obj is PathType pathType && this == pathType;
public static bool operator ==(PathType a, PathType b)
=> a.SplineType == b.SplineType && a.Degree == b.Degree;
=> a.Type == b.Type && a.Degree == b.Degree;
public static bool operator !=(PathType a, PathType b)
=> a.SplineType != b.SplineType || a.Degree != b.Degree;
=> a.Type != b.Type || a.Degree != b.Degree;
public static PathType BSpline(int degree)
{
Debug.Assert(degree > 0);
return new PathType { SplineType = SplineType.BSpline, Degree = degree };
return new PathType { Type = SplineType.BSpline, Degree = degree };
}
}
}