Skip to content

Commit

Permalink
It's time to collect all generators into same change handler.
Browse files Browse the repository at this point in the history
means revert the change in the karaoke-dev#1958.
  • Loading branch information
andy840119 committed Sep 26, 2023
1 parent 3d519c8 commit aed896d
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;

public interface ILyricNotesChangeHandler : ILyricPropertyChangeHandler, ILyricPropertyAutoGenerateChangeHandler
public interface ILyricNotesChangeHandler : ILyricPropertyChangeHandler
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@

namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;

public interface ILyricPropertyAutoGenerateChangeHandler : IAutoGenerateChangeHandler
public interface ILyricPropertyAutoGenerateChangeHandler : ILyricPropertyChangeHandler, IEnumAutoGenerateChangeHandler<AutoGenerateType>
{
IDictionary<Lyric, LocalisableString> GetGeneratorNotSupportedLyrics();
IDictionary<Lyric, LocalisableString> GetGeneratorNotSupportedLyrics(AutoGenerateType type);
}

public enum AutoGenerateType
{
DetectReferenceLyric,

DetectLanguage,

AutoGenerateRubyTags,

AutoGenerateRomajiTags,

AutoGenerateTimeTags,

AutoGenerateNotes,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;

public interface ILyricRomajiTagsChangeHandler : ILyricTextTagsChangeHandler<RomajiTag>, ILyricPropertyAutoGenerateChangeHandler
public interface ILyricRomajiTagsChangeHandler : ILyricTextTagsChangeHandler<RomajiTag>
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,13 @@

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;

namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics;

public partial class LyricLanguageChangeHandler : LyricPropertyChangeHandler, ILyricLanguageChangeHandler
{
#region Auto-Generate

public bool CanGenerate()
{
var detector = GetDetector<CultureInfo, LanguageDetectorConfig>();
return CanDetect(detector);
}

public IDictionary<Lyric, LocalisableString> GetGeneratorNotSupportedLyrics()
{
var detector = GetDetector<CultureInfo, LanguageDetectorConfig>();
return GetInvalidMessageFromDetector(detector);
}

public void AutoGenerate()
{
var detector = GetDetector<CultureInfo, LanguageDetectorConfig>();

PerformOnSelection(lyric =>
{
var detectedLanguage = detector.Detect(lyric);
lyric.Language = detectedLanguage;
});
}

#endregion

public void SetLanguage(CultureInfo? language)
{
PerformOnSelection(lyric =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,13 @@
// Copyright (c) andy840119 <[email protected]>. 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<Note[], NoteGeneratorConfig>();
return CanGenerate(generator);
}

public IDictionary<Lyric, LocalisableString> GetGeneratorNotSupportedLyrics()
{
var generator = GetGenerator<Note[], NoteGeneratorConfig>();
return GetInvalidMessageFromGenerator(generator);
}

public void AutoGenerate()
{
var generator = GetGenerator<Note[], NoteGeneratorConfig>();

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);
}
Loading

0 comments on commit aed896d

Please sign in to comment.