From aed896dd30d9815ad631b90136c6dddbf81d8096 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Wed, 27 Sep 2023 00:22:45 +0800 Subject: [PATCH] It's time to collect all generators into same change handler. means revert the change in the #1958. --- .../Lyrics/ILyricLanguageChangeHandler.cs | 2 +- .../Lyrics/ILyricNotesChangeHandler.cs | 2 +- ...ILyricPropertyAutoGenerateChangeHandler.cs | 19 +- .../Lyrics/ILyricReferenceChangeHandler.cs | 2 +- .../Lyrics/ILyricRomajiTagsChangeHandler.cs | 2 +- .../Lyrics/LyricLanguageChangeHandler.cs | 29 -- .../Lyrics/LyricNotesChangeHandler.cs | 39 --- .../LyricPropertyAutoGenerateChangeHandler.cs | 273 ++++++++++++++++++ .../Lyrics/LyricPropertyChangeHandler.cs | 91 ------ .../Lyrics/LyricReferenceChangeHandler.cs | 33 --- .../Lyrics/LyricRomajiTagsChangeHandler.cs | 29 -- 11 files changed, 294 insertions(+), 227 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs 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/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..67d96528e --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricPropertyAutoGenerateChangeHandler.cs @@ -0,0 +1,273 @@ +// 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.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 : HitObjectPropertyChangeHandler, 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 = createLyricGenerator(); + return canGenerate(rubyGenerator); + + case AutoGenerateType.AutoGenerateRomajiTags: + var romajiGenerator = getSelector(); + return canGenerate(romajiGenerator); + + case AutoGenerateType.AutoGenerateTimeTags: + var timeTagGenerator = createLyricGenerator(); + 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 = createLyricGenerator(); + return getInvalidMessageFromGenerator(rubyGenerator); + + case AutoGenerateType.AutoGenerateRomajiTags: + var romajiGenerator = getSelector(); + return getInvalidMessageFromGenerator(romajiGenerator); + + case AutoGenerateType.AutoGenerateTimeTags: + var timeTagGenerator = createLyricGenerator(); + 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 = createLyricGenerator(); + 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 = createLyricGenerator(); + 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..0856eccfc 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricReferenceChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricReferenceChangeHandler.cs @@ -14,39 +14,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);