Skip to content

Commit

Permalink
Implement SingerUtils and fix all test error.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Nov 8, 2020
1 parent 847a131 commit fa89d41
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
31 changes: 31 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Utils/SingerUtilsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) andy840119 <[email protected]>. 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Skinning/KaraokeSkinLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

Expand Down
12 changes: 10 additions & 2 deletions osu.Game.Rulesets.Karaoke/Utils/SingerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>();

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();
}
}
}

0 comments on commit fa89d41

Please sign in to comment.