Skip to content

Commit

Permalink
Move LyricTextEncoder and LyricTextDecoder to better location.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Aug 9, 2024
1 parent c7c9feb commit f9823b1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.Integration.Formats;
using osu.Game.Rulesets.Karaoke.Tests.Helper;

namespace osu.Game.Rulesets.Karaoke.Tests.Integration.Formats;

public class LyricTextDecoderTest
{
[TestCase("karaoke", new[] { "[0,0]:karaoke" })] // only one lyric.
[TestCase("か\n\n\nけ", new[] { "[0,0]:か", "[0,0]:ら", "[0,0]:お", "[0,0]:け" })] // multi lyric.
public void TestDecodeBeatmapToPureText(string expected, string[] lyrics)
{
var decoder = new LyricTextDecoder();
var actual = decoder.Decode(expected);

var expectedLyrics = TestCaseTagHelper.ParseLyrics(lyrics);
Assert.AreEqual(expectedLyrics.Length, actual.Length);

for (int i = 0; i < expectedLyrics.Length; i++)
{
Assert.AreEqual(expectedLyrics[i].Text, actual[i].Text);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using System.Linq;
using NUnit.Framework;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats;
using osu.Game.Rulesets.Karaoke.Integration.Formats;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Tests.Helper;

namespace osu.Game.Rulesets.Karaoke.Tests.Beatmaps.Formats;
namespace osu.Game.Rulesets.Karaoke.Tests.Integration.Formats;

[TestFixture]
public class LyricTextEncoderTest
Expand Down
19 changes: 19 additions & 0 deletions osu.Game.Rulesets.Karaoke/Integration/Formats/LyricTextDecoder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Integration.Formats;

public class LyricTextDecoder : IDecoder<Lyric[]>
{
public Lyric[] Decode(string source)
{
return source.Split('\n').Select((text, index) => new Lyric
{
Order = index + 1, // should create default order.
Text = text,
}).ToArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Karaoke.Objects;

namespace osu.Game.Rulesets.Karaoke.Beatmaps.Formats;
namespace osu.Game.Rulesets.Karaoke.Integration.Formats;

public class LyricTextEncoder
public class LyricTextEncoder : IEncoder<IBeatmap>
{
public string Encode(IBeatmap output)
{
Expand Down

0 comments on commit f9823b1

Please sign in to comment.