From c8b45a1fd628bbc7016444291301e615ccdb4c9c Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 27 Sep 2023 21:50:06 +0800 Subject: [PATCH 1/3] Rename the interface param name. --- .../Edit/ChangeHandlers/IAutoGenerateChangeHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/IAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/IAutoGenerateChangeHandler.cs index f586224da..4f11b9c61 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/IAutoGenerateChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/IAutoGenerateChangeHandler.cs @@ -11,9 +11,9 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers; /// public interface IEnumAutoGenerateChangeHandler where TEnum : Enum { - bool CanGenerate(TEnum property); + bool CanGenerate(TEnum type); - void AutoGenerate(TEnum property); + void AutoGenerate(TEnum type); } /// From 4af67c9d97fadef034c5d741b6e0fb898917d5db Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 27 Sep 2023 21:50:16 +0800 Subject: [PATCH 2/3] Rename the param name in the change handler. --- .../LyricPropertyAutoGenerateChangeHandler.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs index 19b457ca7..dc1531213 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs @@ -27,16 +27,16 @@ public partial class LyricPropertyAutoGenerateChangeHandler : LyricPropertyChang { // should change this flag if wants to change property in the lyrics. // Not a good to waite a global property for that but there's no better choice. - private AutoGenerateType? currentAutoGenerateProperty; + private AutoGenerateType? currentAutoGenerateType; [Resolved] private EditorBeatmap beatmap { get; set; } = null!; - public bool CanGenerate(AutoGenerateType autoGenerateProperty) + public bool CanGenerate(AutoGenerateType type) { - currentAutoGenerateProperty = autoGenerateProperty; + currentAutoGenerateType = type; - switch (autoGenerateProperty) + switch (type) { case AutoGenerateType.DetectReferenceLyric: var referenceLyricDetector = getDetector(HitObjects); @@ -63,7 +63,7 @@ public bool CanGenerate(AutoGenerateType autoGenerateProperty) return canGenerate(noteGenerator); default: - throw new ArgumentOutOfRangeException(nameof(autoGenerateProperty)); + throw new ArgumentOutOfRangeException(nameof(type)); } bool canDetect(PropertyDetector detector) @@ -73,11 +73,11 @@ bool canGenerate(PropertyGenerator generator) => HitObjects.Where(x => !IsWritePropertyLocked(x)).Any(generator.CanGenerate); } - public IDictionary GetGeneratorNotSupportedLyrics(AutoGenerateType autoGenerateProperty) + public IDictionary GetGeneratorNotSupportedLyrics(AutoGenerateType type) { - currentAutoGenerateProperty = autoGenerateProperty; + currentAutoGenerateType = type; - switch (autoGenerateProperty) + switch (type) { case AutoGenerateType.DetectReferenceLyric: var referenceLyricDetector = getDetector(HitObjects); @@ -104,7 +104,7 @@ public IDictionary GetGeneratorNotSupportedLyrics(Auto return getInvalidMessageFromGenerator(noteGenerator); default: - throw new ArgumentOutOfRangeException(nameof(autoGenerateProperty)); + throw new ArgumentOutOfRangeException(nameof(type)); } IDictionary getInvalidMessageFromDetector(PropertyDetector detector) @@ -124,11 +124,11 @@ IDictionary getInvalidMessageFromGenerator(Property } } - public void AutoGenerate(AutoGenerateType autoGenerateProperty) + public void AutoGenerate(AutoGenerateType type) { - currentAutoGenerateProperty = autoGenerateProperty; + currentAutoGenerateType = type; - switch (autoGenerateProperty) + switch (type) { case AutoGenerateType.DetectReferenceLyric: var referenceLyricDetector = getDetector(HitObjects); @@ -192,7 +192,7 @@ public void AutoGenerate(AutoGenerateType autoGenerateProperty) break; default: - throw new ArgumentOutOfRangeException(nameof(autoGenerateProperty)); + throw new ArgumentOutOfRangeException(nameof(type)); } } @@ -200,7 +200,7 @@ public override bool IsSelectionsLocked() => throw new InvalidOperationException("Auto-generator does not support this check method."); protected override bool IsWritePropertyLocked(Lyric lyric) => - currentAutoGenerateProperty switch + currentAutoGenerateType switch { AutoGenerateType.DetectReferenceLyric => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.ReferenceLyric), nameof(Lyric.ReferenceLyricConfig)), AutoGenerateType.DetectLanguage => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.Language)), From 825847a5e7e4a989e5594f208923d984f1b4585b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 27 Sep 2023 21:55:28 +0800 Subject: [PATCH 3/3] Apply new generator. --- ...icPropertyAutoGenerateChangeHandlerTest.cs | 40 ++++++++++++++++++- ...ILyricPropertyAutoGenerateChangeHandler.cs | 2 + .../LyricPropertyAutoGenerateChangeHandler.cs | 25 ++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) 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 ec6302edf..01ad22e69 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandlerTest.cs @@ -197,7 +197,7 @@ public void TestAutoGenerateRomajiTagsWithNonSupportedLyric() #endregion - #region TimeTag + #region Time-tag [Test] public void TestAutoGenerateTimeTags() @@ -241,6 +241,44 @@ public void TestAutoGenerateTimeTagsWithNonSupportedLyric() #endregion + #region Time-tag romaji + + [Test] + public void TestAutoGenerateTimeTagRomaji() + { + PrepareHitObject(() => new Lyric + { + Text = "カラオケ", + Language = new CultureInfo(17), + TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { "[0,start]", "[3,end]" }), + }); + + TriggerHandlerChanged(c => c.AutoGenerate(AutoGenerateType.AutoGenerateTimeTagRomaji)); + + AssertSelectedHitObject(h => + { + Assert.AreEqual("karaoke", h.TimeTags[0].RomajiText); + }); + } + + [Test] + public void TestAutoGenerateTimeTagRomajiWithNonSupportedLyric() + { + PrepareHitObjects(() => new[] + { + new Lyric + { + Text = "カラオケ", + Language = new CultureInfo(17), + // with no time-tag. + }, + }); + + TriggerHandlerChangedWithException(c => c.AutoGenerate(AutoGenerateType.AutoGenerateTimeTagRomaji)); + } + + #endregion + #region Note [Test] diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricPropertyAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricPropertyAutoGenerateChangeHandler.cs index 64490137c..7f9e7b850 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricPropertyAutoGenerateChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricPropertyAutoGenerateChangeHandler.cs @@ -24,5 +24,7 @@ public enum AutoGenerateType AutoGenerateTimeTags, + AutoGenerateTimeTagRomaji, + AutoGenerateNotes, } diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs index dc1531213..c62c3c1ff 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs @@ -13,6 +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.RomajiTags; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.RubyTags; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.TimeTags; @@ -58,6 +59,10 @@ public bool CanGenerate(AutoGenerateType type) var timeTagGenerator = getSelector(); return canGenerate(timeTagGenerator); + case AutoGenerateType.AutoGenerateTimeTagRomaji: + var timeTagRomajiGenerator = getSelector, RomajiGeneratorConfig>(); + return canGenerate(timeTagRomajiGenerator); + case AutoGenerateType.AutoGenerateNotes: var noteGenerator = getGenerator(); return canGenerate(noteGenerator); @@ -99,6 +104,10 @@ public IDictionary GetGeneratorNotSupportedLyrics(Auto var timeTagGenerator = getSelector(); return getInvalidMessageFromGenerator(timeTagGenerator); + case AutoGenerateType.AutoGenerateTimeTagRomaji: + var timeTagRomajiGenerator = getSelector, RomajiGeneratorConfig>(); + return getInvalidMessageFromGenerator(timeTagRomajiGenerator); + case AutoGenerateType.AutoGenerateNotes: var noteGenerator = getGenerator(); return getInvalidMessageFromGenerator(noteGenerator); @@ -178,6 +187,21 @@ public void AutoGenerate(AutoGenerateType type) }); break; + case AutoGenerateType.AutoGenerateTimeTagRomaji: + var timeTagRomajiGenerator = getSelector, RomajiGeneratorConfig>(); + PerformOnSelection(lyric => + { + var results = timeTagRomajiGenerator.Generate(lyric); + + foreach (var (key, value) in results) + { + var matchedTimeTag = lyric.TimeTags.Single(x => x == key); + matchedTimeTag.InitialRomaji = value.InitialRomaji; + matchedTimeTag.RomajiText = value.RomajiText; + } + }); + break; + case AutoGenerateType.AutoGenerateNotes: var noteGenerator = getGenerator(); PerformOnSelection(lyric => @@ -207,6 +231,7 @@ protected override bool IsWritePropertyLocked(Lyric lyric) => AutoGenerateType.AutoGenerateRubyTags => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.RubyTags)), AutoGenerateType.AutoGenerateRomajiTags => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.RomajiTags)), AutoGenerateType.AutoGenerateTimeTags => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.TimeTags)), + AutoGenerateType.AutoGenerateTimeTagRomaji => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.TimeTags)), AutoGenerateType.AutoGenerateNotes => HitObjectWritableUtils.IsCreateOrRemoveNoteLocked(lyric), _ => throw new ArgumentOutOfRangeException(), };