Skip to content

Commit

Permalink
Apply new generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Sep 27, 2023
1 parent 4af67c9 commit 825847a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void TestAutoGenerateRomajiTagsWithNonSupportedLyric()

#endregion

#region TimeTag
#region Time-tag

[Test]
public void TestAutoGenerateTimeTags()
Expand Down Expand Up @@ -241,6 +241,44 @@ public void TestAutoGenerateTimeTagsWithNonSupportedLyric()

#endregion

#region Time-tag romaji

[Test]
public void TestAutoGenerateTimeTagRomaji()
{
PrepareHitObject(() => new Lyric
{
Text = "カラオケ",
Language = new CultureInfo(17),
TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { "[0,start]", "[3,end]" }),
});

TriggerHandlerChanged(c => c.AutoGenerate(AutoGenerateType.AutoGenerateTimeTagRomaji));

AssertSelectedHitObject(h =>
{
Assert.AreEqual("karaoke", h.TimeTags[0].RomajiText);
});
}

[Test]
public void TestAutoGenerateTimeTagRomajiWithNonSupportedLyric()
{
PrepareHitObjects(() => new[]
{
new Lyric
{
Text = "カラオケ",
Language = new CultureInfo(17),
// with no time-tag.
},
});

TriggerHandlerChangedWithException<GeneratorNotSupportedException>(c => c.AutoGenerate(AutoGenerateType.AutoGenerateTimeTagRomaji));
}

#endregion

#region Note

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ public enum AutoGenerateType

AutoGenerateTimeTags,

AutoGenerateTimeTagRomaji,

AutoGenerateNotes,
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Language;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Notes;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.ReferenceLyric;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Romajies;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.RomajiTags;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.RubyTags;
using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.TimeTags;
Expand Down Expand Up @@ -58,6 +59,10 @@ public bool CanGenerate(AutoGenerateType type)
var timeTagGenerator = getSelector<TimeTag[], TimeTagGeneratorConfig>();
return canGenerate(timeTagGenerator);

case AutoGenerateType.AutoGenerateTimeTagRomaji:
var timeTagRomajiGenerator = getSelector<IReadOnlyDictionary<TimeTag, RomajiGenerateResult>, RomajiGeneratorConfig>();
return canGenerate(timeTagRomajiGenerator);

case AutoGenerateType.AutoGenerateNotes:
var noteGenerator = getGenerator<Note[], NoteGeneratorConfig>();
return canGenerate(noteGenerator);
Expand Down Expand Up @@ -99,6 +104,10 @@ public IDictionary<Lyric, LocalisableString> GetGeneratorNotSupportedLyrics(Auto
var timeTagGenerator = getSelector<TimeTag[], TimeTagGeneratorConfig>();
return getInvalidMessageFromGenerator(timeTagGenerator);

case AutoGenerateType.AutoGenerateTimeTagRomaji:
var timeTagRomajiGenerator = getSelector<IReadOnlyDictionary<TimeTag, RomajiGenerateResult>, RomajiGeneratorConfig>();
return getInvalidMessageFromGenerator(timeTagRomajiGenerator);

case AutoGenerateType.AutoGenerateNotes:
var noteGenerator = getGenerator<Note[], NoteGeneratorConfig>();
return getInvalidMessageFromGenerator(noteGenerator);
Expand Down Expand Up @@ -178,6 +187,21 @@ public void AutoGenerate(AutoGenerateType type)
});
break;

case AutoGenerateType.AutoGenerateTimeTagRomaji:
var timeTagRomajiGenerator = getSelector<IReadOnlyDictionary<TimeTag, RomajiGenerateResult>, RomajiGeneratorConfig>();
PerformOnSelection(lyric =>
{
var results = timeTagRomajiGenerator.Generate(lyric);

foreach (var (key, value) in results)
{
var matchedTimeTag = lyric.TimeTags.Single(x => x == key);
matchedTimeTag.InitialRomaji = value.InitialRomaji;
matchedTimeTag.RomajiText = value.RomajiText;
}
});
break;

case AutoGenerateType.AutoGenerateNotes:
var noteGenerator = getGenerator<Note[], NoteGeneratorConfig>();
PerformOnSelection(lyric =>
Expand Down Expand Up @@ -207,6 +231,7 @@ protected override bool IsWritePropertyLocked(Lyric lyric) =>
AutoGenerateType.AutoGenerateRubyTags => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.RubyTags)),
AutoGenerateType.AutoGenerateRomajiTags => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.RomajiTags)),
AutoGenerateType.AutoGenerateTimeTags => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.TimeTags)),
AutoGenerateType.AutoGenerateTimeTagRomaji => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.TimeTags)),
AutoGenerateType.AutoGenerateNotes => HitObjectWritableUtils.IsCreateOrRemoveNoteLocked(lyric),
_ => throw new ArgumentOutOfRangeException(),
};
Expand Down

0 comments on commit 825847a

Please sign in to comment.