mirror of
https://github.com/ppy/osu.git
synced 2024-11-16 04:47:50 +08:00
Move helper class out to separate file
This commit is contained in:
parent
d5ef32e46b
commit
ca2dc702e6
@ -1,17 +1,11 @@
|
||||
// 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
|
||||
{
|
||||
@ -135,37 +129,4 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
46
osu.Game/Screens/Edit/Timing/TimingSectionAdjustments.cs
Normal file
46
osu.Game/Screens/Edit/Timing/TimingSectionAdjustments.cs
Normal file
@ -0,0 +1,46 @@
|
||||
// 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
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user