1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-10 23:12:54 +08:00
osu-lazer/osu.Game/Screens/Edit/Timing/TimingSectionAdjustments.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
2.7 KiB
C#
Raw Normal View History

2024-09-02 15:52:00 +08:00
// 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.Collections.Generic;
using System.Linq;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Screens.Edit.Timing
{
public static class TimingSectionAdjustments
{
2024-09-02 15:59:19 +08:00
/// <summary>
/// Returns all objects from <paramref name="beatmap"/> which are affected by the supplied <paramref name="timingControlPoint"/>.
/// </summary>
public static List<HitObject> HitObjectsInTimingRange(IBeatmap beatmap, TimingControlPoint timingControlPoint)
2024-09-02 15:52:00 +08:00
{
// If the first group, we grab all hitobjects prior to the next, if the last group, we grab all remaining hitobjects
2024-09-02 15:59:19 +08:00
double startTime = beatmap.ControlPointInfo.TimingPoints.Any(x => x.Time < timingControlPoint.Time) ? timingControlPoint.Time : double.MinValue;
double endTime = beatmap.ControlPointInfo.TimingPoints.FirstOrDefault(x => x.Time > timingControlPoint.Time)?.Time ?? double.MaxValue;
2024-09-02 15:52:00 +08:00
return beatmap.HitObjects.Where(x => Precision.AlmostBigger(x.StartTime, startTime) && Precision.DefinitelyBigger(endTime, x.StartTime)).ToList();
}
2024-09-02 15:59:19 +08:00
/// <summary>
/// Moves all relevant objects after <paramref name="timingControlPoint"/>'s offset has been changed by <paramref name="adjustment"/>.
/// </summary>
public static void AdjustHitObjectOffset(IBeatmap beatmap, TimingControlPoint timingControlPoint, double adjustment)
2024-09-02 15:52:00 +08:00
{
2024-09-02 15:59:19 +08:00
foreach (HitObject hitObject in HitObjectsInTimingRange(beatmap, timingControlPoint))
2024-09-02 15:52:00 +08:00
{
2024-09-02 15:59:19 +08:00
hitObject.StartTime += adjustment;
2024-09-02 15:52:00 +08:00
}
}
2024-09-02 15:59:19 +08:00
/// <summary>
/// Ensures all relevant objects are still snapped to the same beats after <paramref name="timingControlPoint"/>'s beat length / BPM has been changed.
/// </summary>
2024-09-02 15:52:00 +08:00
public static void SetHitObjectBPM(IBeatmap beatmap, TimingControlPoint timingControlPoint, double oldBeatLength)
{
2024-09-02 15:59:19 +08:00
foreach (HitObject hitObject in HitObjectsInTimingRange(beatmap, timingControlPoint))
2024-09-02 15:52:00 +08:00
{
double beat = (hitObject.StartTime - timingControlPoint.Time) / oldBeatLength;
hitObject.StartTime = (beat * timingControlPoint.BeatLength) + timingControlPoint.Time;
if (hitObject is not IHasRepeats && hitObject is IHasDuration hitObjectWithDuration)
hitObjectWithDuration.Duration *= timingControlPoint.BeatLength / oldBeatLength;
}
}
}
}