From c5e922009d8bf7a3abfdade9135b6264001af54a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 10 Aug 2024 00:05:26 +0800 Subject: [PATCH] Remove un-need lyrc Decoder/Encoder. --- .../Beatmaps/Formats/LrcDecoderTest.cs | 75 ------------------- .../Beatmaps/Formats/LrcEncoderTest.cs | 56 -------------- .../Beatmaps/Formats/LrcDecoder.cs | 30 -------- .../Beatmaps/Formats/LrcEncoder.cs | 16 ---- 4 files changed, 177 deletions(-) delete mode 100644 osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/LrcDecoderTest.cs delete mode 100644 osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/LrcEncoderTest.cs delete mode 100644 osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcDecoder.cs delete mode 100644 osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/LrcDecoderTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/LrcDecoderTest.cs deleted file mode 100644 index 8c127335b..000000000 --- a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/LrcDecoderTest.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.IO; -using System.Linq; -using NUnit.Framework; -using osu.Game.Beatmaps; -using osu.Game.IO; -using osu.Game.Rulesets.Karaoke.Beatmaps.Formats; -using osu.Game.Rulesets.Karaoke.Objects; -using osu.Game.Rulesets.Karaoke.Tests.Asserts; -using osu.Game.Rulesets.Karaoke.Tests.Helper; - -namespace osu.Game.Rulesets.Karaoke.Tests.Beatmaps.Formats; - -[TestFixture] -public class LrcDecoderTest -{ - [TestCase("[00:01.00]か[00:02.00]ら[00:03.00]お[00:04.00]け[00:05.00]", "からおけ", 1000, 5000)] - public void TestLyricTextAndTime(string lyricText, string expectedText, double expectedStartTime, double expectedEndTime) - { - var beatmap = decodeLrcLine(lyricText); - - // Get first lyric from beatmap - var actual = beatmap.HitObjects.OfType().FirstOrDefault()!; - Assert.IsNotNull(actual); - Assert.AreEqual(expectedText, actual.Text); - Assert.AreEqual(expectedStartTime, actual.LyricTimingInfo?.StartTime); - Assert.AreEqual(expectedEndTime, actual.LyricTimingInfo?.EndTime); - } - - [TestCase("[00:01.00]か[00:02.00]ら[00:03.00]お[00:04.00]け[00:05.00]", new[] { "[0,start]:1000", "[1,start]:2000", "[2,start]:3000", "[3,start]:4000", "[3,end]:5000" })] - public void TestLyricTimeTag(string text, string[] timeTags) - { - // Get first lyric from beatmap - var beatmap = decodeLrcLine(text); - var lyric = beatmap.HitObjects.OfType().FirstOrDefault(); - - // Check time tag - var expected = TestCaseTagHelper.ParseTimeTags(timeTags); - var actual = lyric?.TimeTags ?? throw new ArgumentNullException(nameof(lyric)); - TimeTagAssert.ArePropertyEqual(expected, actual); - } - - [Ignore("Time-tags with same time might be allowed.")] - [TestCase("[00:04.00]か[00:04.00]ら[00:05.00]お[00:06.00]け[00:07.00]")] - public void TestDecodeLyricWithDuplicatedTimeTag(string text) - { - Assert.Throws(() => decodeLrcLine(text)); - } - - [Ignore("Waiting for lyric parser update.")] - [TestCase("[00:04.00]か[00:03.00]ら[00:02.00]お[00:01.00]け[00:00.00]")] - public void TestDecodeLyricWithTimeTagNotOrder(string text) - { - Assert.Throws(() => decodeLrcLine(text)); - } - - private static Beatmap decodeLrcLine(string line) - { - using var stream = new MemoryStream(); - using var writer = new StreamWriter(stream); - using var reader = new LineBufferedReader(stream); - - // Create stream - writer.Write(line); - writer.Flush(); - stream.Position = 0; - - // Create karaoke note decoder - var decoder = new LrcDecoder(); - return decoder.Decode(reader); - } -} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/LrcEncoderTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/LrcEncoderTest.cs deleted file mode 100644 index e7ae014fe..000000000 --- a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/LrcEncoderTest.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using NUnit.Framework; -using osu.Game.Beatmaps; -using osu.Game.IO; -using osu.Game.IO.Serialization; -using osu.Game.Rulesets.Karaoke.Beatmaps.Formats; -using osu.Game.Rulesets.Karaoke.Tests.Resources; -using LrcDecoder = osu.Game.Rulesets.Karaoke.Beatmaps.Formats.LrcDecoder; - -namespace osu.Game.Rulesets.Karaoke.Tests.Beatmaps.Formats; - -[TestFixture] -public class LrcEncoderTest -{ - private static IEnumerable allLrcFileNames => TestResources.GetStore().GetAvailableResources() - .Where(res => res.EndsWith(".lrc", StringComparison.Ordinal)).Select(x => Path.GetFileNameWithoutExtension(x!)); - - [TestCaseSource(nameof(allLrcFileNames))] - public void TestDecodeEncodedBeatmap(string fileName) - { - var decoded = decode(fileName, out var encoded); - - // Note : this test case does not cover ruby property - Assert.That(decoded.HitObjects.Count, Is.EqualTo(encoded.HitObjects.Count)); - Assert.That(encoded.Serialize(), Is.EqualTo(decoded.Serialize())); - } - - private static Beatmap decode(string filename, out Beatmap encoded) - { - using var stream = TestResources.OpenKarResource(filename); - using var sr = new LineBufferedReader(stream); - - // Read file and decode to file - var legacyDecoded = new LrcDecoder().Decode(sr); - - using var ms = new MemoryStream(); - using var sw = new StreamWriter(ms); - using var sr2 = new LineBufferedReader(ms); - - // Then encode file to stream - string encodeResult = new LrcEncoder().Encode(legacyDecoded); - sw.WriteLine(encodeResult); - sw.Flush(); - - ms.Position = 0; - - encoded = new LrcDecoder().Decode(sr2); - return legacyDecoded; - } -} diff --git a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcDecoder.cs b/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcDecoder.cs deleted file mode 100644 index d30ae957e..000000000 --- a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcDecoder.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Game.Beatmaps; -using osu.Game.Beatmaps.Formats; -using osu.Game.IO; -using osu.Game.Rulesets.Karaoke.Integration.Formats; - -namespace osu.Game.Rulesets.Karaoke.Beatmaps.Formats; - -public class LrcDecoder : Decoder -{ - public static void Register() - { - // Lrc decoder looks like [mm:ss:__] - AddDecoder("[", _ => new LrcDecoder()); - } - - protected override void ParseStreamInto(LineBufferedReader stream, Beatmap output) - { - string lyricText = stream.ReadToEnd(); - var song = new LrcParser.Parser.Lrc.LrcParser().Decode(lyricText); - - var newLyrics = LrcParserUtils.ConvertToLyrics(song); - - // Clear all hitobjects - output.HitObjects.Clear(); - output.HitObjects.AddRange(newLyrics); - } -} diff --git a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs b/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs deleted file mode 100644 index 522828fa6..000000000 --- a/osu.Game.Rulesets.Karaoke/Beatmaps/Formats/LrcEncoder.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Game.Beatmaps; -using osu.Game.Rulesets.Karaoke.Integration.Formats; - -namespace osu.Game.Rulesets.Karaoke.Beatmaps.Formats; - -public class LrcEncoder -{ - public string Encode(Beatmap output) - { - var song = LrcParserUtils.ConvertToSong(output); - return new LrcParser.Parser.Lrc.LrcParser().Encode(song); - } -}