mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 08:20:00 +09:00
Move beat snapping to its own interface
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
// 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 System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Bindables;
|
||||
@ -10,7 +11,6 @@ using osu.Framework.Graphics.Audio;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osuTK;
|
||||
@ -169,53 +169,25 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private BindableBeatDivisor beatDivisor { get; set; }
|
||||
private EditorBeatmap beatmap { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private EditorBeatmap beatmap { get; set; }
|
||||
private IBeatSnapProvider beatSnapProvider { get; set; }
|
||||
|
||||
public (Vector2 position, double time) GetSnappedPosition(Vector2 position, double time)
|
||||
{
|
||||
var targetTime = (position.X / Content.DrawWidth) * track.Length;
|
||||
return (position, beatSnap(targetTime, targetTime));
|
||||
return (position, beatSnapProvider.SnapTime(targetTime, targetTime, beatSnapProvider.BeatDivisor));
|
||||
}
|
||||
|
||||
public float GetBeatSnapDistanceAt(double referenceTime)
|
||||
{
|
||||
DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(referenceTime);
|
||||
return (float)(100 * beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier * difficultyPoint.SpeedMultiplier / beatDivisor.Value);
|
||||
}
|
||||
public float GetBeatSnapDistanceAt(double referenceTime) => throw new NotImplementedException();
|
||||
|
||||
public float DurationToDistance(double referenceTime, double duration)
|
||||
{
|
||||
double beatLength = beatmap.ControlPointInfo.TimingPointAt(referenceTime).BeatLength / beatDivisor.Value;
|
||||
return (float)(duration / beatLength * GetBeatSnapDistanceAt(referenceTime));
|
||||
}
|
||||
public float DurationToDistance(double referenceTime, double duration) => throw new NotImplementedException();
|
||||
|
||||
public double DistanceToDuration(double referenceTime, float distance)
|
||||
{
|
||||
double beatLength = beatmap.ControlPointInfo.TimingPointAt(referenceTime).BeatLength / beatDivisor.Value;
|
||||
return distance / GetBeatSnapDistanceAt(referenceTime) * beatLength;
|
||||
}
|
||||
public double DistanceToDuration(double referenceTime, float distance) => throw new NotImplementedException();
|
||||
|
||||
public double GetSnappedDurationFromDistance(double referenceTime, float distance)
|
||||
=> beatSnap(referenceTime, DistanceToDuration(referenceTime, distance));
|
||||
public double GetSnappedDurationFromDistance(double referenceTime, float distance) => throw new NotImplementedException();
|
||||
|
||||
public float GetSnappedDistanceFromDistance(double referenceTime, float distance)
|
||||
=> DurationToDistance(referenceTime, beatSnap(referenceTime, DistanceToDuration(referenceTime, distance)));
|
||||
|
||||
/// <summary>
|
||||
/// Snaps a duration to the closest beat of a timing point applicable at the reference time.
|
||||
/// </summary>
|
||||
/// <param name="referenceTime">The time of the timing point which <paramref name="duration"/> resides in.</param>
|
||||
/// <param name="duration">The duration to snap.</param>
|
||||
/// <returns>A value that represents <paramref name="duration"/> snapped to the closest beat of the timing point.</returns>
|
||||
private double beatSnap(double referenceTime, double duration)
|
||||
{
|
||||
double beatLength = beatmap.ControlPointInfo.TimingPointAt(referenceTime).BeatLength / beatDivisor.Value;
|
||||
|
||||
// A 1ms offset prevents rounding errors due to minute variations in duration
|
||||
return (int)((duration + 1) / beatLength) * beatLength;
|
||||
}
|
||||
public float GetSnappedDistanceFromDistance(double referenceTime, float distance) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user