From 51119d6cd9cc394a9b20121ec68bb64b8e42fe4d Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 23 Jul 2023 20:21:28 +0800 Subject: [PATCH] Add method for able to change time-tag romaji text and the initial state in the change handler. --- .../Lyrics/LyricTimeTagsChangeHandlerTest.cs | 49 +++++++++++++++++++ .../Lyrics/ILyricTimeTagsChangeHandler.cs | 4 ++ .../Lyrics/LyricTimeTagsChangeHandler.cs | 34 +++++++++++++ 3 files changed, 87 insertions(+) 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 6851ad90f..93039f9a9 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandlerTest.cs @@ -84,6 +84,55 @@ public void TestSetTimeTagTime() }); } + [Test] + public void TestSetTimeTagInitialRomaji() + { + var timeTag = new TimeTag(new TextIndex(), 1000); + PrepareHitObject(() => new Lyric + { + Text = "カラオケ", + TimeTags = new[] + { + timeTag, + }, + }); + + TriggerHandlerChanged(c => c.SetTimeTagInitialRomaji(timeTag, true)); + + AssertSelectedHitObject(_ => + { + Assert.AreEqual(true, timeTag.InitialRomaji); + }); + } + + [Test] + public void TestSetTimeTagRomajiText() + { + var timeTag = new TimeTag(new TextIndex(), 1000); + PrepareHitObject(() => new Lyric + { + Text = "カラオケ", + TimeTags = new[] + { + timeTag, + }, + }); + + TriggerHandlerChanged(c => c.SetTimeTagRomajiText(timeTag, "karaoke")); + + AssertSelectedHitObject(_ => + { + Assert.AreEqual("karaoke", timeTag.RomajiText); + }); + + TriggerHandlerChanged(c => c.SetTimeTagRomajiText(timeTag, " ")); + + AssertSelectedHitObject(_ => + { + Assert.AreEqual(string.Empty, timeTag.RomajiText); + }); + } + [Test] public void TestShiftingTimeTagTime() { diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs index 93ab896ba..2cc9e92e9 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricTimeTagsChangeHandler.cs @@ -11,6 +11,10 @@ public interface ILyricTimeTagsChangeHandler : ILyricListPropertyChangeHandler timeTags, double offset); void ClearTimeTagTime(TimeTag timeTag); diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs index eed1b9d8b..1d94fe5db 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricTimeTagsChangeHandler.cs @@ -55,6 +55,40 @@ public void SetTimeTagTime(TimeTag timeTag, double time) }); } + public void SetTimeTagInitialRomaji(TimeTag timeTag, bool initialRomaji) + { + CheckExactlySelectedOneHitObject(); + + PerformOnSelection(lyric => + { + bool containsInLyric = lyric.TimeTags.Contains(timeTag); + if (!containsInLyric) + throw new InvalidOperationException($"{nameof(timeTag)} is not in the lyric"); + + timeTag.InitialRomaji = initialRomaji; + }); + } + + public void SetTimeTagRomajiText(TimeTag timeTag, string romaji) + { + CheckExactlySelectedOneHitObject(); + + PerformOnSelection(lyric => + { + bool containsInLyric = lyric.TimeTags.Contains(timeTag); + if (!containsInLyric) + throw new InvalidOperationException($"{nameof(timeTag)} is not in the lyric"); + + timeTag.RomajiText = romaji; + + if (!string.IsNullOrWhiteSpace(romaji)) + return; + + timeTag.RomajiText = string.Empty; + timeTag.InitialRomaji = false; + }); + } + public void ShiftingTimeTagTime(IEnumerable timeTags, double offset) { CheckExactlySelectedOneHitObject();