From 4ca6a5a0cc4fb841c35171dde5affcef9c0786fa Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 25 Oct 2019 16:50:21 +0900 Subject: [PATCH] Interface the distance snap provider --- osu.Game/Rulesets/Edit/HitObjectComposer.cs | 37 +------------- .../Rulesets/Edit/IDistanceSnapProvider.cs | 51 +++++++++++++++++++ .../Compose/Components/DistanceSnapGrid.cs | 4 +- 3 files changed, 55 insertions(+), 37 deletions(-) create mode 100644 osu.Game/Rulesets/Edit/IDistanceSnapProvider.cs diff --git a/osu.Game/Rulesets/Edit/HitObjectComposer.cs b/osu.Game/Rulesets/Edit/HitObjectComposer.cs index beb0d38216..5922bfba78 100644 --- a/osu.Game/Rulesets/Edit/HitObjectComposer.cs +++ b/osu.Game/Rulesets/Edit/HitObjectComposer.cs @@ -314,7 +314,8 @@ namespace osu.Game.Rulesets.Edit } [Cached(typeof(HitObjectComposer))] - public abstract class HitObjectComposer : CompositeDrawable + [Cached(typeof(IDistanceSnapProvider))] + public abstract class HitObjectComposer : CompositeDrawable, IDistanceSnapProvider { internal HitObjectComposer() { @@ -351,44 +352,10 @@ namespace osu.Game.Rulesets.Edit protected virtual DistanceSnapGrid CreateDistanceSnapGrid([NotNull] IEnumerable selectedHitObjects) => null; public abstract (Vector2 position, double time) GetSnappedPosition(Vector2 position, double time); - - /// - /// Retrieves the distance between two points within a timing point that are one beat length apart. - /// - /// The time of the timing point. - /// The distance between two points residing in the timing point that are one beat length apart. public abstract float GetBeatSnapDistanceAt(double referenceTime); - - /// - /// Converts a duration to a distance. - /// - /// The time of the timing point which resides in. - /// The duration to convert. - /// A value that represents as a distance in the timing point. public abstract float DurationToDistance(double referenceTime, double duration); - - /// - /// Converts a distance to a duration. - /// - /// The time of the timing point which resides in. - /// The distance to convert. - /// A value that represents as a duration in the timing point. public abstract double DistanceToDuration(double referenceTime, float distance); - - /// - /// Converts a distance to a snapped duration. - /// - /// The time of the timing point which resides in. - /// The distance to convert. - /// A value that represents as a duration snapped to the closest beat of the timing point. public abstract double GetSnappedDurationFromDistance(double referenceTime, float distance); - - /// - /// Converts an unsnapped distance to a snapped distance. - /// - /// The time of the timing point which resides in. - /// The distance to convert. - /// A value that represents snapped to the closest beat of the timing point. public abstract float GetSnappedDistanceFromDistance(double referenceTime, float distance); } } diff --git a/osu.Game/Rulesets/Edit/IDistanceSnapProvider.cs b/osu.Game/Rulesets/Edit/IDistanceSnapProvider.cs new file mode 100644 index 0000000000..c6e61f68da --- /dev/null +++ b/osu.Game/Rulesets/Edit/IDistanceSnapProvider.cs @@ -0,0 +1,51 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osuTK; + +namespace osu.Game.Rulesets.Edit +{ + public interface IDistanceSnapProvider + { + (Vector2 position, double time) GetSnappedPosition(Vector2 position, double time); + + /// + /// Retrieves the distance between two points within a timing point that are one beat length apart. + /// + /// The time of the timing point. + /// The distance between two points residing in the timing point that are one beat length apart. + float GetBeatSnapDistanceAt(double referenceTime); + + /// + /// Converts a duration to a distance. + /// + /// The time of the timing point which resides in. + /// The duration to convert. + /// A value that represents as a distance in the timing point. + float DurationToDistance(double referenceTime, double duration); + + /// + /// Converts a distance to a duration. + /// + /// The time of the timing point which resides in. + /// The distance to convert. + /// A value that represents as a duration in the timing point. + double DistanceToDuration(double referenceTime, float distance); + + /// + /// Converts a distance to a snapped duration. + /// + /// The time of the timing point which resides in. + /// The distance to convert. + /// A value that represents as a duration snapped to the closest beat of the timing point. + double GetSnappedDurationFromDistance(double referenceTime, float distance); + + /// + /// Converts an unsnapped distance to a snapped distance. + /// + /// The time of the timing point which resides in. + /// The distance to convert. + /// A value that represents snapped to the closest beat of the timing point. + float GetSnappedDistanceFromDistance(double referenceTime, float distance); + } +} diff --git a/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs b/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs index 9eaccc5ac3..d6ee6063ef 100644 --- a/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs +++ b/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs @@ -45,7 +45,7 @@ namespace osu.Game.Screens.Edit.Compose.Components private BindableBeatDivisor beatDivisor { get; set; } [Resolved] - private HitObjectComposer composer { get; set; } + private IDistanceSnapProvider snapProvider { get; set; } private readonly Cached gridCache = new Cached(); private readonly HitObject hitObject; @@ -73,7 +73,7 @@ namespace osu.Game.Screens.Edit.Compose.Components private void updateSpacing() { - DistanceSpacing = composer.GetBeatSnapDistanceAt(StartTime); + DistanceSpacing = snapProvider.GetBeatSnapDistanceAt(StartTime); gridCache.Invalidate(); }