Refactor flow of snapping through HitObjectComposer

This commit is contained in:
smoogipoo
2019-10-25 12:34:49 +09:00
parent a6458fdeab
commit 607b4d874a
9 changed files with 128 additions and 89 deletions

View File

@ -2,9 +2,11 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osuTK;
@ -12,6 +14,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
public abstract class CircularDistanceSnapGrid : DistanceSnapGrid
{
[Resolved]
private HitObjectComposer composer { get; set; }
protected CircularDistanceSnapGrid(HitObject hitObject, Vector2 centrePosition)
: base(hitObject, centrePosition)
{
@ -63,7 +68,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
}
}
public override Vector2 GetSnappedPosition(Vector2 position)
public override (Vector2 position, double time) GetSnappedPosition(Vector2 position)
{
Vector2 direction = position - CentrePosition;
@ -76,7 +81,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
int radialCount = Math.Max(1, (int)Math.Round(distance / radius));
Vector2 normalisedDirection = direction * new Vector2(1f / distance);
return CentrePosition + normalisedDirection * radialCount * radius;
Vector2 snappedPosition = CentrePosition + normalisedDirection * radialCount * radius;
return (snappedPosition, StartTime + composer.GetSnappedDurationFromDistance(StartTime, (snappedPosition - CentrePosition).Length));
}
}
}