diff --git a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/KaraokeLegacyBeatmapDecoderTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/KaraokeLegacyBeatmapDecoderTest.cs index 2b1d20694..c6f57a537 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/KaraokeLegacyBeatmapDecoderTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/KaraokeLegacyBeatmapDecoderTest.cs @@ -90,7 +90,7 @@ public void TestDecodeStyle() // Check layout and font index Assert.AreEqual(lyric.LayoutIndex, 2); - Assert.AreEqual(lyric.Singers, 3); + Assert.AreEqual(lyric.Singers, new[] { 1, 2 }); } [Test] diff --git a/osu.Game.Rulesets.Karaoke.Tests/Utils/SingerUtilsTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Utils/SingerUtilsTest.cs new file mode 100644 index 000000000..257b46011 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Utils/SingerUtilsTest.cs @@ -0,0 +1,31 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Game.Rulesets.Karaoke.Utils; + +namespace osu.Game.Rulesets.Karaoke.Tests.Utils +{ + [TestFixture] + public class SingerUtilsTest + { + [TestCase(null, 0)] + [TestCase(new[] { 1 }, 1)] + [TestCase(new[] { 1, 2, 3 }, 7)] + [TestCase(new[] { 1, 4, 5 }, 25)] + public void TestGetShiftingStyleIndex(int[] singerIndexs, int styleIndex) + { + Assert.AreEqual(SingerUtils.GetShiftingStyleIndex(singerIndexs), styleIndex); + } + + [TestCase(-1, new int[] { })] + [TestCase(0, new int[] { })] + [TestCase(1, new[] { 1 })] + [TestCase(7, new[] { 1, 2, 3 })] + [TestCase(25, new[] { 1, 4, 5 })] + public void TestGetSingersIndex(int styleIndex, int[] singerIndexs) + { + Assert.AreEqual(SingerUtils.GetSingersIndex(styleIndex), singerIndexs); + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Singers/Components/Timeline/LyricTimelineHitObjectBlueprint.cs b/osu.Game.Rulesets.Karaoke/Edit/Singers/Components/Timeline/LyricTimelineHitObjectBlueprint.cs index 62a0b10d5..f9bbc5c37 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Singers/Components/Timeline/LyricTimelineHitObjectBlueprint.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Singers/Components/Timeline/LyricTimelineHitObjectBlueprint.cs @@ -57,8 +57,8 @@ public LyricTimelineHitObjectBlueprint(HitObject hitObject, Singer singer) { lyric.SingersBindable.BindValueChanged(e => { - // Check is lyric contains this singer. - var isSingerMatch = e.NewValue.Contains(singer.ID); + // Check is lyric contains this singer, or default singer + var isSingerMatch = e.NewValue?.Contains(singer.ID) ?? singer.ID == 0; if (isSingerMatch) { Show(); diff --git a/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkinLookup.cs b/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkinLookup.cs index 8e07e6371..c19ae5d05 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkinLookup.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkinLookup.cs @@ -16,7 +16,7 @@ public readonly struct KaraokeSkinLookup public KaraokeSkinLookup(KaraokeSkinConfiguration config, int[] singers) : this(config, SingerUtils.GetShiftingStyleIndex(singers)) { - if (config != KaraokeSkinConfiguration.LyricStyle || config != KaraokeSkinConfiguration.NoteStyle) + if (config != KaraokeSkinConfiguration.LyricStyle && config != KaraokeSkinConfiguration.NoteStyle) throw new InvalidDataException($"Only {KaraokeSkinConfiguration.LyricStyle} and {KaraokeSkinConfiguration.NoteStyle} can call this ctor."); } diff --git a/osu.Game.Rulesets.Karaoke/Utils/SingerUtils.cs b/osu.Game.Rulesets.Karaoke/Utils/SingerUtils.cs index 9a18eb668..cf13d64ff 100644 --- a/osu.Game.Rulesets.Karaoke/Utils/SingerUtils.cs +++ b/osu.Game.Rulesets.Karaoke/Utils/SingerUtils.cs @@ -9,9 +9,17 @@ namespace osu.Game.Rulesets.Karaoke.Utils public static class SingerUtils { public static int GetShiftingStyleIndex(int[] singerIds) - => singerIds.Sum(x => (int)Math.Pow(2, x - 1)); + => singerIds?.Sum(x => (int)Math.Pow(2, x - 1)) ?? 0; public static int[] GetSingersIndex(int styleIndex) - => throw new NotImplementedException(); + { + if (styleIndex < 1) + return Array.Empty(); + + string binary = Convert.ToString(styleIndex, 2); + + return binary.Select((v, i) => new { value = v, singer = binary.Length - i }) + .Where(x => x.value == '1').Select(x => x.singer).OrderBy(x => x).ToArray(); + } } }