diff --git a/osu.Game.Rulesets.Karaoke.Tests/Integration/Formats/LyricTextDecoderTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Integration/Formats/LyricTextDecoderTest.cs new file mode 100644 index 000000000..5cf202c15 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Integration/Formats/LyricTextDecoderTest.cs @@ -0,0 +1,27 @@ +// 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.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); + } + } +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/LyricTextEncoderTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Integration/Formats/LyricTextEncoderTest.cs similarity index 89% rename from osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/LyricTextEncoderTest.cs rename to osu.Game.Rulesets.Karaoke.Tests/Integration/Formats/LyricTextEncoderTest.cs index ca4e29b00..f57d783f3 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/LyricTextEncoderTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Integration/Formats/LyricTextEncoderTest.cs @@ -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 diff --git a/osu.Game.Rulesets.Karaoke/Integration/Formats/LyricTextDecoder.cs b/osu.Game.Rulesets.Karaoke/Integration/Formats/LyricTextDecoder.cs new file mode 100644 index 000000000..bb162e472 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Integration/Formats/LyricTextDecoder.cs @@ -0,0 +1,19 @@ +// Copyright (c) andy840119 . 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 +{ + public Lyric[] Decode(string source) + { + return source.Split('\n').Select((text, index) => new Lyric + { + Order = index + 1, // should create default order. + Text = text, + }).ToArray(); + } +} diff --git a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LyricTextEncoder.cs b/osu.Game.Rulesets.Karaoke/Integration/Formats/LyricTextEncoder.cs similarity index 82% rename from osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LyricTextEncoder.cs rename to osu.Game.Rulesets.Karaoke/Integration/Formats/LyricTextEncoder.cs index 4ad6c2960..e4c14d7c0 100644 --- a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LyricTextEncoder.cs +++ b/osu.Game.Rulesets.Karaoke/Integration/Formats/LyricTextEncoder.cs @@ -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 { public string Encode(IBeatmap output) {