mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:07:44 +08:00
Implement and use equality comparers for ControlPoint
This commit is contained in:
parent
8242236ddf
commit
2882981f9c
@ -14,6 +14,12 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
|
||||
public int CompareTo(ControlPoint other) => Time.CompareTo(other.Time);
|
||||
|
||||
public bool Equals(ControlPoint other) => Time.Equals(other?.Time);
|
||||
public virtual bool Equals(ControlPoint other)
|
||||
{
|
||||
if (ReferenceEquals(null, other)) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
|
||||
return Time.Equals(other.Time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,5 +17,10 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
}
|
||||
|
||||
private double speedMultiplier = 1;
|
||||
|
||||
public override bool Equals(ControlPoint other)
|
||||
=> base.Equals(other)
|
||||
&& other is DifficultyControlPoint difficulty
|
||||
&& SpeedMultiplier == difficulty.SpeedMultiplier;
|
||||
}
|
||||
}
|
||||
|
@ -14,5 +14,11 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// Whether the first bar line of this control point is ignored.
|
||||
/// </summary>
|
||||
public bool OmitFirstBarLine;
|
||||
|
||||
public override bool Equals(ControlPoint other)
|
||||
=> base.Equals(other)
|
||||
&& other is EffectControlPoint effect
|
||||
&& KiaiMode == effect.KiaiMode
|
||||
&& OmitFirstBarLine == effect.OmitFirstBarLine;
|
||||
}
|
||||
}
|
||||
|
@ -30,5 +30,11 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
Name = sampleName,
|
||||
Volume = SampleVolume,
|
||||
};
|
||||
|
||||
public override bool Equals(ControlPoint other)
|
||||
=> base.Equals(other)
|
||||
&& other is SampleControlPoint sample
|
||||
&& SampleBank == sample.SampleBank
|
||||
&& SampleVolume == sample.SampleVolume;
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,11 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
}
|
||||
|
||||
private double beatLength = 1000;
|
||||
|
||||
public override bool Equals(ControlPoint other)
|
||||
=> base.Equals(other)
|
||||
&& other is TimingControlPoint timing
|
||||
&& TimeSignature == timing.TimeSignature
|
||||
&& BeatLength == timing.beatLength;
|
||||
}
|
||||
}
|
||||
|
@ -314,13 +314,9 @@ namespace osu.Game.Beatmaps.Formats
|
||||
if (stringSampleSet == @"none")
|
||||
stringSampleSet = @"normal";
|
||||
|
||||
DifficultyControlPoint difficultyPoint = beatmap.ControlPointInfo.DifficultyPointAt(time);
|
||||
SampleControlPoint samplePoint = beatmap.ControlPointInfo.SamplePointAt(time);
|
||||
EffectControlPoint effectPoint = beatmap.ControlPointInfo.EffectPointAt(time);
|
||||
|
||||
if (timingChange)
|
||||
{
|
||||
beatmap.ControlPointInfo.TimingPoints.Add(new TimingControlPoint
|
||||
handleTimingControlPoint(new TimingControlPoint
|
||||
{
|
||||
Time = time,
|
||||
BeatLength = beatLength,
|
||||
@ -328,41 +324,68 @@ namespace osu.Game.Beatmaps.Formats
|
||||
});
|
||||
}
|
||||
|
||||
if (speedMultiplier != difficultyPoint.SpeedMultiplier)
|
||||
handleDifficultyControlPoint(new DifficultyControlPoint
|
||||
{
|
||||
beatmap.ControlPointInfo.DifficultyPoints.RemoveAll(x => x.Time == time);
|
||||
beatmap.ControlPointInfo.DifficultyPoints.Add(new DifficultyControlPoint
|
||||
{
|
||||
Time = time,
|
||||
SpeedMultiplier = speedMultiplier
|
||||
});
|
||||
}
|
||||
Time = time,
|
||||
SpeedMultiplier = speedMultiplier
|
||||
});
|
||||
|
||||
if (stringSampleSet != samplePoint.SampleBank || sampleVolume != samplePoint.SampleVolume)
|
||||
handleEffectControlPoint(new EffectControlPoint
|
||||
{
|
||||
beatmap.ControlPointInfo.SamplePoints.Add(new SampleControlPoint
|
||||
{
|
||||
Time = time,
|
||||
SampleBank = stringSampleSet,
|
||||
SampleVolume = sampleVolume
|
||||
});
|
||||
}
|
||||
Time = time,
|
||||
KiaiMode = kiaiMode,
|
||||
OmitFirstBarLine = omitFirstBarSignature
|
||||
});
|
||||
|
||||
if (kiaiMode != effectPoint.KiaiMode || omitFirstBarSignature != effectPoint.OmitFirstBarLine)
|
||||
handleSampleControlPoint(new LegacySampleControlPoint
|
||||
{
|
||||
beatmap.ControlPointInfo.EffectPoints.Add(new EffectControlPoint
|
||||
{
|
||||
Time = time,
|
||||
KiaiMode = kiaiMode,
|
||||
OmitFirstBarLine = omitFirstBarSignature
|
||||
});
|
||||
}
|
||||
Time = time,
|
||||
SampleBank = stringSampleSet,
|
||||
SampleVolume = sampleVolume,
|
||||
CustomSampleBank = customSampleBank
|
||||
});
|
||||
}
|
||||
catch (FormatException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void handleTimingControlPoint(TimingControlPoint newPoint)
|
||||
{
|
||||
beatmap.ControlPointInfo.TimingPoints.Add(newPoint);
|
||||
}
|
||||
|
||||
private void handleDifficultyControlPoint(DifficultyControlPoint newPoint)
|
||||
{
|
||||
var existing = beatmap.ControlPointInfo.DifficultyPointAt(newPoint.Time);
|
||||
|
||||
if (newPoint.Equals(existing))
|
||||
return;
|
||||
|
||||
beatmap.ControlPointInfo.DifficultyPoints.RemoveAll(x => x.Time == newPoint.Time);
|
||||
beatmap.ControlPointInfo.DifficultyPoints.Add(newPoint);
|
||||
}
|
||||
|
||||
private void handleEffectControlPoint(EffectControlPoint newPoint)
|
||||
{
|
||||
var existing = beatmap.ControlPointInfo.EffectPointAt(newPoint.Time);
|
||||
|
||||
if (newPoint.Equals(existing))
|
||||
return;
|
||||
|
||||
beatmap.ControlPointInfo.EffectPoints.Add(newPoint);
|
||||
}
|
||||
|
||||
private void handleSampleControlPoint(SampleControlPoint newPoint)
|
||||
{
|
||||
var existing = beatmap.ControlPointInfo.SamplePointAt(newPoint.Time);
|
||||
|
||||
if (newPoint.Equals(existing))
|
||||
return;
|
||||
|
||||
beatmap.ControlPointInfo.SamplePoints.Add(newPoint);
|
||||
}
|
||||
|
||||
private void handleHitObject(string line)
|
||||
{
|
||||
// If the ruleset wasn't specified, assume the osu!standard ruleset.
|
||||
|
Loading…
Reference in New Issue
Block a user