From f3ba4297018b97fb4eacd1b4d118a6aeb364e6a2 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Mon, 12 Nov 2018 17:10:37 +0900 Subject: [PATCH] Make sure control points is internally initialised --- .../Components/PathControlPointPiece.cs | 1 - osu.Game/Rulesets/Objects/SliderPath.cs | 26 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs index 22ad911c21..7100d9443e 100644 --- a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Game/Rulesets/Objects/SliderPath.cs b/osu.Game/Rulesets/Objects/SliderPath.cs index 548e1680f7..74a312698c 100644 --- a/osu.Game/Rulesets/Objects/SliderPath.cs +++ b/osu.Game/Rulesets/Objects/SliderPath.cs @@ -13,11 +13,6 @@ namespace osu.Game.Rulesets.Objects { public struct SliderPath : IEquatable { - /// - /// The control points of the path. - /// - public readonly Vector2[] ControlPoints; - /// /// The user-set distance of the path. If non-null, will match this value, /// and the path will be shortened/lengthened to match this length. @@ -29,6 +24,9 @@ namespace osu.Game.Rulesets.Objects /// public readonly PathType Type; + [JsonProperty] + private Vector2[] controlPoints; + private List calculatedPath; private List cumulativeLength; @@ -46,14 +44,27 @@ namespace osu.Game.Rulesets.Objects public SliderPath(PathType type, Vector2[] controlPoints, double? expectedDistance = null) { this = default; + this.controlPoints = controlPoints; - ControlPoints = controlPoints; Type = type; ExpectedDistance = expectedDistance; ensureInitialised(); } + /// + /// The control points of the path. + /// + [JsonIgnore] + public ReadOnlySpan ControlPoints + { + get + { + ensureInitialised(); + return controlPoints.AsSpan(); + } + } + /// /// The distance of the path after lengthening/shortening to account for . /// @@ -116,6 +127,7 @@ namespace osu.Game.Rulesets.Objects return; isInitialised = true; + controlPoints = controlPoints ?? Array.Empty(); calculatedPath = new List(); cumulativeLength = new List(); @@ -166,7 +178,7 @@ namespace osu.Game.Rulesets.Objects if (i == ControlPoints.Length - 1 || ControlPoints[i] == ControlPoints[i + 1]) { - ReadOnlySpan cpSpan = ControlPoints.AsSpan().Slice(start, end - start); + ReadOnlySpan cpSpan = ControlPoints.Slice(start, end - start); foreach (Vector2 t in calculateSubpath(cpSpan)) if (calculatedPath.Count == 0 || calculatedPath.Last() != t)