1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 03:02:56 +08:00

Merge pull request #2986 from peppy/fix-hitsound-fallback

Fix lack of fallback logic for custom bank samples
This commit is contained in:
Dan Balasescu 2018-07-10 17:37:01 +09:00 committed by GitHub
commit b0d839c5d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View File

@ -222,10 +222,10 @@ namespace osu.Game.Tests.Beatmaps.Formats
{ {
var hitObjects = decoder.Decode(stream).HitObjects; var hitObjects = decoder.Decode(stream).HitObjects;
Assert.AreEqual("hitnormal", getTestableSampleInfo(hitObjects[0]).Name); Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[0]).LookupNames.First());
Assert.AreEqual("hitnormal", getTestableSampleInfo(hitObjects[1]).Name); Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[1]).LookupNames.First());
Assert.AreEqual("hitnormal2", getTestableSampleInfo(hitObjects[2]).Name); Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First());
Assert.AreEqual("hitnormal", getTestableSampleInfo(hitObjects[3]).Name); Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[3]).LookupNames.First());
} }
SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(new SampleInfo { Name = "hitnormal" }); SampleInfo getTestableSampleInfo(HitObject hitObject) => hitObject.SampleControlPoint.ApplyTo(new SampleInfo { Name = "hitnormal" });
@ -242,7 +242,7 @@ namespace osu.Game.Tests.Beatmaps.Formats
Assert.AreEqual("hit_1.wav", hitObjects[0].Samples[0].LookupNames.First()); Assert.AreEqual("hit_1.wav", hitObjects[0].Samples[0].LookupNames.First());
Assert.AreEqual("hit_2.wav", hitObjects[1].Samples[0].LookupNames.First()); Assert.AreEqual("hit_2.wav", hitObjects[1].Samples[0].LookupNames.First());
Assert.AreEqual("hitnormal2", getTestableSampleInfo(hitObjects[2]).Name); Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First());
Assert.AreEqual("hit_1.wav", hitObjects[3].Samples[0].LookupNames.First()); Assert.AreEqual("hit_1.wav", hitObjects[3].Samples[0].LookupNames.First());
} }

View File

@ -29,6 +29,11 @@ namespace osu.Game.Audio
/// </summary> /// </summary>
public string Name; public string Name;
/// <summary>
/// An optional suffix to provide priority lookup. Falls back to non-suffixed <see cref="Name"/>.
/// </summary>
public string Suffix;
/// <summary> /// <summary>
/// The sample volume. /// The sample volume.
/// </summary> /// </summary>
@ -42,9 +47,16 @@ namespace osu.Game.Audio
get get
{ {
if (!string.IsNullOrEmpty(Namespace)) if (!string.IsNullOrEmpty(Namespace))
{
if (!string.IsNullOrEmpty(Suffix))
yield return $"{Namespace}/{Bank}-{Name}{Suffix}";
yield return $"{Namespace}/{Bank}-{Name}"; yield return $"{Namespace}/{Bank}-{Name}";
}
yield return $"{Bank}-{Name}"; // Without namespace as a fallback even when we have a namespace // check non-namespace as a fallback even when we have a namespace
if (!string.IsNullOrEmpty(Suffix))
yield return $"{Bank}-{Name}{Suffix}";
yield return $"{Bank}-{Name}";
} }
} }

View File

@ -179,7 +179,7 @@ namespace osu.Game.Beatmaps.Formats
var baseInfo = base.ApplyTo(sampleInfo); var baseInfo = base.ApplyTo(sampleInfo);
if (CustomSampleBank > 1) if (CustomSampleBank > 1)
baseInfo.Name += CustomSampleBank; baseInfo.Suffix = CustomSampleBank.ToString();
return baseInfo; return baseInfo;
} }