Skip to content

Commit

Permalink
Rename Submit extension method to Apply
Browse files Browse the repository at this point in the history
I think this fits better because it makes clear that this applies the change
  • Loading branch information
OliBomby committed Oct 18, 2024
1 parent 9f62626 commit f0ab9f6
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ private void ensureValidPathType(IReadOnlyList<PathControlPoint> segment)
return;

if (segment.Count > 3)
new PathControlPointTypeChange(first, PathType.BEZIER).Submit(changeHandler);
new PathControlPointTypeChange(first, PathType.BEZIER).Apply(changeHandler);

if (segment.Count != 3)
return;

ReadOnlySpan<Vector2> points = segment.Select(p => p.Position).ToArray();
RectangleF boundingBox = PathApproximator.CircularArcBoundingBox(points);
if (boundingBox.Width >= 640 || boundingBox.Height >= 480)
new PathControlPointTypeChange(first, PathType.BEZIER).Submit(changeHandler);
new PathControlPointTypeChange(first, PathType.BEZIER).Apply(changeHandler);
}

/// <summary>
Expand Down Expand Up @@ -370,19 +370,19 @@ private void updatePathTypeOfSelectedPieces(PathType? type)
int thirdPointIndex = indexInSegment + 2;

if (pointsInSegment.Count > thirdPointIndex + 1)
new PathControlPointTypeChange(pointsInSegment[thirdPointIndex], pointsInSegment[0].Type).Submit(changeHandler);
new PathControlPointTypeChange(pointsInSegment[thirdPointIndex], pointsInSegment[0].Type).Apply(changeHandler);
}

new ExpectedDistanceChange(hitObject.Path, null).Submit(changeHandler);
new PathControlPointTypeChange(p.ControlPoint, type).Submit(changeHandler);
new ExpectedDistanceChange(hitObject.Path, null).Apply(changeHandler);
new PathControlPointTypeChange(p.ControlPoint, type).Apply(changeHandler);
}

EnsureValidPathTypes();

if (hitObject.Path.Distance < originalDistance)
new SnapToChange<T>(hitObject, distanceSnapProvider).Submit(changeHandler);
new SnapToChange<T>(hitObject, distanceSnapProvider).Apply(changeHandler);
else
new ExpectedDistanceChange(hitObject.Path, originalDistance).Submit(changeHandler);
new ExpectedDistanceChange(hitObject.Path, originalDistance).Apply(changeHandler);

changeHandler?.EndChange();
}
Expand Down Expand Up @@ -425,8 +425,8 @@ public void DragInProgress(DragEvent e)

Vector2 movementDelta = Parent!.ToLocalSpace(result?.ScreenSpacePosition ?? newHeadPosition) - hitObject.Position;

new PositionChange(hitObject, hitObject.Position + movementDelta).Submit(changeHandler);
new StartTimeChange(hitObject, result?.Time ?? hitObject.StartTime).Submit(changeHandler);
new PositionChange(hitObject, hitObject.Position + movementDelta).Apply(changeHandler);
new StartTimeChange(hitObject, result?.Time ?? hitObject.StartTime).Apply(changeHandler);

for (int i = 1; i < hitObject.Path.ControlPoints.Count; i++)
{
Expand All @@ -436,7 +436,7 @@ public void DragInProgress(DragEvent e)
// All other selected control points (if any) will move together with the head point
// (and so they will not move at all, relative to each other).
if (!selectedControlPoints.Contains(controlPoint))
new PathControlPointPositionChange(controlPoint, controlPoint.Position - movementDelta).Submit(changeHandler);
new PathControlPointPositionChange(controlPoint, controlPoint.Position - movementDelta).Apply(changeHandler);
}
}
else
Expand All @@ -449,28 +449,28 @@ public void DragInProgress(DragEvent e)
{
PathControlPoint controlPoint = controlPoints[i];
if (selectedControlPoints.Contains(controlPoint))
new PathControlPointPositionChange(controlPoint, dragStartPositions[i] + movementDelta).Submit(changeHandler);
new PathControlPointPositionChange(controlPoint, dragStartPositions[i] + movementDelta).Apply(changeHandler);
}
}

// Snap the path to the current beat divisor before checking length validity.
new SnapToChange<T>(hitObject, distanceSnapProvider).Submit(changeHandler);
new SnapToChange<T>(hitObject, distanceSnapProvider).Apply(changeHandler);

