1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 05:37:24 +08:00

Moved HitObject adjustment methods to a static helper class

This commit is contained in:
Aurelian 2024-06-12 19:57:17 +02:00
parent 9906ab3449
commit 9b076a8b03
4 changed files with 42 additions and 38 deletions

View File

@ -2,14 +2,9 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Utils;
using osu.Game.Beatmaps.Timing;
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osuTK.Graphics;
namespace osu.Game.Beatmaps.ControlPoints
@ -110,35 +105,5 @@ namespace osu.Game.Beatmaps.ControlPoints
&& BeatLength.Equals(other.BeatLength);
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), TimeSignature, BeatLength, OmitFirstBarLine);
public List<HitObject> HitObjectsInTimingRange(IBeatmap beatmap)
{
// If the first group, we grab all hitobjects prior to the next, if the last group, we grab all remaining hitobjects
double startTime = beatmap.ControlPointInfo.TimingPoints.Any(x => x.Time < Time) ? Time : double.MinValue;
double endTime = beatmap.ControlPointInfo.TimingPoints.FirstOrDefault(x => x.Time > Time)?.Time ?? double.MaxValue;
return beatmap.HitObjects.Where(x => Precision.AlmostBigger(x.StartTime, startTime) && Precision.DefinitelyBigger(endTime, x.StartTime)).ToList();
}
public void AdjustHitObjectOffset(IBeatmap beatmap, double adjust)
{
foreach (HitObject hitObject in HitObjectsInTimingRange(beatmap))
{
hitObject.StartTime += adjust;
}
}
public void SetHitObjectBPM(IBeatmap beatmap, double oldBeatLength)
{
foreach (HitObject hitObject in HitObjectsInTimingRange(beatmap))
{
double beat = (hitObject.StartTime - Time) / oldBeatLength;
hitObject.StartTime = (beat * BeatLength) + Time;
if (hitObject is not IHasRepeats && hitObject is IHasDuration hitObjectWithDuration)
hitObjectWithDuration.Duration *= BeatLength / oldBeatLength;
}
}
}
}

View File

@ -112,7 +112,7 @@ namespace osu.Game.Screens.Edit.Timing
{
// Only adjust hit object offsets if the group contains a timing control point
if (Beatmap.AdjustNotesOnOffsetBPMChange.Value && cp is TimingControlPoint tp)
tp.AdjustHitObjectOffset(Beatmap, time - SelectedGroup.Value.Time);
TimingSectionAdjustments.AdjustHitObjectOffset(Beatmap, tp, time - SelectedGroup.Value.Time);
Beatmap.ControlPointInfo.Add(time, cp);
}

View File

@ -209,7 +209,7 @@ namespace osu.Game.Screens.Edit.Timing
foreach (var cp in currentGroupItems)
{
if (beatmap.AdjustNotesOnOffsetBPMChange.Value && cp is TimingControlPoint tp)
tp.AdjustHitObjectOffset(beatmap, adjust);
TimingSectionAdjustments.AdjustHitObjectOffset(beatmap, tp, adjust);
beatmap.ControlPointInfo.Add(newOffset, cp);
}

View File

@ -1,11 +1,17 @@
// 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.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Screens.Edit.Timing
{
@ -48,7 +54,7 @@ namespace osu.Game.Screens.Edit.Timing
if (!Beatmap.AdjustNotesOnOffsetBPMChange.Value || ControlPoint.Value == null)
return;
ControlPoint.Value.SetHitObjectBPM(Beatmap, val.OldValue);
TimingSectionAdjustments.SetHitObjectBPM(Beatmap, ControlPoint.Value, val.OldValue);
Beatmap.UpdateAllHitObjects();
});
}
@ -128,4 +134,37 @@ namespace osu.Game.Screens.Edit.Timing
private static double beatLengthToBpm(double beatLength) => 60000 / beatLength;
}
public static class TimingSectionAdjustments
{
public static List<HitObject> HitObjectsInTimingRange(IBeatmap beatmap, double time)
{
// If the first group, we grab all hitobjects prior to the next, if the last group, we grab all remaining hitobjects
double startTime = beatmap.ControlPointInfo.TimingPoints.Any(x => x.Time < time) ? time : double.MinValue;
double endTime = beatmap.ControlPointInfo.TimingPoints.FirstOrDefault(x => x.Time > time)?.Time ?? double.MaxValue;
return beatmap.HitObjects.Where(x => Precision.AlmostBigger(x.StartTime, startTime) && Precision.DefinitelyBigger(endTime, x.StartTime)).ToList();
}
public static void AdjustHitObjectOffset(IBeatmap beatmap, TimingControlPoint timingControlPoint, double adjust)
{
foreach (HitObject hitObject in HitObjectsInTimingRange(beatmap, timingControlPoint.Time))
{
hitObject.StartTime += adjust;
}
}
public static void SetHitObjectBPM(IBeatmap beatmap, TimingControlPoint timingControlPoint, double oldBeatLength)
{
foreach (HitObject hitObject in HitObjectsInTimingRange(beatmap, timingControlPoint.Time))
{
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;
}
}
}
}