From ba258b8a054398a1a860220db453301245b064b8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 10 Jul 2018 02:56:00 +0900 Subject: [PATCH 1/3] Fix lack of fallback logic for custom bank samples Closes #2966. --- Was causing some beatmaps to not play all of their hitsounds --- osu.Game/Audio/SampleInfo.cs | 13 ++++++++++++- osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/osu.Game/Audio/SampleInfo.cs b/osu.Game/Audio/SampleInfo.cs index 7e329ac651..9ed40c648e 100644 --- a/osu.Game/Audio/SampleInfo.cs +++ b/osu.Game/Audio/SampleInfo.cs @@ -29,6 +29,11 @@ namespace osu.Game.Audio /// public string Name; + /// + /// An optional suffix to provide priority lookup. Falls back to non-suffixed . + /// + public string Suffix; + /// /// The sample volume. /// @@ -41,9 +46,15 @@ namespace osu.Game.Audio { get { + if (!string.IsNullOrEmpty(Suffix)) + { + if (!string.IsNullOrEmpty(Namespace)) + yield return $"{Namespace}/{Bank}-{Name}{Suffix}"; + yield return $"{Bank}-{Name}{Suffix}"; // Without namespace as a fallback even when we have a namespace + } + if (!string.IsNullOrEmpty(Namespace)) yield return $"{Namespace}/{Bank}-{Name}"; - yield return $"{Bank}-{Name}"; // Without namespace as a fallback even when we have a namespace } } diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index 22a6acf459..c8874c3bc7 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -179,7 +179,7 @@ namespace osu.Game.Beatmaps.Formats var baseInfo = base.ApplyTo(sampleInfo); if (CustomSampleBank > 1) - baseInfo.Name += CustomSampleBank; + baseInfo.Suffix = CustomSampleBank.ToString(); return baseInfo; } From 14c3cc70b15da9a3ac20cb25c37e704a8536dc61 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 10 Jul 2018 15:23:47 +0900 Subject: [PATCH 2/3] Prefer namespace lookups first --- osu.Game/Audio/SampleInfo.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/osu.Game/Audio/SampleInfo.cs b/osu.Game/Audio/SampleInfo.cs index 9ed40c648e..4345d09e05 100644 --- a/osu.Game/Audio/SampleInfo.cs +++ b/osu.Game/Audio/SampleInfo.cs @@ -46,16 +46,17 @@ namespace osu.Game.Audio { get { - if (!string.IsNullOrEmpty(Suffix)) + if (!string.IsNullOrEmpty(Namespace)) { - if (!string.IsNullOrEmpty(Namespace)) + if (!string.IsNullOrEmpty(Suffix)) yield return $"{Namespace}/{Bank}-{Name}{Suffix}"; - yield return $"{Bank}-{Name}{Suffix}"; // Without namespace as a fallback even when we have a namespace + yield return $"{Namespace}/{Bank}-{Name}"; } - if (!string.IsNullOrEmpty(Namespace)) - 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}"; } } From 65d351c31a7494c1103e92a2425a24310d482d01 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 10 Jul 2018 16:26:04 +0900 Subject: [PATCH 3/3] Fix failing test cases --- .../Beatmaps/Formats/LegacyBeatmapDecoderTest.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs index ad203d2107..2f5b4a13d9 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyBeatmapDecoderTest.cs @@ -222,10 +222,10 @@ namespace osu.Game.Tests.Beatmaps.Formats { var hitObjects = decoder.Decode(stream).HitObjects; - Assert.AreEqual("hitnormal", getTestableSampleInfo(hitObjects[0]).Name); - Assert.AreEqual("hitnormal", getTestableSampleInfo(hitObjects[1]).Name); - Assert.AreEqual("hitnormal2", getTestableSampleInfo(hitObjects[2]).Name); - Assert.AreEqual("hitnormal", getTestableSampleInfo(hitObjects[3]).Name); + Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[0]).LookupNames.First()); + Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[1]).LookupNames.First()); + Assert.AreEqual("normal-hitnormal2", getTestableSampleInfo(hitObjects[2]).LookupNames.First()); + Assert.AreEqual("normal-hitnormal", getTestableSampleInfo(hitObjects[3]).LookupNames.First()); } 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_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()); }