mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:47:26 +08:00
Encapsulate the method to apply SampleControlPoints to SampleInfos
This commit is contained in:
parent
2882981f9c
commit
781095b96b
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user