diff --git a/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/RomajiTagsConverterTest.cs b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/RomajiTagsConverterTest.cs new file mode 100644 index 000000000..0511d9858 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/RomajiTagsConverterTest.cs @@ -0,0 +1,68 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; +using NUnit.Framework; +using osu.Game.Rulesets.Karaoke.IO.Serialization.Converters; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Tests.Asserts; + +namespace osu.Game.Rulesets.Karaoke.Tests.IO.Serialization.Converters +{ + public class RomajiTagsConverterTest : BaseSingleConverterTest + { + protected override JsonConverter[] CreateExtraConverts() + => new JsonConverter[] + { + new RomajiTagConverter(), + }; + + [Test] + public void TestSerialize() + { + var timeTags = new[] + { + new RomajiTag + { + StartIndex = 2, + EndIndex = 3, + Text = "ji" + }, + new RomajiTag + { + StartIndex = 1, + EndIndex = 2, + Text = "roma" + }, + }; + + const string expected = "[\"[1,2]:roma\",\"[2,3]:ji\"]"; + string actual = JsonConvert.SerializeObject(timeTags, CreateSettings()); + Assert.AreEqual(expected, actual); + } + + [Test] + public void TestDeserialize() + { + const string json = "[\"[2,3]:ji\",\"[1,2]:roma\"]"; + + var expected = new[] + { + new RomajiTag + { + StartIndex = 1, + EndIndex = 2, + Text = "roma" + }, + new RomajiTag + { + StartIndex = 2, + EndIndex = 3, + Text = "ji" + }, + }; + var actual = JsonConvert.DeserializeObject(json, CreateSettings()); + TextTagAssert.ArePropertyEqual(expected, actual); + } + } +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/RubyTagsConverterTest.cs b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/RubyTagsConverterTest.cs new file mode 100644 index 000000000..324794204 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/RubyTagsConverterTest.cs @@ -0,0 +1,68 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; +using NUnit.Framework; +using osu.Game.Rulesets.Karaoke.IO.Serialization.Converters; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Tests.Asserts; + +namespace osu.Game.Rulesets.Karaoke.Tests.IO.Serialization.Converters +{ + public class RubyTagsConverterTest : BaseSingleConverterTest + { + protected override JsonConverter[] CreateExtraConverts() + => new JsonConverter[] + { + new RubyTagConverter(), + }; + + [Test] + public void TestSerialize() + { + var timeTags = new[] + { + new RubyTag + { + StartIndex = 2, + EndIndex = 3, + Text = "ビ" + }, + new RubyTag + { + StartIndex = 1, + EndIndex = 2, + Text = "ル" + }, + }; + + const string expected = "[\"[1,2]:ル\",\"[2,3]:ビ\"]"; + string actual = JsonConvert.SerializeObject(timeTags, CreateSettings()); + Assert.AreEqual(expected, actual); + } + + [Test] + public void TestDeserialize() + { + const string json = "[\"[2,3]:ビ\",\"[1,2]:ル\"]"; + + var expected = new[] + { + new RubyTag + { + StartIndex = 1, + EndIndex = 2, + Text = "ル" + }, + new RubyTag + { + StartIndex = 2, + EndIndex = 3, + Text = "ビ" + }, + }; + var actual = JsonConvert.DeserializeObject(json, CreateSettings()); + TextTagAssert.ArePropertyEqual(expected, actual); + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/RomajiTagsConverter.cs b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/RomajiTagsConverter.cs new file mode 100644 index 000000000..4b0888dcc --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/RomajiTagsConverter.cs @@ -0,0 +1,15 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Utils; + +namespace osu.Game.Rulesets.Karaoke.IO.Serialization.Converters +{ + public class RomajiTagsConverter : SortableJsonConvertor + { + protected override IEnumerable GetSortedValue(IEnumerable objects) + => TextTagsUtils.Sort(objects); + } +} diff --git a/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/RubyTagsConverter.cs b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/RubyTagsConverter.cs new file mode 100644 index 000000000..265e4af57 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/IO/Serialization/Converters/RubyTagsConverter.cs @@ -0,0 +1,15 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Utils; + +namespace osu.Game.Rulesets.Karaoke.IO.Serialization.Converters +{ + public class RubyTagsConverter : SortableJsonConvertor + { + protected override IEnumerable GetSortedValue(IEnumerable objects) + => TextTagsUtils.Sort(objects); + } +}