1
0
mirror of https://github.com/ppy/osu.git synced 2024-10-01 02:57:24 +08:00
osu-lazer/osu.Game/Rulesets/Edit/IPositionSnapProvider.cs
Salman Ahmed 528dc03b8c Expose distance spacing in IPositionSnapProvider for updating distance grid
Alternate method is to expose a `SnapDistancesChanged` event in
`IPositionSnapProvider` instead, but I chose this way as an analogue to
`IBeatSnapProvider.BeatDivisor`, which might even make sense to be
exposed as `BindableBeatDivisor` instead of caching that separately.
2022-02-15 02:21:53 +03:00

77 lines
4.0 KiB
C#

// 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 osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Objects;
using osuTK;
namespace osu.Game.Rulesets.Edit
{
public interface IPositionSnapProvider
{
/// <summary>
/// The spacing multiplier applied to beat snap distances.
/// </summary>
/// <seealso cref="BeatmapInfo.DistanceSpacing"/>
IBindable<float> DistanceSpacingMultiplier { get; }
/// <summary>
/// Given a position, find a valid time and position snap.
/// </summary>
/// <remarks>
/// This call should be equivalent to running <see cref="SnapScreenSpacePositionToValidPosition"/> with any additional logic that can be performed without the time immutability restriction.
/// </remarks>
/// <param name="screenSpacePosition">The screen-space position to be snapped.</param>
/// <returns>The time and position post-snapping.</returns>
SnapResult SnapScreenSpacePositionToValidTime(Vector2 screenSpacePosition);
/// <summary>
/// Given a position, find a value position snap, restricting time to its input value.
/// </summary>
/// <param name="screenSpacePosition">The screen-space position to be snapped.</param>
/// <returns>The position post-snapping. Time will always be null.</returns>
SnapResult SnapScreenSpacePositionToValidPosition(Vector2 screenSpacePosition);
/// <summary>
/// Retrieves the distance between two points within a timing point that are one beat length apart.
/// </summary>
/// <param name="referenceObject">An object to be used as a reference point for this operation.</param>
/// <returns>The distance between two points residing in the timing point that are one beat length apart.</returns>
float GetBeatSnapDistanceAt(HitObject referenceObject);
/// <summary>
/// Converts a duration to a distance.
/// </summary>
/// <param name="referenceObject">An object to be used as a reference point for this operation.</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(HitObject referenceObject, double duration);
/// <summary>
/// Converts a distance to a duration.
/// </summary>
/// <param name="referenceObject">An object to be used as a reference point for this operation.</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(HitObject referenceObject, float distance);
/// <summary>
/// Converts a distance to a snapped duration.
/// </summary>
/// <param name="referenceObject">An object to be used as a reference point for this operation.</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(HitObject referenceObject, float distance);
/// <summary>
/// Converts an unsnapped distance to a snapped distance.
/// The returned distance will always be floored (as to never exceed the provided <paramref name="distance"/>.
/// </summary>
/// <param name="referenceObject">An object to be used as a reference point for this operation.</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(HitObject referenceObject, float distance);
}
}