From 3d519c8a4c49bff7be67e66559106ef69e5de539 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 27 Sep 2023 00:21:17 +0800 Subject: [PATCH 1/4] Change handler interface should support the generate handler with enum. --- .../ChangeHandlers/IAutoGenerateChangeHandler.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/IAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/IAutoGenerateChangeHandler.cs index 0713f1040..f586224da 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/IAutoGenerateChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/IAutoGenerateChangeHandler.cs @@ -1,8 +1,21 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. +using System; + namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers; +/// +/// This interface is defined checking able to generate or detect the property, and make the change for the property. +/// +/// +public interface IEnumAutoGenerateChangeHandler where TEnum : Enum +{ + bool CanGenerate(TEnum property); + + void AutoGenerate(TEnum property); +} + /// /// This interface is defined checking able to generate or detect the property, and make the change for the property. /// From 5d5e5dcde81634b688bb5080d2e7c7ec3f126578 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 27 Sep 2023 00:22:45 +0800 Subject: [PATCH 2/4] It's time to collect all generators into same change handler. means revert the change in the #1958. --- .../Lyrics/LyricLanguageChangeHandlerTest.cs | 38 --- .../Lyrics/LyricNotesChangeHandlerTest.cs | 60 ---- ...icPropertyAutoGenerateChangeHandlerTest.cs | 314 ++++++++++++++++-- .../Lyrics/LyricReferenceChangeHandlerTest.cs | 45 --- .../LyricRomajiTagsChangeHandlerTest.cs | 49 --- .../Lyrics/LyricRubyTagsChangeHandlerTest.cs | 49 --- .../Lyrics/LyricTimeTagsChangeHandlerTest.cs | 48 --- .../Lyrics/ILyricLanguageChangeHandler.cs | 2 +- .../Lyrics/ILyricNotesChangeHandler.cs | 2 +- ...ILyricPropertyAutoGenerateChangeHandler.cs | 19 +- .../Lyrics/ILyricReferenceChangeHandler.cs | 2 +- .../Lyrics/ILyricRomajiTagsChangeHandler.cs | 2 +- .../Lyrics/ILyricRubyTagsChangeHandler.cs | 2 +- .../Lyrics/ILyricTimeTagsChangeHandler.cs | 2 +- .../Lyrics/LyricLanguageChangeHandler.cs | 29 -- .../Lyrics/LyricNotesChangeHandler.cs | 39 --- .../LyricPropertyAutoGenerateChangeHandler.cs | 275 +++++++++++++++ .../Lyrics/LyricPropertyChangeHandler.cs | 91 ----- .../Lyrics/LyricReferenceChangeHandler.cs | 36 -- .../Lyrics/LyricRomajiTagsChangeHandler.cs | 29 -- .../Lyrics/LyricRubyTagsChangeHandler.cs | 29 -- .../Lyrics/LyricTimeTagsChangeHandler.cs | 28 -- 22 files changed, 587 insertions(+), 603 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricLanguageChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricLanguageChangeHandlerTest.cs index f3d553a23..73222d5b0 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricLanguageChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricLanguageChangeHandlerTest.cs @@ -11,44 +11,6 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics; public partial class LyricLanguageChangeHandlerTest : LyricPropertyChangeHandlerTest { - protected override bool IncludeAutoGenerator => true; - - #region Auto-Generate - - [Test] - public void TestDetectLanguage() - { - PrepareHitObject(() => new Lyric - { - Text = "カラオケ", - }); - - TriggerHandlerChanged(c => c.AutoGenerate()); - - AssertSelectedHitObject(h => - { - Assert.AreEqual(new CultureInfo("ja"), h.Language); - }); - } - - [Test] - public void TestDetectLanguageWithNonSupportedLyric() - { - PrepareHitObject(() => new Lyric - { - Text = "???", - }); - - TriggerHandlerChanged(c => c.AutoGenerate()); - - AssertSelectedHitObject(h => - { - Assert.IsNull(h.Language); - }); - } - - #endregion - [Test] public void TestSetLanguageToJapanese() { diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricNotesChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricNotesChangeHandlerTest.cs index 1f66520d6..d516f2a59 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricNotesChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricNotesChangeHandlerTest.cs @@ -1,70 +1,10 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System.Linq; -using NUnit.Framework; -using osu.Framework.Allocation; -using osu.Framework.Graphics.Sprites; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -using osu.Game.Rulesets.Karaoke.Edit.Generator; -using osu.Game.Rulesets.Karaoke.Edit.Utils; -using osu.Game.Rulesets.Karaoke.Objects; -using osu.Game.Screens.Edit; namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics; public partial class LyricNotesChangeHandlerTest : LyricPropertyChangeHandlerTest { - protected override bool IncludeAutoGenerator => true; - - #region Note - - [Test] - public void TestAutoGenerateNotes() - { - PrepareHitObject(() => new Lyric - { - Text = "カラオケ", - TimeTags = new[] - { - new TimeTag(new TextIndex(0), 0), - new TimeTag(new TextIndex(1), 1000), - new TimeTag(new TextIndex(2), 2000), - new TimeTag(new TextIndex(3), 3000), - new TimeTag(new TextIndex(3, TextIndex.IndexState.End), 4000), - }, - }); - - TriggerHandlerChanged(c => c.AutoGenerate()); - - AssertSelectedHitObject(h => - { - var actualNotes = getMatchedNotes(h); - Assert.AreEqual(4, actualNotes.Length); - - Assert.AreEqual("カ", actualNotes[0].Text); - Assert.AreEqual("ラ", actualNotes[1].Text); - Assert.AreEqual("オ", actualNotes[2].Text); - Assert.AreEqual("ケ", actualNotes[3].Text); - }); - } - - [Test] - public void TestAutoGenerateNotesWithNonSupportedLyric() - { - PrepareHitObject(() => new Lyric - { - Text = "カラオケ", - }); - - TriggerHandlerChangedWithException(c => c.AutoGenerate()); - } - - private Note[] getMatchedNotes(Lyric lyric) - { - var editorBeatmap = Dependencies.Get(); - return EditorBeatmapUtils.GetNotesByLyric(editorBeatmap, lyric).ToArray(); - } - - #endregion } 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 abd4625db..ec6302edf 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandlerTest.cs @@ -2,15 +2,19 @@ // See the LICENCE file in the repository root for full licence text. using System.Globalization; +using System.Linq; using NUnit.Framework; +using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; using osu.Game.Rulesets.Karaoke.Edit.Generator; +using osu.Game.Rulesets.Karaoke.Edit.Utils; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Objects.Properties; using osu.Game.Rulesets.Karaoke.Tests.Extensions; using osu.Game.Rulesets.Karaoke.Tests.Helper; +using osu.Game.Screens.Edit; namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics; @@ -19,24 +23,282 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics; /// If the in the is not empty. /// should be able to change the property. /// -/// -[TestFixture(typeof(LyricReferenceChangeHandler))] -[TestFixture(typeof(LyricLanguageChangeHandler))] -[TestFixture(typeof(LyricRubyTagsChangeHandler))] -[TestFixture(typeof(LyricRomajiTagsChangeHandler))] -[TestFixture(typeof(LyricTimeTagsChangeHandler))] -[TestFixture(typeof(LyricNotesChangeHandler))] -public partial class LyricPropertyAutoGenerateChangeHandlerTest : LyricPropertyChangeHandlerTest - where TChangeHandler : LyricPropertyChangeHandler, ILyricPropertyAutoGenerateChangeHandler, new() +public partial class LyricPropertyAutoGenerateChangeHandlerTest : LyricPropertyChangeHandlerTest { protected override bool IncludeAutoGenerator => true; + #region Reference lyric + + [Test] + public void TestDetectReferenceLyric() + { + PrepareHitObject(() => new Lyric + { + Text = "カラオケ", + }, false); + + PrepareHitObject(() => new Lyric + { + Text = "カラオケ", + }); + + TriggerHandlerChanged(c => c.AutoGenerate(AutoGenerateType.DetectReferenceLyric)); + + AssertSelectedHitObject(h => + { + Assert.IsNotNull(h.ReferenceLyric); + Assert.IsTrue(h.ReferenceLyricConfig is SyncLyricConfig); + }); + } + + [Test] + public void TestDetectReferenceLyricWithNonSupportedLyric() + { + PrepareHitObject(() => new Lyric + { + Text = "カラオケ", + }, false); + + PrepareHitObject(() => new Lyric + { + Text = "???", + }); + + TriggerHandlerChangedWithException(c => c.AutoGenerate(AutoGenerateType.DetectReferenceLyric)); + } + + #endregion + + #region Language + + [Test] + public void TestDetectLanguage() + { + PrepareHitObject(() => new Lyric + { + Text = "カラオケ", + }); + + TriggerHandlerChanged(c => c.AutoGenerate(AutoGenerateType.DetectLanguage)); + + AssertSelectedHitObject(h => + { + Assert.AreEqual(new CultureInfo("ja"), h.Language); + }); + } + + [Test] + public void TestDetectLanguageWithNonSupportedLyric() + { + PrepareHitObject(() => new Lyric + { + Text = "???", + }); + + TriggerHandlerChanged(c => c.AutoGenerate(AutoGenerateType.DetectLanguage)); + + AssertSelectedHitObject(h => + { + Assert.IsNull(h.Language); + }); + } + + #endregion + + #region Ruby + + [Test] + public void TestAutoGenerateRubyTags() + { + PrepareHitObject(() => new Lyric + { + Text = "風", + Language = new CultureInfo(17), + }); + + TriggerHandlerChanged(c => c.AutoGenerate(AutoGenerateType.AutoGenerateRubyTags)); + + AssertSelectedHitObject(h => + { + var rubyTags = h.RubyTags; + Assert.AreEqual(1, rubyTags.Count); + Assert.AreEqual("かぜ", rubyTags[0].Text); + }); + } + + [Test] + public void TestAutoGenerateRubyTagsWithNonSupportedLyric() + { + PrepareHitObjects(() => new[] + { + new Lyric + { + Text = "風", + }, + new Lyric + { + Text = string.Empty, + }, + new Lyric + { + Text = string.Empty, + Language = new CultureInfo(17), + }, + }); + + TriggerHandlerChangedWithException(c => c.AutoGenerate(AutoGenerateType.AutoGenerateRubyTags)); + } + + #endregion + + #region Romaji + + [Test] + public void TestAutoGenerateRomajiTags() + { + PrepareHitObject(() => new Lyric + { + Text = "風", + Language = new CultureInfo(17), + }); + + TriggerHandlerChanged(c => c.AutoGenerate(AutoGenerateType.AutoGenerateRomajiTags)); + + AssertSelectedHitObject(h => + { + var romajiTags = h.RomajiTags; + Assert.AreEqual(1, romajiTags.Count); + Assert.AreEqual("kaze", romajiTags[0].Text); + }); + } + + [Test] + public void TestAutoGenerateRomajiTagsWithNonSupportedLyric() + { + PrepareHitObjects(() => new[] + { + new Lyric + { + Text = "風", + }, + new Lyric + { + Text = string.Empty, + }, + new Lyric + { + Text = string.Empty, + Language = new CultureInfo(17), + }, + }); + + TriggerHandlerChangedWithException(c => c.AutoGenerate(AutoGenerateType.AutoGenerateRomajiTags)); + } + + #endregion + + #region TimeTag + + [Test] + public void TestAutoGenerateTimeTags() + { + PrepareHitObject(() => new Lyric + { + Text = "カラオケ", + Language = new CultureInfo(17), + }); + + TriggerHandlerChanged(c => c.AutoGenerate(AutoGenerateType.AutoGenerateTimeTags)); + + AssertSelectedHitObject(h => + { + Assert.AreEqual(5, h.TimeTags.Count); + }); + } + + [Test] + public void TestAutoGenerateTimeTagsWithNonSupportedLyric() + { + PrepareHitObjects(() => new[] + { + new Lyric + { + Text = "カラオケ", + }, + new Lyric + { + Text = string.Empty, + }, + new Lyric + { + Text = string.Empty, + Language = new CultureInfo(17), + }, + }); + + TriggerHandlerChangedWithException(c => c.AutoGenerate(AutoGenerateType.AutoGenerateTimeTags)); + } + + #endregion + + #region Note + + [Test] + public void TestAutoGenerateNotes() + { + PrepareHitObject(() => new Lyric + { + Text = "カラオケ", + TimeTags = new[] + { + new TimeTag(new TextIndex(0), 0), + new TimeTag(new TextIndex(1), 1000), + new TimeTag(new TextIndex(2), 2000), + new TimeTag(new TextIndex(3), 3000), + new TimeTag(new TextIndex(3, TextIndex.IndexState.End), 4000), + }, + }); + + TriggerHandlerChanged(c => c.AutoGenerate(AutoGenerateType.AutoGenerateNotes)); + + AssertSelectedHitObject(h => + { + var actualNotes = getMatchedNotes(h); + Assert.AreEqual(4, actualNotes.Length); + Assert.AreEqual("カ", actualNotes[0].Text); + Assert.AreEqual("ラ", actualNotes[1].Text); + Assert.AreEqual("オ", actualNotes[2].Text); + Assert.AreEqual("ケ", actualNotes[3].Text); + }); + } + + [Test] + public void TestAutoGenerateNotesWithNonSupportedLyric() + { + PrepareHitObject(() => new Lyric + { + Text = "カラオケ", + }); + + TriggerHandlerChangedWithException(c => c.AutoGenerate(AutoGenerateType.AutoGenerateNotes)); + } + + private Note[] getMatchedNotes(Lyric lyric) + { + var editorBeatmap = Dependencies.Get(); + return EditorBeatmapUtils.GetNotesByLyric(editorBeatmap, lyric).ToArray(); + } + + #endregion + + #region Shared tests + [Test] [Description("Should be able to generate the property if the lyric is not reference to other lyric.")] - public void ChangeWithNormalLyric() + public void ChangeWithNormalLyric([Values] AutoGenerateType type) { // for detect reference lyric. - if (isLyricReferenceChangeHandler()) + if (isLyricReferenceChangeHandler(type)) { PrepareHitObject(() => new Lyric { @@ -60,48 +322,48 @@ public void ChangeWithNormalLyric() TriggerHandlerChanged(c => { - Assert.IsTrue(c.CanGenerate()); + Assert.IsTrue(c.CanGenerate(type)); }); TriggerHandlerChanged(c => { - Assert.IsEmpty(c.GetGeneratorNotSupportedLyrics()); + Assert.IsEmpty(c.GetGeneratorNotSupportedLyrics(type)); }); TriggerHandlerChanged(c => { - Assert.DoesNotThrow(c.AutoGenerate); + Assert.DoesNotThrow(() => c.AutoGenerate(type)); }); } [Test] [Description("Should not be able to generate the property if the lyric is missing detectable property.")] - public void ChangeWithMissingPropertyLyric() + public void ChangeWithMissingPropertyLyric([Values] AutoGenerateType type) { PrepareHitObject(() => new Lyric()); TriggerHandlerChanged(c => { - Assert.IsFalse(c.CanGenerate()); + Assert.IsFalse(c.CanGenerate(type)); }); TriggerHandlerChanged(c => { - Assert.IsNotEmpty(c.GetGeneratorNotSupportedLyrics()); + Assert.IsNotEmpty(c.GetGeneratorNotSupportedLyrics(type)); }); TriggerHandlerChanged(c => { - var exception = Assert.Catch(c.AutoGenerate); + var exception = Assert.Catch(() => c.AutoGenerate(type)); Assert.Contains(exception?.GetType(), new[] { typeof(GeneratorNotSupportedException), typeof(DetectorNotSupportedException) }); }); } [Test] [Description("Should not be able to generate the property if the lyric is reference to other lyric.")] - public void CheckWithReferencedLyric() + public void CheckWithReferencedLyric([Values] AutoGenerateType type) { - if (isLyricReferenceChangeHandler()) + if (isLyricReferenceChangeHandler(type)) return; PrepareHitObject(() => new Lyric @@ -124,17 +386,19 @@ public void CheckWithReferencedLyric() TriggerHandlerChanged(c => { - Assert.IsFalse(c.CanGenerate()); + Assert.IsFalse(c.CanGenerate(type)); }); TriggerHandlerChanged(c => { - Assert.IsNotEmpty(c.GetGeneratorNotSupportedLyrics()); + Assert.IsNotEmpty(c.GetGeneratorNotSupportedLyrics(type)); }); - TriggerHandlerChangedWithException(c => c.AutoGenerate()); + TriggerHandlerChangedWithException(c => c.AutoGenerate(type)); } - private bool isLyricReferenceChangeHandler() - => typeof(TChangeHandler) == typeof(LyricReferenceChangeHandler); + private bool isLyricReferenceChangeHandler(AutoGenerateType type) + => type == AutoGenerateType.DetectReferenceLyric; + + #endregion } diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricReferenceChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricReferenceChangeHandlerTest.cs index 86c4bf9a0..9f0ce29ce 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricReferenceChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricReferenceChangeHandlerTest.cs @@ -3,7 +3,6 @@ using NUnit.Framework; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -using osu.Game.Rulesets.Karaoke.Edit.Generator; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Objects.Properties; @@ -11,50 +10,6 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics; public partial class LyricReferenceChangeHandlerTest : LyricPropertyChangeHandlerTest { - protected override bool IncludeAutoGenerator => true; - - #region Auto-Generate - - [Test] - public void TestDetectReferenceLyric() - { - PrepareHitObject(() => new Lyric - { - Text = "カラオケ", - }, false); - - PrepareHitObject(() => new Lyric - { - Text = "カラオケ", - }); - - TriggerHandlerChanged(c => c.AutoGenerate()); - - AssertSelectedHitObject(h => - { - Assert.IsNotNull(h.ReferenceLyric); - Assert.IsTrue(h.ReferenceLyricConfig is SyncLyricConfig); - }); - } - - [Test] - public void TestDetectReferenceLyricWithNonSupportedLyric() - { - PrepareHitObject(() => new Lyric - { - Text = "カラオケ", - }, false); - - PrepareHitObject(() => new Lyric - { - Text = "???", - }); - - TriggerHandlerChangedWithException(c => c.AutoGenerate()); - } - - #endregion - [Test] public void TestUpdateReferenceLyric() { diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricRomajiTagsChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricRomajiTagsChangeHandlerTest.cs index 7129984d7..e8e5c3fbd 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricRomajiTagsChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricRomajiTagsChangeHandlerTest.cs @@ -6,61 +6,12 @@ using NUnit.Framework; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -using osu.Game.Rulesets.Karaoke.Edit.Generator; using osu.Game.Rulesets.Karaoke.Objects; namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics; public partial class LyricRomajiTagsChangeHandlerTest : LyricPropertyChangeHandlerTest { - protected override bool IncludeAutoGenerator => true; - - #region Auto-Generate - - [Test] - public void TestAutoGenerateRomajiTags() - { - PrepareHitObject(() => new Lyric - { - Text = "風", - Language = new CultureInfo(17), - }); - - TriggerHandlerChanged(c => c.AutoGenerate()); - - AssertSelectedHitObject(h => - { - var romajiTags = h.RomajiTags; - Assert.AreEqual(1, romajiTags.Count); - Assert.AreEqual("kaze", romajiTags[0].Text); - }); - } - - [Test] - public void TestAutoGenerateRomajiTagsWithNonSupportedLyric() - { - PrepareHitObjects(() => new[] - { - new Lyric - { - Text = "風", - }, - new Lyric - { - Text = string.Empty, - }, - new Lyric - { - Text = string.Empty, - Language = new CultureInfo(17), - }, - }); - - TriggerHandlerChangedWithException(c => c.AutoGenerate()); - } - - #endregion - [Test] public void TestAdd() { diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricRubyTagsChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricRubyTagsChangeHandlerTest.cs index a44b7fe27..bfe295eb2 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricRubyTagsChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricRubyTagsChangeHandlerTest.cs @@ -6,61 +6,12 @@ using NUnit.Framework; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -using osu.Game.Rulesets.Karaoke.Edit.Generator; using osu.Game.Rulesets.Karaoke.Objects; namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics; public partial class LyricRubyTagsChangeHandlerTest : LyricPropertyChangeHandlerTest { - protected override bool IncludeAutoGenerator => true; - - #region Auto-Generate - - [Test] - public void TestAutoGenerateRubyTags() - { - PrepareHitObject(() => new Lyric - { - Text = "風", - Language = new CultureInfo(17), - }); - - TriggerHandlerChanged(c => c.AutoGenerate()); - - AssertSelectedHitObject(h => - { - var rubyTags = h.RubyTags; - Assert.AreEqual(1, rubyTags.Count); - Assert.AreEqual("かぜ", rubyTags[0].Text); - }); - } - - [Test] - public void TestAutoGenerateRubyTagsWithNonSupportedLyric() - { - PrepareHitObjects(() => new[] - { - new Lyric - { - Text = "風", - }, - new Lyric - { - Text = string.Empty, - }, - new Lyric - { - Text = string.Empty, - Language = new CultureInfo(17), - }, - }); - - TriggerHandlerChangedWithException(c => c.AutoGenerate()); - } - - #endregion - [Test] public void TestAdd() { 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 76c392561..f2764e636 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs @@ -2,14 +2,12 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Globalization; using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -using osu.Game.Rulesets.Karaoke.Edit.Generator; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Objects.Properties; using osu.Game.Screens.Edit; @@ -18,52 +16,6 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics; public partial class LyricTimeTagsChangeHandlerTest : LyricPropertyChangeHandlerTest { - protected override bool IncludeAutoGenerator => true; - - #region TimeTag - - [Test] - public void TestAutoGenerateTimeTags() - { - PrepareHitObject(() => new Lyric - { - Text = "カラオケ", - Language = new CultureInfo(17), - }); - - TriggerHandlerChanged(c => c.AutoGenerate()); - - AssertSelectedHitObject(h => - { - Assert.AreEqual(5, h.TimeTags.Count); - }); - } - - [Test] - public void TestAutoGenerateTimeTagsWithNonSupportedLyric() - { - PrepareHitObjects(() => new[] - { - new Lyric - { - Text = "カラオケ", - }, - new Lyric - { - Text = string.Empty, - }, - new Lyric - { - Text = string.Empty, - Language = new CultureInfo(17), - }, - }); - - TriggerHandlerChangedWithException(c => c.AutoGenerate()); - } - - #endregion - [Test] public void TestSetTimeTagTime() { diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricLanguageChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricLanguageChangeHandler.cs index 04dcb4dab..5bf50355b 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricLanguageChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricLanguageChangeHandler.cs @@ -5,7 +5,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -public interface ILyricLanguageChangeHandler : ILyricPropertyChangeHandler, ILyricPropertyAutoGenerateChangeHandler +public interface ILyricLanguageChangeHandler : ILyricPropertyChangeHandler { void SetLanguage(CultureInfo? language); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricNotesChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricNotesChangeHandler.cs index 245ad271a..40c09c314 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricNotesChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricNotesChangeHandler.cs @@ -3,6 +3,6 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -public interface ILyricNotesChangeHandler : ILyricPropertyChangeHandler, ILyricPropertyAutoGenerateChangeHandler +public interface ILyricNotesChangeHandler : ILyricPropertyChangeHandler { } diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricPropertyAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricPropertyAutoGenerateChangeHandler.cs index c15ba30c0..64490137c 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricPropertyAutoGenerateChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricPropertyAutoGenerateChangeHandler.cs @@ -7,7 +7,22 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -public interface ILyricPropertyAutoGenerateChangeHandler : IAutoGenerateChangeHandler +public interface ILyricPropertyAutoGenerateChangeHandler : ILyricPropertyChangeHandler, IEnumAutoGenerateChangeHandler { - IDictionary GetGeneratorNotSupportedLyrics(); + IDictionary GetGeneratorNotSupportedLyrics(AutoGenerateType type); +} + +public enum AutoGenerateType +{ + DetectReferenceLyric, + + DetectLanguage, + + AutoGenerateRubyTags, + + AutoGenerateRomajiTags, + + AutoGenerateTimeTags, + + AutoGenerateNotes, } diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricReferenceChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricReferenceChangeHandler.cs index 976ce038a..0e58a6448 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricReferenceChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricReferenceChangeHandler.cs @@ -7,7 +7,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -public interface ILyricReferenceChangeHandler : ILyricPropertyChangeHandler, ILyricPropertyAutoGenerateChangeHandler +public interface ILyricReferenceChangeHandler : ILyricPropertyChangeHandler { void UpdateReferenceLyric(Lyric? referenceLyric); diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricRomajiTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricRomajiTagsChangeHandler.cs index ef6d38780..6924a9715 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricRomajiTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricRomajiTagsChangeHandler.cs @@ -5,6 +5,6 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -public interface ILyricRomajiTagsChangeHandler : ILyricTextTagsChangeHandler, ILyricPropertyAutoGenerateChangeHandler +public interface ILyricRomajiTagsChangeHandler : ILyricTextTagsChangeHandler { } diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricRubyTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricRubyTagsChangeHandler.cs index 014098f70..4c2fc7c22 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricRubyTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricRubyTagsChangeHandler.cs @@ -5,6 +5,6 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -public interface ILyricRubyTagsChangeHandler : ILyricTextTagsChangeHandler, ILyricPropertyAutoGenerateChangeHandler +public interface ILyricRubyTagsChangeHandler : ILyricTextTagsChangeHandler { } diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs index 2cc9e92e9..1a83d1241 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs @@ -7,7 +7,7 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; -public interface ILyricTimeTagsChangeHandler : ILyricListPropertyChangeHandler, ILyricPropertyAutoGenerateChangeHandler +public interface ILyricTimeTagsChangeHandler : ILyricListPropertyChangeHandler { void SetTimeTagTime(TimeTag timeTag, double time); diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricLanguageChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricLanguageChangeHandler.cs index 9ab9d6535..ceb30d124 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricLanguageChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricLanguageChangeHandler.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Globalization; -using osu.Framework.Localisation; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Language; using osu.Game.Rulesets.Karaoke.Edit.Utils; using osu.Game.Rulesets.Karaoke.Objects; @@ -12,33 +10,6 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; public partial class LyricLanguageChangeHandler : LyricPropertyChangeHandler, ILyricLanguageChangeHandler { - #region Auto-Generate - - public bool CanGenerate() - { - var detector = GetDetector(); - return CanDetect(detector); - } - - public IDictionary GetGeneratorNotSupportedLyrics() - { - var detector = GetDetector(); - return GetInvalidMessageFromDetector(detector); - } - - public void AutoGenerate() - { - var detector = GetDetector(); - - PerformOnSelection(lyric => - { - var detectedLanguage = detector.Detect(lyric); - lyric.Language = detectedLanguage; - }); - } - - #endregion - public void SetLanguage(CultureInfo? language) { PerformOnSelection(lyric => diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricNotesChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricNotesChangeHandler.cs index 7218be7dc..551410cce 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricNotesChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricNotesChangeHandler.cs @@ -1,52 +1,13 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; -using osu.Framework.Allocation; -using osu.Framework.Localisation; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Notes; using osu.Game.Rulesets.Karaoke.Edit.Utils; using osu.Game.Rulesets.Karaoke.Objects; -using osu.Game.Screens.Edit; namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; public partial class LyricNotesChangeHandler : LyricPropertyChangeHandler, ILyricNotesChangeHandler { - #region Auto-Generate - - [Resolved] - private EditorBeatmap beatmap { get; set; } = null!; - - public bool CanGenerate() - { - var generator = GetGenerator(); - return CanGenerate(generator); - } - - public IDictionary GetGeneratorNotSupportedLyrics() - { - var generator = GetGenerator(); - return GetInvalidMessageFromGenerator(generator); - } - - public void AutoGenerate() - { - var generator = GetGenerator(); - - PerformOnSelection(lyric => - { - // clear exist notes if from those - var matchedNotes = EditorBeatmapUtils.GetNotesByLyric(beatmap, lyric); - RemoveRange(matchedNotes); - - var notes = generator.Generate(lyric); - AddRange(notes); - }); - } - - #endregion - protected override bool IsWritePropertyLocked(Lyric lyric) => HitObjectWritableUtils.IsCreateOrRemoveNoteLocked(lyric); } diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs new file mode 100644 index 000000000..19b457ca7 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs @@ -0,0 +1,275 @@ +// 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.Globalization; +using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Localisation; +using osu.Game.Rulesets.Karaoke.Configuration; +using osu.Game.Rulesets.Karaoke.Edit.Generator; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics; +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.RomajiTags; +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; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Objects.Properties; +using osu.Game.Screens.Edit; + +namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; + +public partial class LyricPropertyAutoGenerateChangeHandler : LyricPropertyChangeHandler, ILyricPropertyAutoGenerateChangeHandler +{ + // 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; + + [Resolved] + private EditorBeatmap beatmap { get; set; } = null!; + + public bool CanGenerate(AutoGenerateType autoGenerateProperty) + { + currentAutoGenerateProperty = autoGenerateProperty; + + switch (autoGenerateProperty) + { + case AutoGenerateType.DetectReferenceLyric: + var referenceLyricDetector = getDetector(HitObjects); + return canDetect(referenceLyricDetector); + + case AutoGenerateType.DetectLanguage: + var languageDetector = getDetector(); + return canDetect(languageDetector); + + case AutoGenerateType.AutoGenerateRubyTags: + var rubyGenerator = getSelector(); + return canGenerate(rubyGenerator); + + case AutoGenerateType.AutoGenerateRomajiTags: + var romajiGenerator = getSelector(); + return canGenerate(romajiGenerator); + + case AutoGenerateType.AutoGenerateTimeTags: + var timeTagGenerator = getSelector(); + return canGenerate(timeTagGenerator); + + case AutoGenerateType.AutoGenerateNotes: + var noteGenerator = getGenerator(); + return canGenerate(noteGenerator); + + default: + throw new ArgumentOutOfRangeException(nameof(autoGenerateProperty)); + } + + bool canDetect(PropertyDetector detector) + => HitObjects.Where(x => !IsWritePropertyLocked(x)).Any(detector.CanDetect); + + bool canGenerate(PropertyGenerator generator) + => HitObjects.Where(x => !IsWritePropertyLocked(x)).Any(generator.CanGenerate); + } + + public IDictionary GetGeneratorNotSupportedLyrics(AutoGenerateType autoGenerateProperty) + { + currentAutoGenerateProperty = autoGenerateProperty; + + switch (autoGenerateProperty) + { + case AutoGenerateType.DetectReferenceLyric: + var referenceLyricDetector = getDetector(HitObjects); + return getInvalidMessageFromDetector(referenceLyricDetector); + + case AutoGenerateType.DetectLanguage: + var languageDetector = getDetector(); + return getInvalidMessageFromDetector(languageDetector); + + case AutoGenerateType.AutoGenerateRubyTags: + var rubyGenerator = getSelector(); + return getInvalidMessageFromGenerator(rubyGenerator); + + case AutoGenerateType.AutoGenerateRomajiTags: + var romajiGenerator = getSelector(); + return getInvalidMessageFromGenerator(romajiGenerator); + + case AutoGenerateType.AutoGenerateTimeTags: + var timeTagGenerator = getSelector(); + return getInvalidMessageFromGenerator(timeTagGenerator); + + case AutoGenerateType.AutoGenerateNotes: + var noteGenerator = getGenerator(); + return getInvalidMessageFromGenerator(noteGenerator); + + default: + throw new ArgumentOutOfRangeException(nameof(autoGenerateProperty)); + } + + IDictionary getInvalidMessageFromDetector(PropertyDetector detector) + => HitObjects.Select(x => new KeyValuePair(x, detector.GetInvalidMessage(x) ?? getReferenceLyricInvalidMessage(x))) + .Where(x => x.Value != null) + .ToDictionary(k => k.Key, v => v.Value!.Value); + + IDictionary getInvalidMessageFromGenerator(PropertyGenerator generator) + => HitObjects.Select(x => new KeyValuePair(x, generator.GetInvalidMessage(x) ?? getReferenceLyricInvalidMessage(x))) + .Where(x => x.Value != null) + .ToDictionary(k => k.Key, v => v.Value!.Value); + + LocalisableString? getReferenceLyricInvalidMessage(Lyric lyric) + { + bool locked = IsWritePropertyLocked(lyric); + return locked ? "Cannot modify property because has reference lyric." : default(LocalisableString?); + } + } + + public void AutoGenerate(AutoGenerateType autoGenerateProperty) + { + currentAutoGenerateProperty = autoGenerateProperty; + + switch (autoGenerateProperty) + { + case AutoGenerateType.DetectReferenceLyric: + var referenceLyricDetector = getDetector(HitObjects); + PerformOnSelection(lyric => + { + var referencedLyric = referenceLyricDetector.Detect(lyric); + lyric.ReferenceLyricId = referencedLyric?.ID; + + // technically this property should be assigned by beatmap processor, but should be OK to assign here for testing purpose. + lyric.ReferenceLyric = referencedLyric; + + if (lyric.ReferenceLyricId != null && lyric.ReferenceLyricConfig is not SyncLyricConfig) + lyric.ReferenceLyricConfig = new SyncLyricConfig(); + }); + break; + + case AutoGenerateType.DetectLanguage: + var languageDetector = getDetector(); + PerformOnSelection(lyric => + { + var detectedLanguage = languageDetector.Detect(lyric); + lyric.Language = detectedLanguage; + }); + break; + + case AutoGenerateType.AutoGenerateRubyTags: + var rubyGenerator = getSelector(); + PerformOnSelection(lyric => + { + lyric.RubyTags = rubyGenerator.Generate(lyric); + }); + break; + + case AutoGenerateType.AutoGenerateRomajiTags: + var romajiGenerator = getSelector(); + PerformOnSelection(lyric => + { + lyric.RomajiTags = romajiGenerator.Generate(lyric); + }); + break; + + case AutoGenerateType.AutoGenerateTimeTags: + var timeTagGenerator = getSelector(); + PerformOnSelection(lyric => + { + lyric.TimeTags = timeTagGenerator.Generate(lyric); + }); + break; + + case AutoGenerateType.AutoGenerateNotes: + var noteGenerator = getGenerator(); + PerformOnSelection(lyric => + { + // clear exist notes if from those + var matchedNotes = EditorBeatmapUtils.GetNotesByLyric(beatmap, lyric); + RemoveRange(matchedNotes); + + var notes = noteGenerator.Generate(lyric); + AddRange(notes); + }); + break; + + default: + throw new ArgumentOutOfRangeException(nameof(autoGenerateProperty)); + } + } + + public override bool IsSelectionsLocked() + => throw new InvalidOperationException("Auto-generator does not support this check method."); + + protected override bool IsWritePropertyLocked(Lyric lyric) => + currentAutoGenerateProperty switch + { + AutoGenerateType.DetectReferenceLyric => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.ReferenceLyric), nameof(Lyric.ReferenceLyricConfig)), + AutoGenerateType.DetectLanguage => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.Language)), + 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.AutoGenerateNotes => HitObjectWritableUtils.IsCreateOrRemoveNoteLocked(lyric), + _ => throw new ArgumentOutOfRangeException(), + }; + + #region Utililty + + [Resolved] + private KaraokeRulesetEditGeneratorConfigManager? generatorConfigManager { get; set; } + + private LyricPropertyDetector getDetector() + where TConfig : GeneratorConfig, new() + { + var config = getGeneratorConfig(); + return createInstance>(config); + } + + private LyricPropertyDetector getDetector(IEnumerable lyrics) + where TConfig : GeneratorConfig, new() + { + var config = getGeneratorConfig(); + return createInstance>(lyrics, config); + } + + private LyricPropertyGenerator getGenerator() + where TConfig : GeneratorConfig, new() + { + var config = getGeneratorConfig(); + return createInstance>(config); + } + + private LyricGeneratorSelector getSelector() + where TBaseConfig : GeneratorConfig + { + return createInstance>(generatorConfigManager); + } + + private static TType createInstance(params object?[]? args) + { + var generatedType = getChildType(typeof(TType)); + + var instance = (TType?)Activator.CreateInstance(generatedType, args); + if (instance == null) + throw new InvalidOperationException(); + + return instance; + + static Type getChildType(Type type) + { + // should get the assembly that the has the class GeneratorConfig. + var assembly = typeof(GeneratorConfig).Assembly; + return assembly.GetTypes() + .Single(x => type.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); + } + } + + private TConfig getGeneratorConfig() + where TConfig : GeneratorConfig, new() + { + if (generatorConfigManager == null) + throw new InvalidOperationException(); + + return generatorConfigManager.Get(); + } + + #endregion +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyChangeHandler.cs index 17c5e6230..ec7e45949 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyChangeHandler.cs @@ -1,101 +1,10 @@ // 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.Framework.Allocation; -using osu.Framework.Localisation; -using osu.Game.Rulesets.Karaoke.Configuration; -using osu.Game.Rulesets.Karaoke.Edit.Generator; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics; using osu.Game.Rulesets.Karaoke.Objects; namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; public abstract partial class LyricPropertyChangeHandler : HitObjectPropertyChangeHandler, ILyricPropertyChangeHandler { - #region Auto-Generate - - [Resolved] - private KaraokeRulesetEditGeneratorConfigManager? generatorConfigManager { get; set; } - - protected LyricPropertyDetector GetDetector() - where TConfig : GeneratorConfig, new() - { - var config = getGeneratorConfig(); - return createInstance>(config); - } - - protected LyricPropertyDetector GetDetector(IEnumerable lyrics) - where TConfig : GeneratorConfig, new() - { - var config = getGeneratorConfig(); - return createInstance>(lyrics, config); - } - - protected LyricPropertyGenerator GetGenerator() - where TConfig : GeneratorConfig, new() - { - var config = getGeneratorConfig(); - return createInstance>(config); - } - - protected LyricGeneratorSelector GetSelector() - where TBaseConfig : GeneratorConfig - { - return createInstance>(generatorConfigManager); - } - - private static TType createInstance(params object?[]? args) - { - var generatedType = getChildType(typeof(TType)); - - var instance = (TType?)Activator.CreateInstance(generatedType, args); - if (instance == null) - throw new InvalidOperationException(); - - return instance; - - static Type getChildType(Type type) - { - // should get the assembly that the has the class GeneratorConfig. - var assembly = typeof(GeneratorConfig).Assembly; - return assembly.GetTypes() - .Single(x => type.IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); - } - } - - private TConfig getGeneratorConfig() - where TConfig : GeneratorConfig, new() - { - if (generatorConfigManager == null) - throw new InvalidOperationException(); - - return generatorConfigManager.Get(); - } - - protected bool CanDetect(PropertyDetector detector) - => HitObjects.Where(x => !IsWritePropertyLocked(x)).Any(detector.CanDetect); - - protected bool CanGenerate(PropertyGenerator generator) - => HitObjects.Where(x => !IsWritePropertyLocked(x)).Any(generator.CanGenerate); - - protected IDictionary GetInvalidMessageFromDetector(PropertyDetector detector) - => HitObjects.Select(x => new KeyValuePair(x, detector.GetInvalidMessage(x) ?? getReferenceLyricInvalidMessage(x))) - .Where(x => x.Value != null) - .ToDictionary(k => k.Key, v => v.Value!.Value); - - protected IDictionary GetInvalidMessageFromGenerator(PropertyGenerator generator) - => HitObjects.Select(x => new KeyValuePair(x, generator.GetInvalidMessage(x) ?? getReferenceLyricInvalidMessage(x))) - .Where(x => x.Value != null) - .ToDictionary(k => k.Key, v => v.Value!.Value); - - private LocalisableString? getReferenceLyricInvalidMessage(Lyric lyric) - { - bool locked = IsWritePropertyLocked(lyric); - return locked ? "Cannot modify property because has reference lyric." : default(LocalisableString?); - } - - #endregion } diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricReferenceChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricReferenceChangeHandler.cs index b3b6f5c62..1c4ff4a19 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricReferenceChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricReferenceChangeHandler.cs @@ -2,10 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; using System.Linq; -using osu.Framework.Localisation; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.ReferenceLyric; using osu.Game.Rulesets.Karaoke.Edit.Utils; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Objects.Properties; @@ -14,39 +11,6 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; public partial class LyricReferenceChangeHandler : LyricPropertyChangeHandler, ILyricReferenceChangeHandler { - #region Auto-Generate - - public bool CanGenerate() - { - var detector = GetDetector(HitObjects); - return CanDetect(detector); - } - - public IDictionary GetGeneratorNotSupportedLyrics() - { - var detector = GetDetector(HitObjects); - return GetInvalidMessageFromDetector(detector); - } - - public void AutoGenerate() - { - var detector = GetDetector(HitObjects); - - PerformOnSelection(lyric => - { - var referencedLyric = detector.Detect(lyric); - lyric.ReferenceLyricId = referencedLyric?.ID; - - // technically this property should be assigned by beatmap processor, but should be OK to assign here for testing purpose. - lyric.ReferenceLyric = referencedLyric; - - if (lyric.ReferenceLyricId != null && lyric.ReferenceLyricConfig is not SyncLyricConfig) - lyric.ReferenceLyricConfig = new SyncLyricConfig(); - }); - } - - #endregion - public void UpdateReferenceLyric(Lyric? referenceLyric) { if (referenceLyric != null && !HitObjects.Contains(referenceLyric)) diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricRomajiTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricRomajiTagsChangeHandler.cs index 4e2da4483..9a45af2cd 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricRomajiTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricRomajiTagsChangeHandler.cs @@ -1,9 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; -using osu.Framework.Localisation; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.RomajiTags; using osu.Game.Rulesets.Karaoke.Edit.Utils; using osu.Game.Rulesets.Karaoke.Objects; @@ -11,32 +8,6 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; public partial class LyricRomajiTagsChangeHandler : LyricTextTagsChangeHandler, ILyricRomajiTagsChangeHandler { - #region Auto-Generate - - public bool CanGenerate() - { - var generator = GetSelector(); - return CanGenerate(generator); - } - - public IDictionary GetGeneratorNotSupportedLyrics() - { - var generator = GetSelector(); - return GetInvalidMessageFromGenerator(generator); - } - - public void AutoGenerate() - { - var generator = GetSelector(); - - PerformOnSelection(lyric => - { - lyric.RomajiTags = generator.Generate(lyric); - }); - } - - #endregion - protected override bool ContainsInLyric(Lyric lyric, RomajiTag textTag) => lyric.RomajiTags.Contains(textTag); diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricRubyTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricRubyTagsChangeHandler.cs index 445984b1c..99dbc30f9 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricRubyTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricRubyTagsChangeHandler.cs @@ -1,9 +1,6 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; -using osu.Framework.Localisation; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.RubyTags; using osu.Game.Rulesets.Karaoke.Edit.Utils; using osu.Game.Rulesets.Karaoke.Objects; @@ -11,32 +8,6 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; public partial class LyricRubyTagsChangeHandler : LyricTextTagsChangeHandler, ILyricRubyTagsChangeHandler { - #region Auto-Generate - - public bool CanGenerate() - { - var generator = GetSelector(); - return CanGenerate(generator); - } - - public IDictionary GetGeneratorNotSupportedLyrics() - { - var generator = GetSelector(); - return GetInvalidMessageFromGenerator(generator); - } - - public void AutoGenerate() - { - var generator = GetSelector(); - - PerformOnSelection(lyric => - { - lyric.RubyTags = generator.Generate(lyric); - }); - } - - #endregion - protected override bool ContainsInLyric(Lyric lyric, RubyTag textTag) => lyric.RubyTags.Contains(textTag); diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs index 1d94fe5db..87dd4226b 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs @@ -5,8 +5,6 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics.Sprites; -using osu.Framework.Localisation; -using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.TimeTags; using osu.Game.Rulesets.Karaoke.Edit.Utils; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Utils; @@ -15,32 +13,6 @@ namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; public partial class LyricTimeTagsChangeHandler : LyricPropertyChangeHandler, ILyricTimeTagsChangeHandler { - #region Auto-Generate - - public bool CanGenerate() - { - var generator = GetSelector(); - return CanGenerate(generator); - } - - public IDictionary GetGeneratorNotSupportedLyrics() - { - var generator = GetSelector(); - return GetInvalidMessageFromGenerator(generator); - } - - public void AutoGenerate() - { - var generator = GetSelector(); - - PerformOnSelection(lyric => - { - lyric.TimeTags = generator.Generate(lyric); - }); - } - - #endregion - public void SetTimeTagTime(TimeTag timeTag, double time) { CheckExactlySelectedOneHitObject(); From 2b3b6dfb2cdacb50475030e5c01b63ade20c0b99 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 27 Sep 2023 21:08:29 +0800 Subject: [PATCH 3/4] Fix the api broken. --- .../Edit/Beatmaps/Lyrics/LyricEditorScreen.cs | 4 +++ .../LanguageAutoGenerateSubsection.cs | 7 +++++- .../LyricEditorAutoGenerateSubsection.cs | 25 ++++++++++++++----- .../Notes/NoteAutoGenerateSubsection.cs | 7 +++++- .../ReferenceLyricAutoGenerateSection.cs | 7 +++++- .../RomajiTagAutoGenerateSection.cs | 7 +++++- .../RubyRomaji/RubyTagAutoGenerateSection.cs | 7 +++++- .../RubyRomaji/TextTagAutoGenerateSection.cs | 8 ++++-- .../TimeTags/TimeTagAutoGenerateSection.cs | 7 +++++- .../AssignLanguageStepScreen.cs | 16 +++++------- .../GenerateRubyRomajiStepScreen.cs | 14 ++++------- 11 files changed, 76 insertions(+), 33 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorScreen.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorScreen.cs index e3ad67f7d..f03a305ab 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorScreen.cs @@ -21,6 +21,9 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics; public partial class LyricEditorScreen : BeatmapEditorScreen { + [Cached(typeof(ILyricPropertyAutoGenerateChangeHandler))] + private readonly LyricPropertyAutoGenerateChangeHandler lyricPropertyAutoGenerateChangeHandler; + [Cached(typeof(ILyricsChangeHandler))] private readonly LyricsChangeHandler lyricsChangeHandler; @@ -68,6 +71,7 @@ public partial class LyricEditorScreen : BeatmapEditorScreen public LyricEditorScreen() : base(KaraokeBeatmapEditorScreenMode.Lyric) { + AddInternal(lyricPropertyAutoGenerateChangeHandler = new LyricPropertyAutoGenerateChangeHandler()); AddInternal(lyricsChangeHandler = new LyricsChangeHandler()); AddInternal(lyricNotesChangeHandler = new LyricNotesChangeHandler()); AddInternal(lyricTextChangeHandler = new LyricTextChangeHandler()); diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Language/LanguageAutoGenerateSubsection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Language/LanguageAutoGenerateSubsection.cs index 3d476f13e..b5aef9127 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Language/LanguageAutoGenerateSubsection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Language/LanguageAutoGenerateSubsection.cs @@ -10,10 +10,15 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.Language; -public partial class LanguageAutoGenerateSubsection : LyricEditorAutoGenerateSubsection +public partial class LanguageAutoGenerateSubsection : LyricEditorAutoGenerateSubsection { private const string typing_mode = "TYPING_MODE"; + public LanguageAutoGenerateSubsection() + : base(AutoGenerateType.DetectLanguage) + { + } + protected override DescriptionFormat CreateInvalidDescriptionFormat() => new() { diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/LyricEditorAutoGenerateSubsection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/LyricEditorAutoGenerateSubsection.cs index 4da0cf98f..22c7eee24 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/LyricEditorAutoGenerateSubsection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/LyricEditorAutoGenerateSubsection.cs @@ -11,11 +11,17 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings; -public abstract partial class LyricEditorAutoGenerateSubsection : AutoGenerateSubsection - where TChangeHandler : class, ILyricPropertyAutoGenerateChangeHandler +public abstract partial class LyricEditorAutoGenerateSubsection : AutoGenerateSubsection { + private readonly AutoGenerateType autoGenerateType; + + protected LyricEditorAutoGenerateSubsection(AutoGenerateType generateType) + { + this.autoGenerateType = generateType; + } + protected override EditorSectionButton CreateGenerateButton() - => new AutoGenerateButton(); + => new AutoGenerateButton(autoGenerateType); protected sealed override DescriptionTextFlowContainer CreateDescriptionTextFlowContainer() => new LyricEditorDescriptionTextFlowContainer(); @@ -23,7 +29,14 @@ protected sealed override DescriptionTextFlowContainer CreateDescriptionTextFlow private partial class AutoGenerateButton : SelectLyricButton { [Resolved] - private TChangeHandler changeHandler { get; set; } = null!; + private ILyricPropertyAutoGenerateChangeHandler lyricPropertyAutoGenerateChangeHandler { get; set; } = null!; + + private readonly AutoGenerateType autoGenerateType; + + public AutoGenerateButton(AutoGenerateType generateType) + { + autoGenerateType = generateType; + } protected override LocalisableString StandardText => "Generate"; @@ -31,12 +44,12 @@ private partial class AutoGenerateButton : SelectLyricButton protected override IDictionary GetDisableSelectingLyrics() { - return changeHandler.GetGeneratorNotSupportedLyrics(); + return lyricPropertyAutoGenerateChangeHandler.GetGeneratorNotSupportedLyrics(autoGenerateType); } protected override void Apply() { - changeHandler.AutoGenerate(); + lyricPropertyAutoGenerateChangeHandler.AutoGenerate(autoGenerateType); } } } diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Notes/NoteAutoGenerateSubsection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Notes/NoteAutoGenerateSubsection.cs index 539beb61d..92b5796a5 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Notes/NoteAutoGenerateSubsection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Notes/NoteAutoGenerateSubsection.cs @@ -18,10 +18,15 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.Notes; /// But need to make sure that lyric should not have any /// If found any issue, will navigate to target lyric. /// -public partial class NoteAutoGenerateSubsection : LyricEditorAutoGenerateSubsection +public partial class NoteAutoGenerateSubsection : LyricEditorAutoGenerateSubsection { private const string create_time_tag_mode = "CREATE_TIME_TAG_MODE"; + public NoteAutoGenerateSubsection() + : base(AutoGenerateType.AutoGenerateNotes) + { + } + protected override DescriptionFormat CreateInvalidDescriptionFormat() => new() { diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Reference/ReferenceLyricAutoGenerateSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Reference/ReferenceLyricAutoGenerateSection.cs index c7fa14338..b91e381f4 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Reference/ReferenceLyricAutoGenerateSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/Reference/ReferenceLyricAutoGenerateSection.cs @@ -13,8 +13,13 @@ public partial class ReferenceLyricAutoGenerateSection : AutoGenerateSection protected override AutoGenerateSubsection CreateAutoGenerateSubsection() => new ReferenceLyricAutoGenerateSubsection(); - private partial class ReferenceLyricAutoGenerateSubsection : LyricEditorAutoGenerateSubsection + private partial class ReferenceLyricAutoGenerateSubsection : LyricEditorAutoGenerateSubsection { + public ReferenceLyricAutoGenerateSubsection() + : base(AutoGenerateType.DetectReferenceLyric) + { + } + protected override DescriptionFormat CreateInvalidDescriptionFormat() => new() { diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RomajiTagAutoGenerateSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RomajiTagAutoGenerateSection.cs index 420fb60a4..dd2c9ce68 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RomajiTagAutoGenerateSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RomajiTagAutoGenerateSection.cs @@ -13,8 +13,13 @@ public partial class RomajiTagAutoGenerateSection : TextTagAutoGenerateSection protected override AutoGenerateSubsection CreateAutoGenerateSubsection() => new RomajiTagAutoGenerateSubsection(); - private partial class RomajiTagAutoGenerateSubsection : TextTagAutoGenerateSubsection + private partial class RomajiTagAutoGenerateSubsection : TextTagAutoGenerateSubsection { + public RomajiTagAutoGenerateSubsection() + : base(AutoGenerateType.AutoGenerateRomajiTags) + { + } + protected override ConfigButton CreateConfigButton() => new RomajiTagAutoGenerateConfigButton(); diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RubyTagAutoGenerateSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RubyTagAutoGenerateSection.cs index f6e16ab51..3b73c7ebd 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RubyTagAutoGenerateSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RubyTagAutoGenerateSection.cs @@ -13,8 +13,13 @@ public partial class RubyTagAutoGenerateSection : TextTagAutoGenerateSection protected override AutoGenerateSubsection CreateAutoGenerateSubsection() => new RubyTagAutoGenerateSubsection(); - private partial class RubyTagAutoGenerateSubsection : TextTagAutoGenerateSubsection + private partial class RubyTagAutoGenerateSubsection : TextTagAutoGenerateSubsection { + public RubyTagAutoGenerateSubsection() + : base(AutoGenerateType.AutoGenerateRubyTags) + { + } + protected override ConfigButton CreateConfigButton() => new RubyTagAutoGenerateConfigButton(); diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagAutoGenerateSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagAutoGenerateSection.cs index 4e05aefc8..976c7a4d7 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagAutoGenerateSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagAutoGenerateSection.cs @@ -10,11 +10,15 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.RubyRo public abstract partial class TextTagAutoGenerateSection : AutoGenerateSection { - protected abstract partial class TextTagAutoGenerateSubsection : LyricEditorAutoGenerateSubsection - where TChangeHandler : class, ILyricPropertyAutoGenerateChangeHandler + protected abstract partial class TextTagAutoGenerateSubsection : LyricEditorAutoGenerateSubsection { private const string language_mode = "LANGUAGE_MODE"; + protected TextTagAutoGenerateSubsection(AutoGenerateType generateType) + : base(generateType) + { + } + protected override DescriptionFormat CreateInvalidDescriptionFormat() => new() { diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/TimeTags/TimeTagAutoGenerateSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/TimeTags/TimeTagAutoGenerateSection.cs index 2018b995d..3a3258e08 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/TimeTags/TimeTagAutoGenerateSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/TimeTags/TimeTagAutoGenerateSection.cs @@ -15,10 +15,15 @@ public partial class TimeTagAutoGenerateSection : AutoGenerateSection protected override AutoGenerateSubsection CreateAutoGenerateSubsection() => new TimeTageAutoGenerateSubsection(); - private partial class TimeTageAutoGenerateSubsection : LyricEditorAutoGenerateSubsection + private partial class TimeTageAutoGenerateSubsection : LyricEditorAutoGenerateSubsection { private const string language_mode = "LANGUAGE_MODE"; + public TimeTageAutoGenerateSubsection() + : base(AutoGenerateType.AutoGenerateTimeTags) + { + } + protected override DescriptionFormat CreateInvalidDescriptionFormat() => new() { diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/AssignLanguage/AssignLanguageStepScreen.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/AssignLanguage/AssignLanguageStepScreen.cs index 38af1a571..7583293a9 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/AssignLanguage/AssignLanguageStepScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/AssignLanguage/AssignLanguageStepScreen.cs @@ -19,20 +19,16 @@ public partial class AssignLanguageStepScreen : LyricImporterStepScreenWithLyric public override IconUsage Icon => FontAwesome.Solid.Globe; + [Cached(typeof(ILyricPropertyAutoGenerateChangeHandler))] + private readonly LyricPropertyAutoGenerateChangeHandler lyricPropertyAutoGenerateChangeHandler; + [Cached(typeof(ILyricLanguageChangeHandler))] private readonly LyricLanguageChangeHandler lyricLanguageChangeHandler; - [Cached(typeof(ILyricRubyTagsChangeHandler))] - private readonly LyricRubyTagsChangeHandler lyricRubyTagsChangeHandler; - - [Cached(typeof(ILyricRomajiTagsChangeHandler))] - private readonly LyricRomajiTagsChangeHandler lyricRomajiTagsChangeHandler; - public AssignLanguageStepScreen() { + AddInternal(lyricPropertyAutoGenerateChangeHandler = new LyricPropertyAutoGenerateChangeHandler()); AddInternal(lyricLanguageChangeHandler = new LyricLanguageChangeHandler()); - AddInternal(lyricRubyTagsChangeHandler = new LyricRubyTagsChangeHandler()); - AddInternal(lyricRomajiTagsChangeHandler = new LyricRomajiTagsChangeHandler()); } protected override TopNavigation CreateNavigation() @@ -53,8 +49,8 @@ protected override void LoadComplete() public override void Complete() { // Check is need to go to generate ruby/romaji step or just skip. - if (lyricRubyTagsChangeHandler.CanGenerate() - || lyricRomajiTagsChangeHandler.CanGenerate()) + if (lyricPropertyAutoGenerateChangeHandler.CanGenerate(AutoGenerateType.AutoGenerateRubyTags) + || lyricPropertyAutoGenerateChangeHandler.CanGenerate(AutoGenerateType.AutoGenerateRomajiTags)) { ScreenStack.Push(LyricImporterStep.GenerateRuby); } diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/GenerateRubyRomaji/GenerateRubyRomajiStepScreen.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/GenerateRubyRomaji/GenerateRubyRomajiStepScreen.cs index df375556f..e400ce8a6 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/GenerateRubyRomaji/GenerateRubyRomajiStepScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Import/Lyrics/GenerateRubyRomaji/GenerateRubyRomajiStepScreen.cs @@ -19,16 +19,12 @@ public partial class GenerateRubyRomajiStepScreen : LyricImporterStepScreenWithL public override IconUsage Icon => FontAwesome.Solid.Gem; - [Cached(typeof(ILyricRubyTagsChangeHandler))] - private readonly LyricRubyTagsChangeHandler lyricRubyTagsChangeHandler; - - [Cached(typeof(ILyricRomajiTagsChangeHandler))] - private readonly LyricRomajiTagsChangeHandler lyricRomajiTagsChangeHandler; + [Cached(typeof(ILyricPropertyAutoGenerateChangeHandler))] + private readonly LyricPropertyAutoGenerateChangeHandler lyricPropertyAutoGenerateChangeHandler; public GenerateRubyRomajiStepScreen() { - AddInternal(lyricRubyTagsChangeHandler = new LyricRubyTagsChangeHandler()); - AddInternal(lyricRomajiTagsChangeHandler = new LyricRomajiTagsChangeHandler()); + AddInternal(lyricPropertyAutoGenerateChangeHandler = new LyricPropertyAutoGenerateChangeHandler()); } protected override TopNavigation CreateNavigation() @@ -45,9 +41,9 @@ protected override void LoadComplete() base.LoadComplete(); // Asking auto-generate ruby or romaji. - if (lyricRubyTagsChangeHandler.CanGenerate()) + if (lyricPropertyAutoGenerateChangeHandler.CanGenerate(AutoGenerateType.AutoGenerateRubyTags)) AskForAutoGenerateRuby(); - else if (lyricRomajiTagsChangeHandler.CanGenerate()) + else if (lyricPropertyAutoGenerateChangeHandler.CanGenerate(AutoGenerateType.AutoGenerateRomajiTags)) AskForAutoGenerateRomaji(); } From 6f1ded249a49d484deb0565f8f0c7246b24d5cbd Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 27 Sep 2023 21:27:03 +0800 Subject: [PATCH 4/4] Remove un-need change handler. --- .../Lyrics/LyricNotesChangeHandlerTest.cs | 10 ---------- .../Lyrics/ILyricNotesChangeHandler.cs | 8 -------- .../Lyrics/LyricNotesChangeHandler.cs | 13 ------------- .../Edit/Beatmaps/Lyrics/LyricEditorScreen.cs | 4 ---- 4 files changed, 35 deletions(-) delete mode 100644 osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricNotesChangeHandlerTest.cs delete mode 100644 osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricNotesChangeHandler.cs delete mode 100644 osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricNotesChangeHandler.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricNotesChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricNotesChangeHandlerTest.cs deleted file mode 100644 index d516f2a59..000000000 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricNotesChangeHandlerTest.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; - -namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics; - -public partial class LyricNotesChangeHandlerTest : LyricPropertyChangeHandlerTest -{ -} diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricNotesChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricNotesChangeHandler.cs deleted file mode 100644 index 40c09c314..000000000 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricNotesChangeHandler.cs +++ /dev/null @@ -1,8 +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.ChangeHandlers.Lyrics; - -public interface ILyricNotesChangeHandler : ILyricPropertyChangeHandler -{ -} diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricNotesChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricNotesChangeHandler.cs deleted file mode 100644 index 551410cce..000000000 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricNotesChangeHandler.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) andy840119 . Licensed under the GPL Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Game.Rulesets.Karaoke.Edit.Utils; -using osu.Game.Rulesets.Karaoke.Objects; - -namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; - -public partial class LyricNotesChangeHandler : LyricPropertyChangeHandler, ILyricNotesChangeHandler -{ - protected override bool IsWritePropertyLocked(Lyric lyric) - => HitObjectWritableUtils.IsCreateOrRemoveNoteLocked(lyric); -} diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorScreen.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorScreen.cs index f03a305ab..679b5716b 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/LyricEditorScreen.cs @@ -27,9 +27,6 @@ public partial class LyricEditorScreen : BeatmapEditorScreen [Cached(typeof(ILyricsChangeHandler))] private readonly LyricsChangeHandler lyricsChangeHandler; - [Cached(typeof(ILyricNotesChangeHandler))] - private readonly LyricNotesChangeHandler lyricNotesChangeHandler; - [Cached(typeof(ILyricTextChangeHandler))] private readonly LyricTextChangeHandler lyricTextChangeHandler; @@ -73,7 +70,6 @@ public LyricEditorScreen() { AddInternal(lyricPropertyAutoGenerateChangeHandler = new LyricPropertyAutoGenerateChangeHandler()); AddInternal(lyricsChangeHandler = new LyricsChangeHandler()); - AddInternal(lyricNotesChangeHandler = new LyricNotesChangeHandler()); AddInternal(lyricTextChangeHandler = new LyricTextChangeHandler()); AddInternal(lyricReferenceChangeHandler = new LyricReferenceChangeHandler()); AddInternal(lyricLanguageChangeHandler = new LyricLanguageChangeHandler());