mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 00:09:55 +09:00
Move beat snapping to its own interface
This commit is contained in:
@ -8,11 +8,12 @@ using osu.Framework.Bindables;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Beatmaps.Timing;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
|
||||
namespace osu.Game.Screens.Edit
|
||||
{
|
||||
public class EditorBeatmap : IBeatmap
|
||||
public class EditorBeatmap : IBeatmap, IBeatSnapProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked when a <see cref="HitObject"/> is added to this <see cref="EditorBeatmap"/>.
|
||||
@ -33,11 +34,14 @@ namespace osu.Game.Screens.Edit
|
||||
|
||||
public readonly IBeatmap PlayableBeatmap;
|
||||
|
||||
private readonly BindableBeatDivisor beatDivisor;
|
||||
|
||||
private readonly Dictionary<HitObject, Bindable<double>> startTimeBindables = new Dictionary<HitObject, Bindable<double>>();
|
||||
|
||||
public EditorBeatmap(IBeatmap playableBeatmap)
|
||||
public EditorBeatmap(IBeatmap playableBeatmap, BindableBeatDivisor beatDivisor = null)
|
||||
{
|
||||
PlayableBeatmap = playableBeatmap;
|
||||
this.beatDivisor = beatDivisor;
|
||||
|
||||
foreach (var obj in HitObjects)
|
||||
trackStartTime(obj);
|
||||
@ -123,5 +127,17 @@ namespace osu.Game.Screens.Edit
|
||||
|
||||
return list.Count - 1;
|
||||
}
|
||||
|
||||
public double SnapTime(double referenceTime, double duration, int beatDivisor)
|
||||
{
|
||||
double beatLength = GetBeatLengthAtTime(referenceTime, beatDivisor);
|
||||
|
||||
// A 1ms offset prevents rounding errors due to minute variations in duration
|
||||
return (int)((duration + 1) / beatLength) * beatLength;
|
||||
}
|
||||
|
||||
public double GetBeatLengthAtTime(double referenceTime, int beatDivisor) => ControlPointInfo.TimingPointAt(referenceTime).BeatLength / BeatDivisor;
|
||||
|
||||
public int BeatDivisor => beatDivisor?.Value ?? 1;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user