From cd954dfd24d0def5ca2f2ecff835a9be9719a358 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 16 Jan 2024 00:03:37 +0800 Subject: [PATCH 1/3] Rename the romanization-related property name in the time-tag. --- ...icPropertyAutoGenerateChangeHandlerTest.cs | 2 +- .../Lyrics/LyricTimeTagsChangeHandlerTest.cs | 6 ++--- .../Editor/Checks/CheckLyricTimeTagTest.cs | 16 ++++++------- .../Helper/TestCaseTagHelper.cs | 12 +++++----- .../LyricPropertyAutoGenerateChangeHandler.cs | 4 ++-- .../Lyrics/LyricTimeTagsChangeHandler.cs | 8 +++---- .../Edit/Checks/CheckLyricTimeTag.cs | 22 ++++++++--------- .../Objects/Lyric_Binding.cs | 4 ++-- osu.Game.Rulesets.Karaoke/Objects/TimeTag.cs | 24 +++++++++---------- .../Beatmaps/Lyrics/LyricEditorVerifier.cs | 2 +- .../Settings/Romaji/RomajiEditSection.cs | 6 ++--- 11 files changed, 53 insertions(+), 53 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandlerTest.cs index 54d6bbc30..9b53520f0 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandlerTest.cs @@ -211,7 +211,7 @@ public void TestAutoGenerateTimeTagRomaji() AssertSelectedHitObject(h => { - Assert.AreEqual("karaoke", h.TimeTags[0].RomajiText); + Assert.AreEqual("karaoke", h.TimeTags[0].RomanizedSyllable); }); } diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs index f2764e636..334d0b310 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs @@ -54,7 +54,7 @@ public void TestSetTimeTagInitialRomaji() AssertSelectedHitObject(_ => { - Assert.AreEqual(true, timeTag.InitialRomaji); + Assert.AreEqual(true, timeTag.FirstSyllable); }); } @@ -75,14 +75,14 @@ public void TestSetTimeTagRomajiText() AssertSelectedHitObject(_ => { - Assert.AreEqual("karaoke", timeTag.RomajiText); + Assert.AreEqual("karaoke", timeTag.RomanizedSyllable); }); TriggerHandlerChanged(c => c.SetTimeTagRomajiText(timeTag, " ")); AssertSelectedHitObject(_ => { - Assert.AreEqual(string.Empty, timeTag.RomajiText); + Assert.AreEqual(string.Empty, timeTag.RomanizedSyllable); }); } diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckLyricTimeTagTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckLyricTimeTagTest.cs index 9c2c1f369..b789cacc7 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckLyricTimeTagTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckLyricTimeTagTest.cs @@ -105,7 +105,7 @@ public void TestCheckEmptyTime(string text, string[] timeTags) [TestCase("カラオケ", "")] // should not be empty. [TestCase("カラオケ", " ")] // should not be white-space only. [TestCase("カラオケ", "卡拉OK")] // should be within latin. - public void TestCheckTimeTagRomajiInvalidText(string text, string romajiText) + public void TestCheckTimeTagRomajiInvalidText(string text, string romanizedSyllable) { var lyric = new Lyric { @@ -114,7 +114,7 @@ public void TestCheckTimeTagRomajiInvalidText(string text, string romajiText) { new TimeTag(new TextIndex()) { - RomajiText = romajiText, + RomanizedSyllable = romanizedSyllable, Time = 1000, }, new TimeTag(new TextIndex(3, TextIndex.IndexState.End)) @@ -128,7 +128,7 @@ public void TestCheckTimeTagRomajiInvalidText(string text, string romajiText) } [TestCase("カラオケ", null)] // should not be white-space only. - public void TestCheckRomajiEmptyTextIfFirst(string text, string romajiText) + public void TestCheckRomajiEmptyTextIfFirst(string text, string romanizedSyllable) { var lyric = new Lyric { @@ -137,8 +137,8 @@ public void TestCheckRomajiEmptyTextIfFirst(string text, string romajiText) { new TimeTag(new TextIndex()) { - RomajiText = romajiText, - InitialRomaji = true, + RomanizedSyllable = romanizedSyllable, + FirstSyllable = true, Time = 1000, }, new TimeTag(new TextIndex(3, TextIndex.IndexState.End)) @@ -154,7 +154,7 @@ public void TestCheckRomajiEmptyTextIfFirst(string text, string romajiText) [TestCase("カラオケ", "")] // should not have empty text if end. [TestCase("カラオケ", " ")] // should not have empty text if end. [TestCase("カラオケ", "123")] // should not have empty text if end. - public void TestRomajiNotHaveEmptyTextIfEnd(string text, string romajiText) + public void TestRomajiNotHaveEmptyTextIfEnd(string text, string romanizedSyllable) { var lyric = new Lyric { @@ -167,7 +167,7 @@ public void TestRomajiNotHaveEmptyTextIfEnd(string text, string romajiText) }, new TimeTag(new TextIndex(3, TextIndex.IndexState.End)) { - RomajiText = romajiText, + RomanizedSyllable = romanizedSyllable, Time = 2000, }, }, @@ -190,7 +190,7 @@ public void TestRomajiNotFistRomajiTextIfEnd() }, new TimeTag(new TextIndex(3, TextIndex.IndexState.End)) { - InitialRomaji = true, // is invalid. + FirstSyllable = true, // is invalid. Time = 2000, }, }, diff --git a/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseTagHelper.cs b/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseTagHelper.cs index 5855b32f6..5503b8995 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseTagHelper.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseTagHelper.cs @@ -129,9 +129,9 @@ public static RomajiTag ParseRomajiTag(string? str) /// [0,start]:1000 -> has time-tag index with time.
/// [0,start] -> has time-tag index with no time.
/// [0,start]: -> has time-tag index with no time.
- /// [0,start]#karaoke -> has time-tag index with romaji.
- /// [0,start]#^karaoke -> has time-tag index with romaji, and it's initial romaji.
- /// [0,start]:1000#karaoke -> has time-tag index with time and romaji.
+ /// [0,start]#karaoke -> has time-tag index with romanized syllable.
+ /// [0,start]#^karaoke -> has time-tag index with romanized syllable, and it's the first one.
+ /// [0,start]:1000#karaoke -> has time-tag index with time and romanized syllable.
/// /// Time tag string format /// Time tag object @@ -152,12 +152,12 @@ public static TimeTag ParseTimeTag(string? str) var state = result.GetGroupValue("state") == "start" ? TextIndex.IndexState.Start : TextIndex.IndexState.End; int? time = result.GetGroupValue("time"); string? text = result.GetGroupValue("text"); - bool? initialRomaji = text?.StartsWith("^"); + bool? firstSyllable = text?.StartsWith("^"); return new TimeTag(new TextIndex(index, state), time) { - RomajiText = text?.Replace("^", ""), - InitialRomaji = initialRomaji ?? default, + FirstSyllable = firstSyllable ?? default, + RomanizedSyllable = text?.Replace("^", ""), }; }); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs index a460f0f46..224cc702a 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs @@ -179,8 +179,8 @@ public void AutoGenerate(AutoGenerateType type) foreach (var (key, value) in results) { var matchedTimeTag = lyric.TimeTags.Single(x => x == key); - matchedTimeTag.InitialRomaji = value.InitialRomaji; - matchedTimeTag.RomajiText = value.RomajiText; + matchedTimeTag.FirstSyllable = value.InitialRomaji; + matchedTimeTag.RomanizedSyllable = value.RomajiText; } }); break; diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs index 87dd4226b..7c8a0afaa 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs @@ -37,7 +37,7 @@ public void SetTimeTagInitialRomaji(TimeTag timeTag, bool initialRomaji) if (!containsInLyric) throw new InvalidOperationException($"{nameof(timeTag)} is not in the lyric"); - timeTag.InitialRomaji = initialRomaji; + timeTag.FirstSyllable = initialRomaji; }); } @@ -51,13 +51,13 @@ public void SetTimeTagRomajiText(TimeTag timeTag, string romaji) if (!containsInLyric) throw new InvalidOperationException($"{nameof(timeTag)} is not in the lyric"); - timeTag.RomajiText = romaji; + timeTag.RomanizedSyllable = romaji; if (!string.IsNullOrWhiteSpace(romaji)) return; - timeTag.RomajiText = string.Empty; - timeTag.InitialRomaji = false; + timeTag.RomanizedSyllable = string.Empty; + timeTag.FirstSyllable = false; }); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Checks/CheckLyricTimeTag.cs b/osu.Game.Rulesets.Karaoke/Edit/Checks/CheckLyricTimeTag.cs index 0343cebd6..528212106 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Checks/CheckLyricTimeTag.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Checks/CheckLyricTimeTag.cs @@ -35,7 +35,7 @@ protected override IEnumerable Check(Lyric lyric) { var issues = new List(); issues.AddRange(CheckTimeTag(lyric)); - issues.AddRange(CheckTimeTagRomaji(lyric)); + issues.AddRange(CheckTimeTagRomanizedSyllable(lyric)); return issues; } @@ -78,7 +78,7 @@ protected IEnumerable CheckTimeTag(Lyric lyric) } } - protected IEnumerable CheckTimeTagRomaji(Lyric lyric) + protected IEnumerable CheckTimeTagRomanizedSyllable(Lyric lyric) { if (!lyric.TimeTags.Any()) { @@ -87,27 +87,27 @@ protected IEnumerable CheckTimeTagRomaji(Lyric lyric) foreach (var timeTag in lyric.TimeTags) { - bool initialRomaji = timeTag.InitialRomaji; - string? romajiText = timeTag.RomajiText; + bool firstSyllable = timeTag.FirstSyllable; + string? romanizedSyllable = timeTag.RomanizedSyllable; switch (timeTag.Index.State) { case TextIndex.IndexState.Start: - // if input the romaji text, should be valid. - if (romajiText != null && !isRomajiTextValid(romajiText)) + // if input the romanized syllable, should be valid. + if (romanizedSyllable != null && !isRomanizedSyllableValid(romanizedSyllable)) yield return new IssueTemplateLyricTimeTagRomajiInvalidText(this).Create(lyric, timeTag); - // if is first romaji text, should not be null. - if (initialRomaji && romajiText == null) + // if is first romanized syllable, should not be null. + if (firstSyllable && romanizedSyllable == null) yield return new IssueTemplateLyricTimeTagRomajiInvalidTextIfFirst(this).Create(lyric, timeTag); break; case TextIndex.IndexState.End: - if (romajiText != null) + if (romanizedSyllable != null) yield return new IssueTemplateLyricTimeTagRomajiNotHaveEmptyTextIfEnd(this).Create(lyric, timeTag); - if (initialRomaji) + if (firstSyllable) yield return new IssueTemplateLyricTimeTagRomajiNotFistRomajiTextIfEnd(this).Create(lyric, timeTag); break; @@ -119,7 +119,7 @@ protected IEnumerable CheckTimeTagRomaji(Lyric lyric) yield break; - static bool isRomajiTextValid(string text) + static bool isRomanizedSyllableValid(string text) { // should not be white-space only. if (string.IsNullOrWhiteSpace(text)) diff --git a/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs b/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs index 75869c4ec..d39dd1c79 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs @@ -61,7 +61,7 @@ private void initInternalBindingEvent() foreach (var c in args.NewItems.Cast()) { c.TimingChanged += timingInvalidate; - c.RomajiChanged += romajiInvalidate; + c.SyllableChanged += romajiInvalidate; } break; @@ -73,7 +73,7 @@ private void initInternalBindingEvent() foreach (var c in args.OldItems.Cast()) { c.TimingChanged -= timingInvalidate; - c.RomajiChanged -= romajiInvalidate; + c.SyllableChanged -= romajiInvalidate; } break; diff --git a/osu.Game.Rulesets.Karaoke/Objects/TimeTag.cs b/osu.Game.Rulesets.Karaoke/Objects/TimeTag.cs index bf92ff651..79ffc86eb 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/TimeTag.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/TimeTag.cs @@ -17,9 +17,9 @@ public class TimeTag : IDeepCloneable public event Action? TimingChanged; /// - /// Invoked when or of this is changed. + /// Invoked when or of this is changed. /// - public event Action? RomajiChanged; + public event Action? SyllableChanged; public TimeTag(TextIndex index, double? time = null) { @@ -27,8 +27,8 @@ public TimeTag(TextIndex index, double? time = null) Time = time; TimeBindable.ValueChanged += _ => TimingChanged?.Invoke(); - InitialRomajiBindable.ValueChanged += _ => RomajiChanged?.Invoke(); - RomajiTextBindable.ValueChanged += _ => RomajiChanged?.Invoke(); + FirstSyllableBindable.ValueChanged += _ => SyllableChanged?.Invoke(); + RomanizedSyllableBindable.ValueChanged += _ => SyllableChanged?.Invoke(); } /// @@ -50,7 +50,7 @@ public double? Time } [JsonIgnore] - public readonly Bindable InitialRomajiBindable = new(); + public readonly Bindable FirstSyllableBindable = new(); /// /// Mark if this romaji is the first letter of the romaji word. @@ -65,22 +65,22 @@ public double? Time /// If this is the first or(4th) time-tag, then this value should be true.
/// If this ts the 2th or 3th time-tag, then this value should be false.
/// - public bool InitialRomaji + public bool FirstSyllable { - get => InitialRomajiBindable.Value; - set => InitialRomajiBindable.Value = value; + get => FirstSyllableBindable.Value; + set => FirstSyllableBindable.Value = value; } [JsonIgnore] - public readonly Bindable RomajiTextBindable = new(); + public readonly Bindable RomanizedSyllableBindable = new(); /// /// Romaji /// - public string? RomajiText + public string? RomanizedSyllable { - get => RomajiTextBindable.Value; - set => RomajiTextBindable.Value = value; + get => RomanizedSyllableBindable.Value; + set => RomanizedSyllableBindable.Value = value; } public TimeTag DeepClone() diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorVerifier.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorVerifier.cs index 100015ceb..e0904cfd8 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorVerifier.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorVerifier.cs @@ -200,6 +200,6 @@ public class CheckLyricTimeTagRomaji : CheckLyricTimeTag { protected override IEnumerable Check(Lyric lyric) { - return CheckTimeTagRomaji(lyric); + return CheckTimeTagRomanizedSyllable(lyric); } } diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Romaji/RomajiEditSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Romaji/RomajiEditSection.cs index dffe4b520..d48191bbd 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Romaji/RomajiEditSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Romaji/RomajiEditSection.cs @@ -69,7 +69,7 @@ protected override Drawable CreateDrawable(TimeTag item) }, RomajiEditPropertyMode.Initial => new LabelledInitialSwitchButton(item) { - Label = item.RomajiText ?? string.Empty, + Label = item.RomanizedSyllable ?? string.Empty, }, _ => throw new ArgumentOutOfRangeException(nameof(bindableRomajiEditPropertyMode.Value)), }; @@ -98,7 +98,7 @@ protected override void TriggerSelect(TimeTag item) => editRomajiModeState.Select(item); protected override string GetFieldValue(TimeTag timeTag) - => timeTag.RomajiText ?? string.Empty; + => timeTag.RomanizedSyllable ?? string.Empty; protected override void ApplyValue(TimeTag timeTag, string value) => lyricTimeTagsChangeHandler.SetTimeTagRomajiText(timeTag, value); @@ -121,7 +121,7 @@ public LabelledInitialSwitchButton(TimeTag item) } protected override bool GetFieldValue(TimeTag timeTag) - => timeTag.InitialRomaji; + => timeTag.FirstSyllable; protected override void ApplyValue(TimeTag timeTag, bool value) => lyricTimeTagsChangeHandler.SetTimeTagInitialRomaji(timeTag, value); From 38a6ed26a7a029750a0fb7565741b7f916cadc1a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 16 Jan 2024 00:06:49 +0800 Subject: [PATCH 2/3] Rename the method in the change handler. --- .../Lyrics/LyricTimeTagsChangeHandlerTest.cs | 10 +++++----- .../Lyrics/ILyricTimeTagsChangeHandler.cs | 4 ++-- .../Lyrics/LyricTimeTagsChangeHandler.cs | 10 +++++----- .../Lyrics/Settings/Romaji/RomajiEditSection.cs | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs index 334d0b310..4374f0292 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs @@ -38,7 +38,7 @@ public void TestSetTimeTagTime() } [Test] - public void TestSetTimeTagInitialRomaji() + public void TestSetTimeTagFirstSyllable() { var timeTag = new TimeTag(new TextIndex(), 1000); PrepareHitObject(() => new Lyric @@ -50,7 +50,7 @@ public void TestSetTimeTagInitialRomaji() }, }); - TriggerHandlerChanged(c => c.SetTimeTagInitialRomaji(timeTag, true)); + TriggerHandlerChanged(c => c.SetTimeTagFirstSyllable(timeTag, true)); AssertSelectedHitObject(_ => { @@ -59,7 +59,7 @@ public void TestSetTimeTagInitialRomaji() } [Test] - public void TestSetTimeTagRomajiText() + public void TestSetTimeTagRomanizedSyllable() { var timeTag = new TimeTag(new TextIndex(), 1000); PrepareHitObject(() => new Lyric @@ -71,14 +71,14 @@ public void TestSetTimeTagRomajiText() }, }); - TriggerHandlerChanged(c => c.SetTimeTagRomajiText(timeTag, "karaoke")); + TriggerHandlerChanged(c => c.SetTimeTagRomanizedSyllable(timeTag, "karaoke")); AssertSelectedHitObject(_ => { Assert.AreEqual("karaoke", timeTag.RomanizedSyllable); }); - TriggerHandlerChanged(c => c.SetTimeTagRomajiText(timeTag, " ")); + TriggerHandlerChanged(c => c.SetTimeTagRomanizedSyllable(timeTag, " ")); AssertSelectedHitObject(_ => { diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs index 1a83d1241..76b7f7ca0 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs @@ -11,9 +11,9 @@ public interface ILyricTimeTagsChangeHandler : ILyricListPropertyChangeHandler timeTags, double offset); diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs index 7c8a0afaa..8b298ee39 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs @@ -27,7 +27,7 @@ public void SetTimeTagTime(TimeTag timeTag, double time) }); } - public void SetTimeTagInitialRomaji(TimeTag timeTag, bool initialRomaji) + public void SetTimeTagFirstSyllable(TimeTag timeTag, bool firstSyllable) { CheckExactlySelectedOneHitObject(); @@ -37,11 +37,11 @@ public void SetTimeTagInitialRomaji(TimeTag timeTag, bool initialRomaji) if (!containsInLyric) throw new InvalidOperationException($"{nameof(timeTag)} is not in the lyric"); - timeTag.FirstSyllable = initialRomaji; + timeTag.FirstSyllable = firstSyllable; }); } - public void SetTimeTagRomajiText(TimeTag timeTag, string romaji) + public void SetTimeTagRomanizedSyllable(TimeTag timeTag, string? romanizedSyllable) { CheckExactlySelectedOneHitObject(); @@ -51,9 +51,9 @@ public void SetTimeTagRomajiText(TimeTag timeTag, string romaji) if (!containsInLyric) throw new InvalidOperationException($"{nameof(timeTag)} is not in the lyric"); - timeTag.RomanizedSyllable = romaji; + timeTag.RomanizedSyllable = romanizedSyllable; - if (!string.IsNullOrWhiteSpace(romaji)) + if (!string.IsNullOrWhiteSpace(romanizedSyllable)) return; timeTag.RomanizedSyllable = string.Empty; diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Romaji/RomajiEditSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Romaji/RomajiEditSection.cs index d48191bbd..e66b401d0 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Romaji/RomajiEditSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Romaji/RomajiEditSection.cs @@ -101,7 +101,7 @@ protected override string GetFieldValue(TimeTag timeTag) => timeTag.RomanizedSyllable ?? string.Empty; protected override void ApplyValue(TimeTag timeTag, string value) - => lyricTimeTagsChangeHandler.SetTimeTagRomajiText(timeTag, value); + => lyricTimeTagsChangeHandler.SetTimeTagRomanizedSyllable(timeTag, value); [BackgroundDependencyLoader] private void load() @@ -124,7 +124,7 @@ protected override bool GetFieldValue(TimeTag timeTag) => timeTag.FirstSyllable; protected override void ApplyValue(TimeTag timeTag, bool value) - => lyricTimeTagsChangeHandler.SetTimeTagInitialRomaji(timeTag, value); + => lyricTimeTagsChangeHandler.SetTimeTagFirstSyllable(timeTag, value); [BackgroundDependencyLoader] private void load(IEditRomajiModeState editRomajiModeState) From d63d5cf861b84b19157683f8a29af606f852f97d Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 16 Jan 2024 00:18:01 +0800 Subject: [PATCH 3/3] Rename the romanization generator and adjust the naming. --- .../Romajis/RomajiGenerateResultHelper.cs | 50 --------------- .../BaseRomanizationGeneratorTest.cs} | 12 ++-- .../Ja/JaRomanizationGeneratorTest.cs} | 41 ++++++------ .../RomanizationGenerateResultHelper.cs | 50 +++++++++++++++ .../RomanizationGeneratorSelectorTest.cs} | 14 ++--- ...araokeRulesetEditGeneratorConfigManager.cs | 6 +- .../LyricPropertyAutoGenerateChangeHandler.cs | 12 ++-- .../Lyrics/Romajies/RomajiGenerateResult.cs | 11 ---- .../Romajies/RomajiGeneratorSelector.cs | 20 ------ .../Ja/JaRomanizationGenerator.cs} | 62 +++++++++---------- .../Ja/JaRomanizationGeneratorConfig.cs} | 6 +- .../RomanizationGenerateResult.cs | 11 ++++ .../RomanizationGenerator.cs} | 8 +-- .../RomanizationGeneratorConfig.cs} | 4 +- .../RomanizationGeneratorSelector.cs | 20 ++++++ 15 files changed, 162 insertions(+), 165 deletions(-) delete mode 100644 osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romajis/RomajiGenerateResultHelper.cs rename osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/{Romajis/BaseRomajiGeneratorTest.cs => Romanization/BaseRomanizationGeneratorTest.cs} (56%) rename osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/{Romajis/Ja/JaRomajiGeneratorTest.cs => Romanization/Ja/JaRomanizationGeneratorTest.cs} (71%) create mode 100644 osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/Romanization/RomanizationGenerateResultHelper.cs rename osu.Game.Rulesets.Karaoke.Tests/Editor/Generator/Lyrics/{Romajis/RomajiGeneratorSelectorTest.cs => Romanization/RomanizationGeneratorSelectorTest.cs} (77%) delete mode 100644 osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGenerateResult.cs delete mode 100644 osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romajies/RomajiGeneratorSelector.cs rename osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/{Romajies/Ja/JaRomajiGenerator.cs => Romanization/Ja/JaRomanizationGenerator.cs} (58%) rename osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/{Romajies/Ja/JaRomajiGeneratorConfig.cs => Romanization/Ja/JaRomanizationGeneratorConfig.cs} (54%) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGenerateResult.cs rename osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/{Romajies/RomajiGenerator.cs => Romanization/RomanizationGenerator.cs} (69%) rename osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/{Romajies/RomajiGeneratorConfig.cs => Romanization/RomanizationGeneratorConfig.cs} (53%) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Romanization/RomanizationGeneratorSelector.cs 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)); + } +}