1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 16:12:57 +08:00

Encapsulate the method to apply SampleControlPoints to SampleInfos

This commit is contained in:
smoogipoo 2018-06-28 18:20:29 +09:00
parent 2882981f9c
commit 781095b96b
2 changed files with 18 additions and 7 deletions

View File

@ -31,6 +31,18 @@ namespace osu.Game.Beatmaps.ControlPoints
Volume = SampleVolume,
};
/// <summary>
/// Applies <see cref="SampleBank"/> and <see cref="SampleVolume"/> to a <see cref="SampleInfo"/> if necessary, returning the modified <see cref="SampleInfo"/>.
/// </summary>
/// <param name="sampleInfo">The <see cref="SampleInfo"/>. This will not be modified.</param>
/// <returns>The modified <see cref="SampleInfo"/>. This does not share a reference with <paramref name="sampleInfo"/>.</returns>
public virtual SampleInfo ApplyTo(SampleInfo sampleInfo) => new SampleInfo
{
Bank = sampleInfo.Bank ?? SampleBank,
Name = sampleInfo.Name,
Volume = sampleInfo.Volume > 0 ? sampleInfo.Volume : SampleVolume
};
public override bool Equals(ControlPoint other)
=> base.Equals(other)
&& other is SampleControlPoint sample

View File

@ -90,13 +90,12 @@ namespace osu.Game.Rulesets.Objects.Drawables
if (HitObject.SampleControlPoint == null)
throw new ArgumentNullException(nameof(HitObject.SampleControlPoint), $"{nameof(HitObject)}s must always have an attached {nameof(HitObject.SampleControlPoint)}."
+ $" This is an indication that {nameof(HitObject.ApplyDefaults)} has not been invoked on {this}.");
AddInternal(Samples = new SkinnableSound(samples.Select(s => new SampleInfo
{
Bank = s.Bank ?? HitObject.SampleControlPoint.SampleBank,
Name = s.Name,
Volume = s.Volume > 0 ? s.Volume : HitObject.SampleControlPoint.SampleVolume,
Namespace = SampleNamespace
}).ToArray()));
samples = samples.Select(s => HitObject.SampleControlPoint.ApplyTo(s)).ToArray();
foreach (var s in samples)
s.Namespace = SampleNamespace;
AddInternal(Samples = new SkinnableSound(samples));
}
}