if (!hitObject.Path.HasValidLength)
{
for (int i = 0; i < hitObject.Path.ControlPoints.Count; i++)
new PathControlPointPositionChange(hitObject.Path.ControlPoints[i], oldControlPoints[i]).Submit(changeHandler);
new PathControlPointPositionChange(hitObject.Path.ControlPoints[i], oldControlPoints[i]).Apply(changeHandler);

new PositionChange(hitObject, oldPosition).Submit(changeHandler);
new StartTimeChange(hitObject, oldStartTime).Submit(changeHandler);
new PositionChange(hitObject, oldPosition).Apply(changeHandler);
new StartTimeChange(hitObject, oldStartTime).Apply(changeHandler);
// Snap the path length again to undo the invalid length.
new SnapToChange<T>(hitObject, distanceSnapProvider).Submit(changeHandler);
new SnapToChange<T>(hitObject, distanceSnapProvider).Apply(changeHandler);
return;
}

// Maintain the path types in case they got defaulted to bezier at some point during the drag.
for (int i = 0; i < hitObject.Path.ControlPoints.Count; i++)
new PathControlPointTypeChange(hitObject.Path.ControlPoints[i], dragPathTypes[i]).Submit(changeHandler);
new PathControlPointTypeChange(hitObject.Path.ControlPoints[i], dragPathTypes[i]).Apply(changeHandler);

EnsureValidPathTypes();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ private void adjustLength(double proposedDistance, bool adjustVelocity)
if (Precision.AlmostEquals(proposedDistance, HitObject.Path.Distance) && Precision.AlmostEquals(proposedVelocity, HitObject.SliderVelocityMultiplier))
return;

new SliderVelocityMultiplierChange(HitObject, proposedVelocity).Submit(changeHandler);
new ExpectedDistanceChange(HitObject.Path, proposedDistance).Submit(changeHandler);
new QueueUpdateHitObject(editorBeatmap, HitObject).Submit(changeHandler);
new SliderVelocityMultiplierChange(HitObject, proposedVelocity).Apply(changeHandler);
new ExpectedDistanceChange(HitObject.Path, proposedDistance).Apply(changeHandler);
new QueueUpdateHitObject(editorBeatmap, HitObject).Apply(changeHandler);
}

/// <summary>
Expand All @@ -303,8 +303,8 @@ private void trimExcessControlPoints(SliderPath sliderPath)

if (Precision.AlmostBigger(segmentEnds[segmentIndex], 1, 1E-3))
{
new RemoveRangePathControlPointChange(sliderPath.ControlPoints, i + 1, sliderPath.ControlPoints.Count - i - 1).Submit(changeHandler);
new PathControlPointTypeChange(sliderPath.ControlPoints[^1], null).Submit(changeHandler);
new RemoveRangePathControlPointChange(sliderPath.ControlPoints, i + 1, sliderPath.ControlPoints.Count - i - 1).Apply(changeHandler);
new PathControlPointTypeChange(sliderPath.ControlPoints[^1], null).Apply(changeHandler);
break;
}

Expand Down Expand Up @@ -439,11 +439,11 @@ private PathControlPoint addControlPoint(Vector2 position)
var pathControlPoint = new PathControlPoint { Position = position };

// Move the control points from the insertion index onwards to make room for the insertion
new InsertPathControlPointChange(HitObject.Path.ControlPoints, insertionIndex, pathControlPoint).Submit(changeHandler);
new InsertPathControlPointChange(HitObject.Path.ControlPoints, insertionIndex, pathControlPoint).Apply(changeHandler);

ControlPointVisualiser?.EnsureValidPathTypes();

new SnapToChange<Slider>(HitObject, distanceSnapProvider).Submit(changeHandler);
new SnapToChange<Slider>(HitObject, distanceSnapProvider).Apply(changeHandler);

return pathControlPoint;
}
Expand All @@ -459,15 +459,15 @@ private void removeControlPoints(List<PathControlPoint> toRemove)
// The first control point in the slider must have a type, so take it from the previous "first" one
// Todo: Should be handled within SliderPath itself
if (c == controlPoints[0] && controlPoints.Count > 1 && controlPoints[1].Type == null)
new PathControlPointTypeChange(controlPoints[1], controlPoints[0].Type).Submit(changeHandler);
new PathControlPointTypeChange(controlPoints[1], controlPoints[0].Type).Apply(changeHandler);

new RemovePathControlPointChange(HitObject.Path.ControlPoints, c).Submit(changeHandler);
new RemovePathControlPointChange(HitObject.Path.ControlPoints, c).Apply(changeHandler);
}

ControlPointVisualiser?.EnsureValidPathTypes();

