mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:33:01 +08:00
Interface the distance snap provider
This commit is contained in:
parent
607b4d874a
commit
4ca6a5a0cc
@ -314,7 +314,8 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Cached(typeof(HitObjectComposer))]
|
[Cached(typeof(HitObjectComposer))]
|
||||||
public abstract class HitObjectComposer : CompositeDrawable
|
[Cached(typeof(IDistanceSnapProvider))]
|
||||||
|
public abstract class HitObjectComposer : CompositeDrawable, IDistanceSnapProvider
|
||||||
{
|
{
|
||||||
internal HitObjectComposer()
|
internal HitObjectComposer()
|
||||||
{
|
{
|
||||||
@ -351,44 +352,10 @@ namespace osu.Game.Rulesets.Edit
|
|||||||
protected virtual DistanceSnapGrid CreateDistanceSnapGrid([NotNull] IEnumerable<HitObject> selectedHitObjects) => null;
|
protected virtual DistanceSnapGrid CreateDistanceSnapGrid([NotNull] IEnumerable<HitObject> selectedHitObjects) => null;
|
||||||
|
|
||||||
public abstract (Vector2 position, double time) GetSnappedPosition(Vector2 position, double time);
|
public abstract (Vector2 position, double time) GetSnappedPosition(Vector2 position, double time);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves the distance between two points within a timing point that are one beat length apart.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="referenceTime">The time of the timing point.</param>
|
|
||||||
/// <returns>The distance between two points residing in the timing point that are one beat length apart.</returns>
|
|
||||||
public abstract float GetBeatSnapDistanceAt(double referenceTime);
|
public abstract float GetBeatSnapDistanceAt(double referenceTime);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts a duration to a distance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="referenceTime">The time of the timing point which <paramref name="duration"/> resides in.</param>
|
|
||||||
/// <param name="duration">The duration to convert.</param>
|
|
||||||
/// <returns>A value that represents <paramref name="duration"/> as a distance in the timing point.</returns>
|
|
||||||
public abstract float DurationToDistance(double referenceTime, double duration);
|
public abstract float DurationToDistance(double referenceTime, double duration);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts a distance to a duration.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="referenceTime">The time of the timing point which <paramref name="distance"/> resides in.</param>
|
|
||||||
/// <param name="distance">The distance to convert.</param>
|
|
||||||
/// <returns>A value that represents <paramref name="distance"/> as a duration in the timing point.</returns>
|
|
||||||
public abstract double DistanceToDuration(double referenceTime, float distance);
|
public abstract double DistanceToDuration(double referenceTime, float distance);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts a distance to a snapped duration.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="referenceTime">The time of the timing point which <paramref name="distance"/> resides in.</param>
|
|
||||||
/// <param name="distance">The distance to convert.</param>
|
|
||||||
/// <returns>A value that represents <paramref name="distance"/> as a duration snapped to the closest beat of the timing point.</returns>
|
|
||||||
public abstract double GetSnappedDurationFromDistance(double referenceTime, float distance);
|
public abstract double GetSnappedDurationFromDistance(double referenceTime, float distance);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts an unsnapped distance to a snapped distance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="referenceTime">The time of the timing point which <paramref name="distance"/> resides in.</param>
|
|
||||||
/// <param name="distance">The distance to convert.</param>
|
|
||||||
/// <returns>A value that represents <paramref name="distance"/> snapped to the closest beat of the timing point.</returns>
|
|
||||||
public abstract float GetSnappedDistanceFromDistance(double referenceTime, float distance);
|
public abstract float GetSnappedDistanceFromDistance(double referenceTime, float distance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
51
osu.Game/Rulesets/Edit/IDistanceSnapProvider.cs
Normal file
51
osu.Game/Rulesets/Edit/IDistanceSnapProvider.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the distance between two points within a timing point that are one beat length apart.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="referenceTime">The time of the timing point.</param>
|
||||||
|
/// <returns>The distance between two points residing in the timing point that are one beat length apart.</returns>
|
||||||
|
float GetBeatSnapDistanceAt(double referenceTime);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a duration to a distance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="referenceTime">The time of the timing point which <paramref name="duration"/> resides in.</param>
|
||||||
|
/// <param name="duration">The duration to convert.</param>
|
||||||
|
/// <returns>A value that represents <paramref name="duration"/> as a distance in the timing point.</returns>
|
||||||
|
float DurationToDistance(double referenceTime, double duration);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a distance to a duration.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="referenceTime">The time of the timing point which <paramref name="distance"/> resides in.</param>
|
||||||
|
/// <param name="distance">The distance to convert.</param>
|
||||||
|
/// <returns>A value that represents <paramref name="distance"/> as a duration in the timing point.</returns>
|
||||||
|
double DistanceToDuration(double referenceTime, float distance);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a distance to a snapped duration.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="referenceTime">The time of the timing point which <paramref name="distance"/> resides in.</param>
|
||||||
|
/// <param name="distance">The distance to convert.</param>
|
||||||
|
/// <returns>A value that represents <paramref name="distance"/> as a duration snapped to the closest beat of the timing point.</returns>
|
||||||
|
double GetSnappedDurationFromDistance(double referenceTime, float distance);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts an unsnapped distance to a snapped distance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="referenceTime">The time of the timing point which <paramref name="distance"/> resides in.</param>
|
||||||
|
/// <param name="distance">The distance to convert.</param>
|
||||||
|
/// <returns>A value that represents <paramref name="distance"/> snapped to the closest beat of the timing point.</returns>
|
||||||
|
float GetSnappedDistanceFromDistance(double referenceTime, float distance);
|
||||||
|
}
|
||||||
|
}
|
@ -45,7 +45,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
private BindableBeatDivisor beatDivisor { get; set; }
|
private BindableBeatDivisor beatDivisor { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private HitObjectComposer composer { get; set; }
|
private IDistanceSnapProvider snapProvider { get; set; }
|
||||||
|
|
||||||
private readonly Cached gridCache = new Cached();
|
private readonly Cached gridCache = new Cached();
|
||||||
private readonly HitObject hitObject;
|
private readonly HitObject hitObject;
|
||||||
@ -73,7 +73,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
private void updateSpacing()
|
private void updateSpacing()
|
||||||
{
|
{
|
||||||
DistanceSpacing = composer.GetBeatSnapDistanceAt(StartTime);
|
DistanceSpacing = snapProvider.GetBeatSnapDistanceAt(StartTime);
|
||||||
gridCache.Invalidate();
|
gridCache.Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user