Skip to content

Commit

Permalink
Add method for able to change time-tag romaji text and the initial st…
Browse files Browse the repository at this point in the history
…ate in the change handler.
  • Loading branch information
andy840119 committed Jul 23, 2023
1 parent 66db91a commit 51119d6
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public interface ILyricTimeTagsChangeHandler : ILyricListPropertyChangeHandler<T
{
void SetTimeTagTime(TimeTag timeTag, double time);

void SetTimeTagInitialRomaji(TimeTag timeTag, bool initialRomaji);

void SetTimeTagRomajiText(TimeTag timeTag, string romaji);

void ShiftingTimeTagTime(IEnumerable<TimeTag> timeTags, double offset);

void ClearTimeTagTime(TimeTag timeTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimeTag> timeTags, double offset)
{
CheckExactlySelectedOneHitObject();
Expand Down

0 comments on commit 51119d6

Please sign in to comment.