// Snap the slider to the current beat divisor before checking length validity.
new SnapToChange<Slider>(HitObject, distanceSnapProvider).Submit(changeHandler);
new SnapToChange<Slider>(HitObject, distanceSnapProvider).Apply(changeHandler);

// 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)
Expand All @@ -480,9 +480,9 @@ private void removeControlPoints(List<PathControlPoint> toRemove)
// So the slider needs to be offset by this amount instead, and all control points offset backwards such that the path is re-positioned at (0, 0)
Vector2 first = controlPoints[0].Position;
foreach (var c in controlPoints)
new PathControlPointPositionChange(c, c.Position - first).Submit(changeHandler);
new PathControlPointPositionChange(c, c.Position - first).Apply(changeHandler);

new PositionChange(HitObject, HitObject.Position + first).Submit(changeHandler);
new PositionChange(HitObject, HitObject.Position + first).Apply(changeHandler);
}

private void splitControlPoints(List<PathControlPoint> controlPointsToSplitAt)
Expand Down Expand Up @@ -512,7 +512,7 @@ private void splitControlPoints(List<PathControlPoint> controlPointsToSplitAt)

// Extract the split portion and remove from the original slider.
var splitControlPoints = controlPoints.Take(index + 1).ToList();
new RemoveRangePathControlPointChange(HitObject.Path.ControlPoints, 0, index).Submit(changeHandler);
new RemoveRangePathControlPointChange(HitObject.Path.ControlPoints, 0, index).Apply(changeHandler);

var newSlider = new Slider
{
Expand All @@ -526,28 +526,28 @@ private void splitControlPoints(List<PathControlPoint> controlPointsToSplitAt)
};

// Increase the start time of the slider before adding the new slider so the new slider is immediately inserted at the correct index and internal state remains valid.
new StartTimeChange(HitObject, HitObject.StartTime + split_gap).Submit(changeHandler);
new StartTimeChange(HitObject, HitObject.StartTime + split_gap).Apply(changeHandler);

new AddHitObjectChange(editorBeatmap, newSlider).Submit(changeHandler);
new AddHitObjectChange(editorBeatmap, newSlider).Apply(changeHandler);

new NewComboChange(HitObject, false).Submit(changeHandler);
new ExpectedDistanceChange(HitObject.Path, HitObject.Path.ExpectedDistance.Value - newSlider.Path.CalculatedDistance).Submit(changeHandler);
new StartTimeChange(HitObject, HitObject.StartTime + newSlider.SpanDuration).Submit(changeHandler);
new NewComboChange(HitObject, false).Apply(changeHandler);
new ExpectedDistanceChange(HitObject.Path, HitObject.Path.ExpectedDistance.Value - newSlider.Path.CalculatedDistance).Apply(changeHandler);
new StartTimeChange(HitObject, HitObject.StartTime + newSlider.SpanDuration).Apply(changeHandler);

// In case the remainder of the slider has no length left over, give it length anyways so we don't get a 0 length slider.
if (HitObject.Path.ExpectedDistance.Value <= Precision.DOUBLE_EPSILON)
{
new ExpectedDistanceChange(HitObject.Path, null).Submit(changeHandler);
new ExpectedDistanceChange(HitObject.Path, null).Apply(changeHandler);
}
}

// Once all required pieces have been split off, the original slider has the final split.
// As a final step, we must reset its control points to have an origin of (0,0).
Vector2 first = controlPoints[0].Position;
foreach (var c in controlPoints)
new PathControlPointPositionChange(c, c.Position - first).Submit(changeHandler);
new PathControlPointPositionChange(c, c.Position - first).Apply(changeHandler);

new PositionChange(HitObject, HitObject.Position + first).Submit(changeHandler);
new PositionChange(HitObject, HitObject.Position + first).Apply(changeHandler);
}

private void convertToStream()
Expand Down Expand Up @@ -581,13 +581,13 @@ private void convertToStream()
Position = position,
NewCombo = i == 0 && HitObject.NewCombo,
Samples = HitObject.HeadCircle.Samples.Select(s => s.With()).ToList()
}).Submit(changeHandler);
}).Apply(changeHandler);

i += 1;
time = HitObject.StartTime + i * streamSpacing;
}

new RemoveHitObjectChange(editorBeatmap, HitObject).Submit(changeHandler);
new RemoveHitObjectChange(editorBeatmap, HitObject).Apply(changeHandler);

changeHandler?.EndChange();
}
Expand Down
Loading

0 comments on commit f0ab9f6

Please sign in to comment.