Implement and use equality comparers for ControlPoint

This commit is contained in:
smoogipoo 2018-06-28 18:08:46 +09:00
parent 8242236ddf
commit 2882981f9c
6 changed files with 82 additions and 30 deletions

View File

@ -14,6 +14,12 @@ public class ControlPoint : IComparable<ControlPoint>, IEquatable<ControlPoint>
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);
}
}
}

View File

@ -17,5 +17,10 @@ public double SpeedMultiplier
}
private double speedMultiplier = 1;
public override bool Equals(ControlPoint other)
=> base.Equals(other)
&& other is DifficultyControlPoint difficulty
&& SpeedMultiplier == difficulty.SpeedMultiplier;
}
}

View File

@ -14,5 +14,11 @@ public class EffectControlPoint : ControlPoint
/// 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;
}
}

View File

@ -30,5 +30,11 @@ public class SampleControlPoint : ControlPoint
Name = sampleName,
Volume = SampleVolume,
};
public override bool Equals(ControlPoint other)
=> base.Equals(other)
&& other is SampleControlPoint sample
&& SampleBank == sample.SampleBank
&& SampleVolume == sample.SampleVolume;
}
}

View File

@ -23,5 +23,11 @@ public double BeatLength
}
private double beatLength = 1000;
public override bool Equals(ControlPoint other)
=> base.Equals(other)
&& other is TimingControlPoint timing
&& TimeSignature == timing.TimeSignature
&& BeatLength == timing.beatLength;
}
}

View File

@ -314,13 +314,9 @@ private void handleTimingPoint(string line)
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 @@ private void handleTimingPoint(string line)
});
}
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.