Clone and copy ControlPointInfo when retrieving a playable beatmap

This commit is contained in:
Dean Herbert
2021-01-04 16:37:07 +09:00
parent cd7a5ca23a
commit ba4e411422
11 changed files with 86 additions and 6 deletions

View File

@ -28,5 +28,22 @@ namespace osu.Game.Beatmaps.ControlPoints
/// <param name="existing">An existing control point to compare with.</param>
/// <returns>Whether this <see cref="ControlPoint"/> is redundant when placed alongside <paramref name="existing"/>.</returns>
public abstract bool IsRedundant(ControlPoint existing);
/// <summary>
/// Create a copy of this room without online information.
/// Should be used to create a local copy of a room for submitting in the future.
/// </summary>
public ControlPoint CreateCopy()
{
var copy = (ControlPoint)Activator.CreateInstance(GetType());
copy.CopyFrom(this);
return copy;
}
public virtual void CopyFrom(ControlPoint other)
{
}
}
}

View File

@ -11,7 +11,7 @@ using osu.Framework.Lists;
namespace osu.Game.Beatmaps.ControlPoints
{
[Serializable]
public class ControlPointInfo
public class ControlPointInfo : ICloneable
{
/// <summary>
/// All control points grouped by time.
@ -297,5 +297,15 @@ namespace osu.Game.Beatmaps.ControlPoints
break;
}
}
public object Clone()
{
var controlPointInfo = new ControlPointInfo();
foreach (var point in AllControlPoints)
controlPointInfo.Add(point.Time, point.CreateCopy());
return controlPointInfo;
}
}
}

View File

@ -39,5 +39,12 @@ namespace osu.Game.Beatmaps.ControlPoints
public override bool IsRedundant(ControlPoint existing)
=> existing is DifficultyControlPoint existingDifficulty
&& SpeedMultiplier == existingDifficulty.SpeedMultiplier;
public override void CopyFrom(ControlPoint other)
{
SpeedMultiplier = ((DifficultyControlPoint)other).SpeedMultiplier;
base.CopyFrom(other);
}
}
}

View File

@ -50,5 +50,13 @@ namespace osu.Game.Beatmaps.ControlPoints
&& existing is EffectControlPoint existingEffect
&& KiaiMode == existingEffect.KiaiMode
&& OmitFirstBarLine == existingEffect.OmitFirstBarLine;
public override void CopyFrom(ControlPoint other)
{
KiaiMode = ((EffectControlPoint)other).KiaiMode;
OmitFirstBarLine = ((EffectControlPoint)other).OmitFirstBarLine;
base.CopyFrom(other);
}
}
}

View File

@ -72,5 +72,13 @@ namespace osu.Game.Beatmaps.ControlPoints
=> existing is SampleControlPoint existingSample
&& SampleBank == existingSample.SampleBank
&& SampleVolume == existingSample.SampleVolume;
public override void CopyFrom(ControlPoint other)
{
SampleVolume = ((SampleControlPoint)other).SampleVolume;
SampleBank = ((SampleControlPoint)other).SampleBank;
base.CopyFrom(other);
}
}
}

View File

@ -69,5 +69,13 @@ namespace osu.Game.Beatmaps.ControlPoints
// Timing points are never redundant as they can change the time signature.
public override bool IsRedundant(ControlPoint existing) => false;
public override void CopyFrom(ControlPoint other)
{
TimeSignature = ((TimingControlPoint)other).TimeSignature;
BeatLength = ((TimingControlPoint)other).BeatLength;
base.CopyFrom(other);
}
}
}