diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/RomajiGenerateResultHelper.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/RomajiGenerateResultHelper.cs deleted file mode 100644 index 6d2f25f61..000000000 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/RomajiGenerateResultHelper.cs +++ /dev/null @@ -1,50 +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.Linq; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; -using osu.Game.Rulesets.Karaoke.Objects; - -namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romajis; - -public class RomajiGenerateResultHelper -{ - /// - /// Convert the string format into the . - /// - /// - /// karaoke - /// ^karaoke - /// - /// Origin time-tag - /// Generate result string format - /// Romaji generate result. - public static KeyValuePair ParseRomajiGenerateResult(TimeTag timeTag, string str) - { - var result = new RomajiGenerateResult - { - InitialRomaji = str.StartsWith("^", StringComparison.Ordinal), - RomajiText = str.Replace("^", ""), - }; - - return new KeyValuePair(timeTag, result); - } - - public static IReadOnlyDictionary ParseRomajiGenerateResults(IList timeTags, IList strings) - { - if (timeTags.Count != strings.Count) - throw new InvalidOperationException(); - - return parseRomajiGenerateResults(timeTags, strings).ToDictionary(k => k.Key, v => v.Value); - - static IEnumerable> parseRomajiGenerateResults(IList timeTags, IList strings) - { - for (int i = 0; i < timeTags.Count; i++) - { - yield return ParseRomajiGenerateResult(timeTags[i], strings[i]); - } - } - } -} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/BaseRomajiGeneratorTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/BaseRomanizationGeneratorTest.cs similarity index 56% rename from osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/BaseRomajiGeneratorTest.cs rename to osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/BaseRomanizationGeneratorTest.cs index 59e80aedf..319e013cf 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/BaseRomajiGeneratorTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/BaseRomanizationGeneratorTest.cs @@ -4,22 +4,22 @@ using System.Collections.Generic; using System.Linq; using NUnit.Framework; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Tests.Asserts; -namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romajis; +namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romanization; -public abstract class BaseRomajiGeneratorTest : BaseLyricGeneratorTest, TConfig> - where TRomajiGenerator : RomajiGenerator where TConfig : RomajiGeneratorConfig, new() +public abstract class BaseRomanizationGeneratorTest : BaseLyricGeneratorTest, TConfig> + where TRomanizationGenerator : RomanizationGenerator where TConfig : RomanizationGeneratorConfig, new() { protected void CheckGenerateResult(Lyric lyric, string[] expectedRubies, TConfig config) { - var expected = RomajiGenerateResultHelper.ParseRomajiGenerateResults(lyric.TimeTags, expectedRubies); + var expected = RomanizationGenerateResultHelper.ParseRomanizationGenerateResults(lyric.TimeTags, expectedRubies); CheckGenerateResult(lyric, expected, config); } - protected override void AssertEqual(IReadOnlyDictionary expected, IReadOnlyDictionary actual) + protected override void AssertEqual(IReadOnlyDictionary expected, IReadOnlyDictionary actual) { TimeTagAssert.ArePropertyEqual(expected.Select(x => x.Key).ToArray(), actual.Select(x => x.Key).ToArray()); Assert.AreEqual(expected.Select(x => x.Value), actual.Select(x => x.Value)); diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/Ja/JaRomajiGeneratorTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/Ja/JaRomanizationGeneratorTest.cs similarity index 71% rename from osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/Ja/JaRomajiGeneratorTest.cs rename to osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/Ja/JaRomanizationGeneratorTest.cs index 1a28e9879..7f30bcca6 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/Ja/JaRomajiGeneratorTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/Ja/JaRomanizationGeneratorTest.cs @@ -4,19 +4,19 @@ using System.Collections.Generic; using System.Linq; using NUnit.Framework; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies.Ja; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization.Ja; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Tests.Helper; -namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romajis.Ja; +namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romanization.Ja; -public class JaRomajiGeneratorTest : BaseRomajiGeneratorTest +public class JaRomanizationGeneratorTest : BaseRomanizationGeneratorTest { [TestCase("花火大会", new[] { "[0,start]", "[3,end]" }, true)] [TestCase("花火大会", new[] { "[0,start]" }, true)] [TestCase("花火大会", new[] { "[3,end]" }, false)] // not able to generate the has no start time-tag. - [TestCase("花火大会", new string[] { }, false)] // not able to generate the romaji if has no time-tag. - [TestCase("", new string[] { }, false)] // not able to generate the romaji if lyric is empty. + [TestCase("花火大会", new string[] { }, false)] // not able to make the romanization if has no time-tag. + [TestCase("", new string[] { }, false)] // not able to make the romanization if lyric is empty. [TestCase(" ", new string[] { }, false)] [TestCase(null, new string[] { }, false)] public void TestCanGenerate(string text, string[] timeTagStrings, bool canGenerate) @@ -40,7 +40,7 @@ public void TestCanGenerate(string text, string[] timeTagStrings, bool canGenera [TestCase("枯れた世界に輝く", new[] { "[0,start]", "[1,start]", "[2,start]", "[3,start]", "[4,start]", "[5,start]", "[6,start]", "[6,start]", "[6,start]", "[7,start]", "[7,end]" }, new[] { "^kare", "", "ta", "sekai", "", "ni", "kagayaku", "", "", "", "" })] - public void TestGenerate(string text, string[] timeTagStrings, string[] expectedRomajies) + public void TestGenerate(string text, string[] timeTagStrings, string[] expectedRomanizedSyllables) { var config = GeneratorEmptyConfig(); @@ -51,12 +51,12 @@ public void TestGenerate(string text, string[] timeTagStrings, string[] expected TimeTags = timeTags, }; - CheckGenerateResult(lyric, expectedRomajies, config); + CheckGenerateResult(lyric, expectedRomanizedSyllables, config); } [TestCase("はなび", new[] { "[0,start]" }, new[] { "^HANA BI" })] [TestCase("花火大会", new[] { "[0,start]", "[2,start]", "[3,end]" }, new[] { "^HANABI", "TAIKAI", "" })] - public void TestGenerateWithUppercase(string text, string[] timeTagStrings, string[] expectedRomajies) + public void TestGenerateWithUppercase(string text, string[] timeTagStrings, string[] expectedRomanizedSyllables) { var config = GeneratorEmptyConfig(x => x.Uppercase.Value = true); @@ -67,7 +67,7 @@ public void TestGenerateWithUppercase(string text, string[] timeTagStrings, stri TimeTags = timeTags, }; - CheckGenerateResult(lyric, expectedRomajies, config); + CheckGenerateResult(lyric, expectedRomanizedSyllables, config); } [TestCase("花", new[] { "[0,start]", "[0,end]" }, new[] { "[0]:hana" }, new[] { "^hana", "" })] @@ -75,13 +75,13 @@ public void TestGenerateWithUppercase(string text, string[] timeTagStrings, stri [TestCase("花火", new[] { "[0,start]", "[1,start]", "[1,end]" }, new[] { "[0]:hana", "[1]:bi" }, new[] { "^hana", "bi", "" })] [TestCase("花火", new[] { "[0,start]", "[0,start]", "[1,start]", "[1,end]" }, new[] { "[0]:hana", "[1]:bi" }, new[] { "^hana", "", "bi", "" })] [TestCase("はなび", new[] { "[0,start]", "[1,start]", "[2,start]", "[2,end]" }, new[] { "[0]:hana", "[2]:bi" }, new[] { "^hana", "", "bi", "" })] - public void TestConvertToRomajiGenerateResult(string text, string[] timeTagStrings, string[] romajiParams, string[] expectedResults) + public void TestConvertToRomanizationGenerateResult(string text, string[] timeTagStrings, string[] romanizationParams, string[] expectedResults) { var timeTags = TestCaseTagHelper.ParseTimeTags(timeTagStrings); - var romajis = parseRomajiGenerateResults(romajiParams); + var romanizations = parseRomanizationGenerateResults(romanizationParams); - var expected = RomajiGenerateResultHelper.ParseRomajiGenerateResults(timeTags, expectedResults); - var actual = JaRomajiGenerator.Convert(timeTags, romajis); + var expected = RomanizationGenerateResultHelper.ParseRomanizationGenerateResults(timeTags, expectedResults); + var actual = JaRomanizationGenerator.Convert(timeTags, romanizations); AssertEqual(expected, actual); } @@ -89,23 +89,20 @@ public void TestConvertToRomajiGenerateResult(string text, string[] timeTagStrin /// /// Process test case time tag string format into /// - /// - /// - /// /// Time tag string format - /// Time tag object - private static JaRomajiGenerator.RomajiGeneratorParameter parseRomajiGenerateResult(string str) + /// Time tag object + private static JaRomanizationGenerator.RomanizationGeneratorParameter parseRomanizationGenerateResult(string str) { // because format is same as the text-tag testing format, so just use this helper. var romajiTag = TestCaseTagHelper.ParseRomajiTag(str); - return new JaRomajiGenerator.RomajiGeneratorParameter + return new JaRomanizationGenerator.RomanizationGeneratorParameter { StartIndex = romajiTag.StartIndex, EndIndex = romajiTag.EndIndex, - RomajiText = romajiTag.Text, + RomanizedSyllable = romajiTag.Text, }; } - private static JaRomajiGenerator.RomajiGeneratorParameter[] parseRomajiGenerateResults(IEnumerable strings) - => strings.Select(parseRomajiGenerateResult).ToArray(); + private static JaRomanizationGenerator.RomanizationGeneratorParameter[] parseRomanizationGenerateResults(IEnumerable strings) + => strings.Select(parseRomanizationGenerateResult).ToArray(); } diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/RomanizationGenerateResultHelper.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/RomanizationGenerateResultHelper.cs new file mode 100644 index 000000000..669e5c0d3 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/RomanizationGenerateResultHelper.cs @@ -0,0 +1,50 @@ +// 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.Linq; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization; +using osu.Game.Rulesets.Karaoke.Objects; + +namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romanization; + +public class RomanizationGenerateResultHelper +{ + /// + /// Convert the string format into the . + /// + /// + /// karaoke + /// ^karaoke + /// + /// Origin time-tag + /// Generate result string format + /// Romanization generate result. + public static KeyValuePair ParseRomanizationGenerateResult(TimeTag timeTag, string str) + { + var result = new RomanizationGenerateResult + { + FirstSyllable = str.StartsWith("^", StringComparison.Ordinal), + RomanizedSyllable = str.Replace("^", ""), + }; + + return new KeyValuePair(timeTag, result); + } + + public static IReadOnlyDictionary ParseRomanizationGenerateResults(IList timeTags, IList strings) + { + if (timeTags.Count != strings.Count) + throw new InvalidOperationException(); + + return parseRomanizationGenerateResults(timeTags, strings).ToDictionary(k => k.Key, v => v.Value); + + static IEnumerable> parseRomanizationGenerateResults(IList timeTags, IList strings) + { + for (int i = 0; i < timeTags.Count; i++) + { + yield return ParseRomanizationGenerateResult(timeTags[i], strings[i]); + } + } + } +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/RomajiGeneratorSelectorTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/RomanizationGeneratorSelectorTest.cs similarity index 77% rename from osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/RomajiGeneratorSelectorTest.cs rename to osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/RomanizationGeneratorSelectorTest.cs index 81d14827d..75f05a522 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/RomajiGeneratorSelectorTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/RomanizationGeneratorSelectorTest.cs @@ -6,18 +6,18 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Graphics.Sprites; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization; 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.Editor.Generator.Lyrics.Romajis; +namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Generator.Lyrics.Romanization; -public class RomajiTagGeneratorSelectorTest : BaseLyricGeneratorSelectorTest> +public class RomanizationGeneratorSelectorTest : BaseLyricGeneratorSelectorTest> { [TestCase(17, "花火大会", true)] [TestCase(17, "我是中文", true)] // only change the language code to decide should be able to generate or not. - [TestCase(17, "", false)] // will not able to generate the romaji if lyric is empty. + [TestCase(17, "", false)] // will not able to make the romanization if lyric is empty. [TestCase(17, " ", false)] [TestCase(17, null, false)] [TestCase(1028, "はなび", false)] // Should not be able to generate if language is not supported. @@ -39,7 +39,7 @@ public void TestCanGenerate(int lcid, string text, bool canGenerate) [TestCase(17, "はなび", new[] { "[0,start]" }, new[] { "^hana bi" })] // Japanese [TestCase(1041, "花火大会", new[] { "[0,start]", "[3,end]" }, new[] { "^hanabi taikai", "" })] // Japanese - public void TestGenerate(int lcid, string text, string[] timeTagStrings, string[] expectedRomajies) + public void TestGenerate(int lcid, string text, string[] timeTagStrings, string[] expectedRomanizedSyllables) { var selector = CreateSelector(); @@ -51,11 +51,11 @@ public void TestGenerate(int lcid, string text, string[] timeTagStrings, string[ TimeTags = timeTags, }; - var expected = RomajiGenerateResultHelper.ParseRomajiGenerateResults(timeTags, expectedRomajies); + var expected = RomanizationGenerateResultHelper.ParseRomanizationGenerateResults(timeTags, expectedRomanizedSyllables); CheckGenerateResult(lyric, expected, selector); } - protected override void AssertEqual(IReadOnlyDictionary expected, IReadOnlyDictionary actual) + protected override void AssertEqual(IReadOnlyDictionary expected, IReadOnlyDictionary actual) { TimeTagAssert.ArePropertyEqual(expected.Select(x => x.Key).ToArray(), actual.Select(x => x.Key).ToArray()); Assert.AreEqual(expected.Select(x => x.Value), actual.Select(x => x.Value)); diff --git a/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs b/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs index 97b8b462d..ad4e9753a 100644 --- a/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs +++ b/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs @@ -10,7 +10,7 @@ using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Language; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Notes; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.ReferenceLyric; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies.Ja; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization.Ja; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.RubyTags.Ja; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.TimeTags.Ja; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.TimeTags.Zh; @@ -50,7 +50,7 @@ protected override void InitialiseDefaults() SetDefault(); // Romaji generator - SetDefault(); + SetDefault(); // Note generator SetDefault(); @@ -79,7 +79,7 @@ protected static KaraokeRulesetEditGeneratorSetting GetSettingByType() = Type t when t == typeof(JaRubyTagGeneratorConfig) => KaraokeRulesetEditGeneratorSetting.JaRubyTagGeneratorConfig, Type t when t == typeof(JaTimeTagGeneratorConfig) => KaraokeRulesetEditGeneratorSetting.JaTimeTagGeneratorConfig, Type t when t == typeof(ZhTimeTagGeneratorConfig) => KaraokeRulesetEditGeneratorSetting.ZhTimeTagGeneratorConfig, - Type t when t == typeof(JaRomajiGeneratorConfig) => KaraokeRulesetEditGeneratorSetting.JaRomajiGeneratorConfig, + Type t when t == typeof(JaRomanizationGeneratorConfig) => KaraokeRulesetEditGeneratorSetting.JaRomajiGeneratorConfig, Type t when t == typeof(NoteGeneratorConfig) => KaraokeRulesetEditGeneratorSetting.NoteGeneratorConfig, _ => throw new NotSupportedException(), }; diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs index 224cc702a..3069f5152 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs @@ -13,7 +13,7 @@ using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Language; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Notes; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.ReferenceLyric; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.RubyTags; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.TimeTags; using osu.Game.Rulesets.Karaoke.Edit.Utils; @@ -55,7 +55,7 @@ public bool CanGenerate(AutoGenerateType type) return canGenerate(timeTagGenerator); case AutoGenerateType.AutoGenerateTimeTagRomaji: - var timeTagRomajiGenerator = getSelector, RomajiGeneratorConfig>(); + var timeTagRomajiGenerator = getSelector, RomanizationGeneratorConfig>(); return canGenerate(timeTagRomajiGenerator); case AutoGenerateType.AutoGenerateNotes: @@ -96,7 +96,7 @@ public IDictionary GetGeneratorNotSupportedLyrics(Auto return getInvalidMessageFromGenerator(timeTagGenerator); case AutoGenerateType.AutoGenerateTimeTagRomaji: - var timeTagRomajiGenerator = getSelector, RomajiGeneratorConfig>(); + var timeTagRomajiGenerator = getSelector, RomanizationGeneratorConfig>(); return getInvalidMessageFromGenerator(timeTagRomajiGenerator); case AutoGenerateType.AutoGenerateNotes: @@ -171,7 +171,7 @@ public void AutoGenerate(AutoGenerateType type) break; case AutoGenerateType.AutoGenerateTimeTagRomaji: - var timeTagRomajiGenerator = getSelector, RomajiGeneratorConfig>(); + var timeTagRomajiGenerator = getSelector, RomanizationGeneratorConfig>(); PerformOnSelection(lyric => { var results = timeTagRomajiGenerator.Generate(lyric); @@ -179,8 +179,8 @@ public void AutoGenerate(AutoGenerateType type) foreach (var (key, value) in results) { var matchedTimeTag = lyric.TimeTags.Single(x => x == key); - matchedTimeTag.FirstSyllable = value.InitialRomaji; - matchedTimeTag.RomanizedSyllable = value.RomajiText; + matchedTimeTag.FirstSyllable = value.FirstSyllable; + matchedTimeTag.RomanizedSyllable = value.RomanizedSyllable; } }); break; diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGenerateResult.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGenerateResult.cs deleted file mode 100644 index 5e436e639..000000000 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGenerateResult.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; - -public struct RomajiGenerateResult -{ - public bool InitialRomaji { get; set; } - - public string? RomajiText { get; set; } -} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGeneratorSelector.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGeneratorSelector.cs deleted file mode 100644 index 58c8d2c1b..000000000 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGeneratorSelector.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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 System.Globalization; -using osu.Game.Rulesets.Karaoke.Configuration; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies.Ja; -using osu.Game.Rulesets.Karaoke.Objects; - -namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; - -public class RomajiGeneratorSelector : LyricGeneratorSelector, RomajiGeneratorConfig> -{ - public RomajiGeneratorSelector(KaraokeRulesetEditGeneratorConfigManager generatorConfigManager) - : base(generatorConfigManager) - { - RegisterGenerator(new CultureInfo(17)); - RegisterGenerator(new CultureInfo(1041)); - } -} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/Ja/JaRomajiGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/Ja/JaRomanizationGenerator.cs similarity index 58% rename from osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/Ja/JaRomajiGenerator.cs rename to osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/Ja/JaRomanizationGenerator.cs index 249df6bfc..e6d9ca096 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/Ja/JaRomajiGenerator.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/Ja/JaRomanizationGenerator.cs @@ -13,13 +13,13 @@ using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Utils; -namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies.Ja; +namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization.Ja; -public class JaRomajiGenerator : RomajiGenerator +public class JaRomanizationGenerator : RomanizationGenerator { private readonly Analyzer analyzer; - public JaRomajiGenerator(JaRomajiGeneratorConfig config) + public JaRomanizationGenerator(JaRomanizationGeneratorConfig config) : base(config) { analyzer = Analyzer.NewAnonymous((fieldName, reader) => @@ -29,20 +29,20 @@ public JaRomajiGenerator(JaRomajiGeneratorConfig config) }); } - protected override IReadOnlyDictionary GenerateFromItem(Lyric item) + protected override IReadOnlyDictionary GenerateFromItem(Lyric item) { // Tokenize the text string text = item.Text; var tokenStream = analyzer.GetTokenStream("dummy", new StringReader(text)); // get the processing tags. - var processingRomajies = getProcessingRomajies(text, tokenStream, Config).ToArray(); + var processingRomanizations = getProcessingRomanizations(text, tokenStream, Config).ToArray(); // then, trying to mapping them with the time-tags. - return Convert(item.TimeTags, processingRomajies); + return Convert(item.TimeTags, processingRomanizations); } - private static IEnumerable getProcessingRomajies(string text, TokenStream tokenStream, JaRomajiGeneratorConfig config) + private static IEnumerable getProcessingRomanizations(string text, TokenStream tokenStream, JaRomanizationGeneratorConfig config) { // Reset the stream and convert all result tokenStream.Reset(); @@ -65,18 +65,18 @@ private static IEnumerable getProcessingRomajies(strin string parentText = text[offsetAttribute.StartOffset..offsetAttribute.EndOffset]; bool fromKanji = JpStringUtils.ToKatakana(katakana) != JpStringUtils.ToKatakana(parentText); - // Convert to romaji. - string romaji = JpStringUtils.ToRomaji(katakana); + // Convert to romanized syllable. + string romanizedSyllable = JpStringUtils.ToRomaji(katakana); if (config.Uppercase.Value) - romaji = romaji.ToUpper(); + romanizedSyllable = romanizedSyllable.ToUpper(); // Make tag - yield return new RomajiGeneratorParameter + yield return new RomanizationGeneratorParameter { FromKanji = fromKanji, StartIndex = offsetAttribute.StartOffset, EndIndex = offsetAttribute.EndOffset - 1, - RomajiText = romaji, + RomanizedSyllable = romanizedSyllable, }; } @@ -85,58 +85,58 @@ private static IEnumerable getProcessingRomajies(strin tokenStream.Dispose(); } - internal static IReadOnlyDictionary Convert(IList timeTags, IList romajis) + internal static IReadOnlyDictionary Convert(IList timeTags, IList romanizations) { - var group = createGroup(timeTags, romajis); + var group = createGroup(timeTags, romanizations); return group.ToDictionary(k => k.Key, x => { - bool isFirst = timeTags.IndexOf(x.Key) == 0; // todo: use better to mark the initial romaji. - string romajiText = string.Join(" ", x.Value.Select(r => r.RomajiText)); + bool isFirst = timeTags.IndexOf(x.Key) == 0; // todo: use better to mark the first syllable. + string romanizedSyllable = string.Join(" ", x.Value.Select(r => r.RomanizedSyllable)); - return new RomajiGenerateResult + return new RomanizationGenerateResult { - InitialRomaji = isFirst, - RomajiText = romajiText, + FirstSyllable = isFirst, + RomanizedSyllable = romanizedSyllable, }; }); - static IReadOnlyDictionary> createGroup(IList timeTags, IList romajis) + static IReadOnlyDictionary> createGroup(IList timeTags, IList romanizations) { - var dictionary = timeTags.ToDictionary(x => x, v => new List()); + var dictionary = timeTags.ToDictionary(x => x, v => new List()); int processedIndex = 0; foreach (var (timeTag, list) in dictionary) { - while (processedIndex < romajis.Count && isTimeTagInRange(timeTags, timeTag, romajis[processedIndex])) + while (processedIndex < romanizations.Count && isTimeTagInRange(timeTags, timeTag, romanizations[processedIndex])) { - list.Add(romajis[processedIndex]); + list.Add(romanizations[processedIndex]); processedIndex++; } } - if (processedIndex < romajis.Count - 1) - throw new InvalidOperationException("Still have romajies that haven't process"); + if (processedIndex < romanizations.Count - 1) + throw new InvalidOperationException("Still have romanizations that haven't process"); return dictionary; } - static bool isTimeTagInRange(IEnumerable timeTags, TimeTag currentTimeTag, RomajiGeneratorParameter parameter) + static bool isTimeTagInRange(IEnumerable timeTags, TimeTag currentTimeTag, RomanizationGeneratorParameter parameter) { if (currentTimeTag.Index.State == TextIndex.IndexState.End) return false; - int romajiIndex = parameter.StartIndex; + int romanizationIndex = parameter.StartIndex; var nextTimeTag = timeTags.GetNextMatch(currentTimeTag, x => x.Index > currentTimeTag.Index && x.Index.State == TextIndex.IndexState.Start); if (nextTimeTag == null) - return romajiIndex >= currentTimeTag.Index.Index; + return romanizationIndex >= currentTimeTag.Index.Index; - return romajiIndex >= currentTimeTag.Index.Index && romajiIndex < nextTimeTag.Index.Index; + return romanizationIndex >= currentTimeTag.Index.Index && romanizationIndex < nextTimeTag.Index.Index; } } - internal class RomajiGeneratorParameter + internal class RomanizationGeneratorParameter { public bool FromKanji { get; set; } @@ -144,6 +144,6 @@ internal class RomajiGeneratorParameter public int EndIndex { get; set; } - public string RomajiText { get; set; } = string.Empty; + public string RomanizedSyllable { get; set; } = string.Empty; } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/Ja/JaRomajiGeneratorConfig.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/Ja/JaRomanizationGeneratorConfig.cs similarity index 54% rename from osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/Ja/JaRomajiGeneratorConfig.cs rename to osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/Ja/JaRomanizationGeneratorConfig.cs index 5f67b92eb..464a4e2ee 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/Ja/JaRomajiGeneratorConfig.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/Ja/JaRomanizationGeneratorConfig.cs @@ -3,10 +3,10 @@ using osu.Framework.Bindables; -namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies.Ja; +namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization.Ja; -public class JaRomajiGeneratorConfig : RomajiGeneratorConfig +public class JaRomanizationGeneratorConfig : RomanizationGeneratorConfig { - [ConfigSource("Uppercase", "Export romaji with uppercase.")] + [ConfigSource("Uppercase", "Export romanization with uppercase.")] public Bindable Uppercase { get; } = new BindableBool(); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGenerateResult.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGenerateResult.cs new file mode 100644 index 000000000..53eb8bb1f --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGenerateResult.cs @@ -0,0 +1,11 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization; + +public struct RomanizationGenerateResult +{ + public bool FirstSyllable { get; set; } + + public string? RomanizedSyllable { get; set; } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGenerator.cs similarity index 69% rename from osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGenerator.cs rename to osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGenerator.cs index 554feffa8..c47eef0a5 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGenerator.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGenerator.cs @@ -7,12 +7,12 @@ using osu.Framework.Localisation; using osu.Game.Rulesets.Karaoke.Objects; -namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; +namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization; -public abstract class RomajiGenerator : LyricPropertyGenerator, TConfig> - where TConfig : RomajiGeneratorConfig, new() +public abstract class RomanizationGenerator : LyricPropertyGenerator, TConfig> + where TConfig : RomanizationGeneratorConfig, new() { - protected RomajiGenerator(TConfig config) + protected RomanizationGenerator(TConfig config) : base(config) { } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGeneratorConfig.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGeneratorConfig.cs similarity index 53% rename from osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGeneratorConfig.cs rename to osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGeneratorConfig.cs index a0d5ede2a..f6e594d77 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGeneratorConfig.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGeneratorConfig.cs @@ -1,8 +1,8 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies; +namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization; -public abstract class RomajiGeneratorConfig : GeneratorConfig +public abstract class RomanizationGeneratorConfig : GeneratorConfig { } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGeneratorSelector.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGeneratorSelector.cs new file mode 100644 index 000000000..a13729c2b --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGeneratorSelector.cs @@ -0,0 +1,20 @@ +// 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 System.Globalization; +using osu.Game.Rulesets.Karaoke.Configuration; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization.Ja; +using osu.Game.Rulesets.Karaoke.Objects; + +namespace osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romanization; + +public class RomanizationGeneratorSelector : LyricGeneratorSelector, RomanizationGeneratorConfig> +{ + public RomanizationGeneratorSelector(KaraokeRulesetEditGeneratorConfigManager generatorConfigManager) + : base(generatorConfigManager) + { + RegisterGenerator(new CultureInfo(17)); + RegisterGenerator(new CultureInfo(1041)); + } +}