Skip to content

Commit

Permalink
Rename the romanization-related property name in the time-tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Jan 16, 2024
1 parent 620ecc7 commit b84e915
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void TestAutoGenerateTimeTagRomaji()

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void TestSetTimeTagInitialRomaji()

AssertSelectedHitObject(_ =>
{
Assert.AreEqual(true, timeTag.InitialRomaji);
Assert.AreEqual(true, timeTag.FirstSyllable);
});
}

Expand All @@ -75,14 +75,14 @@ public void TestSetTimeTagRomajiText()

AssertSelectedHitObject(_ =>
{
Assert.AreEqual("karaoke", timeTag.RomajiText);
Assert.AreEqual("karaoke", timeTag.RomanizedSyllable);
});

TriggerHandlerChanged(c => c.SetTimeTagRomajiText(timeTag, " "));

AssertSelectedHitObject(_ =>
{
Assert.AreEqual(string.Empty, timeTag.RomajiText);
Assert.AreEqual(string.Empty, timeTag.RomanizedSyllable);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void TestCheckEmptyTime(string text, string[] timeTags)
[TestCase("カラオケ", "")] // should not be empty.
[TestCase("カラオケ", " ")] // should not be white-space only.
[TestCase("カラオケ", "卡拉OK")] // should be within latin.
public void TestCheckTimeTagRomajiInvalidText(string text, string romajiText)
public void TestCheckTimeTagRomajiInvalidText(string text, string romanizedSyllable)
{
var lyric = new Lyric
{
Expand All @@ -114,7 +114,7 @@ public void TestCheckTimeTagRomajiInvalidText(string text, string romajiText)
{
new TimeTag(new TextIndex())
{
RomajiText = romajiText,
RomanizedSyllable = romanizedSyllable,
Time = 1000,
},
new TimeTag(new TextIndex(3, TextIndex.IndexState.End))
Expand All @@ -128,7 +128,7 @@ public void TestCheckTimeTagRomajiInvalidText(string text, string romajiText)
}

[TestCase("カラオケ", null)] // should not be white-space only.
public void TestCheckRomajiEmptyTextIfFirst(string text, string romajiText)
public void TestCheckRomajiEmptyTextIfFirst(string text, string romanizedSyllable)
{
var lyric = new Lyric
{
Expand All @@ -137,8 +137,8 @@ public void TestCheckRomajiEmptyTextIfFirst(string text, string romajiText)
{
new TimeTag(new TextIndex())
{
RomajiText = romajiText,
InitialRomaji = true,
RomanizedSyllable = romanizedSyllable,
FirstSyllable = true,
Time = 1000,
},
new TimeTag(new TextIndex(3, TextIndex.IndexState.End))
Expand All @@ -154,7 +154,7 @@ public void TestCheckRomajiEmptyTextIfFirst(string text, string romajiText)
[TestCase("カラオケ", "")] // should not have empty text if end.
[TestCase("カラオケ", " ")] // should not have empty text if end.
[TestCase("カラオケ", "123")] // should not have empty text if end.
public void TestRomajiNotHaveEmptyTextIfEnd(string text, string romajiText)
public void TestRomajiNotHaveEmptyTextIfEnd(string text, string romanizedSyllable)
{
var lyric = new Lyric
{
Expand All @@ -167,7 +167,7 @@ public void TestRomajiNotHaveEmptyTextIfEnd(string text, string romajiText)
},
new TimeTag(new TextIndex(3, TextIndex.IndexState.End))
{
RomajiText = romajiText,
RomanizedSyllable = romanizedSyllable,
Time = 2000,
},
},
Expand All @@ -190,7 +190,7 @@ public void TestRomajiNotFistRomajiTextIfEnd()
},
new TimeTag(new TextIndex(3, TextIndex.IndexState.End))
{
InitialRomaji = true, // is invalid.
FirstSyllable = true, // is invalid.
Time = 2000,
},
},
Expand Down
12 changes: 6 additions & 6 deletions osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ public static RomajiTag ParseRomajiTag(string? str)
/// [0,start]:1000 -> has time-tag index with time.<br/>
/// [0,start] -> has time-tag index with no time.<br/>
/// [0,start]: -> has time-tag index with no time.<br/>
/// [0,start]#karaoke -> has time-tag index with romaji.<br/>
/// [0,start]#^karaoke -> has time-tag index with romaji, and it's initial romaji.<br/>
/// [0,start]:1000#karaoke -> has time-tag index with time and romaji.<br/>
/// [0,start]#karaoke -> has time-tag index with romanized syllable.<br/>
/// [0,start]#^karaoke -> has time-tag index with romanized syllable, and it's the first one.<br/>
/// [0,start]:1000#karaoke -> has time-tag index with time and romanized syllable.<br/>
/// </example>
/// <param name="str">Time tag string format</param>
/// <returns><see cref="TimeTag"/>Time tag object</returns>
Expand All @@ -152,12 +152,12 @@ public static TimeTag ParseTimeTag(string? str)
var state = result.GetGroupValue<string>("state") == "start" ? TextIndex.IndexState.Start : TextIndex.IndexState.End;
int? time = result.GetGroupValue<int?>("time");
string? text = result.GetGroupValue<string?>("text");
bool? initialRomaji = text?.StartsWith("^");
bool? firstSyllable = text?.StartsWith("^");

return new TimeTag(new TextIndex(index, state), time)
{
RomajiText = text?.Replace("^", ""),
InitialRomaji = initialRomaji ?? default,
FirstSyllable = firstSyllable ?? default,
RomanizedSyllable = text?.Replace("^", ""),
};
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ public void AutoGenerate(AutoGenerateType type)
foreach (var (key, value) in results)
{
var matchedTimeTag = lyric.TimeTags.Single(x => x == key);
matchedTimeTag.InitialRomaji = value.InitialRomaji;
matchedTimeTag.RomajiText = value.RomajiText;
matchedTimeTag.FirstSyllable = value.InitialRomaji;
matchedTimeTag.RomanizedSyllable = value.RomajiText;
}
});
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void SetTimeTagInitialRomaji(TimeTag timeTag, bool initialRomaji)
if (!containsInLyric)
throw new InvalidOperationException($"{nameof(timeTag)} is not in the lyric");

timeTag.InitialRomaji = initialRomaji;
timeTag.FirstSyllable = initialRomaji;
});
}

Expand All @@ -51,13 +51,13 @@ public void SetTimeTagRomajiText(TimeTag timeTag, string romaji)
if (!containsInLyric)
throw new InvalidOperationException($"{nameof(timeTag)} is not in the lyric");

timeTag.RomajiText = romaji;
timeTag.RomanizedSyllable = romaji;

if (!string.IsNullOrWhiteSpace(romaji))
return;

timeTag.RomajiText = string.Empty;
timeTag.InitialRomaji = false;
timeTag.RomanizedSyllable = string.Empty;
timeTag.FirstSyllable = false;
});
}

Expand Down
22 changes: 11 additions & 11 deletions osu.Game.Rulesets.Karaoke/Edit/Checks/CheckLyricTimeTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override IEnumerable<Issue> Check(Lyric lyric)
{
var issues = new List<Issue>();
issues.AddRange(CheckTimeTag(lyric));
issues.AddRange(CheckTimeTagRomaji(lyric));
issues.AddRange(CheckTimeTagRomanizedSyllable(lyric));
return issues;
}

Expand Down Expand Up @@ -78,7 +78,7 @@ protected IEnumerable<Issue> CheckTimeTag(Lyric lyric)
}
}

protected IEnumerable<Issue> CheckTimeTagRomaji(Lyric lyric)
protected IEnumerable<Issue> CheckTimeTagRomanizedSyllable(Lyric lyric)
{
if (!lyric.TimeTags.Any())
{
Expand All @@ -87,27 +87,27 @@ protected IEnumerable<Issue> CheckTimeTagRomaji(Lyric lyric)

foreach (var timeTag in lyric.TimeTags)
{
bool initialRomaji = timeTag.InitialRomaji;
string? romajiText = timeTag.RomajiText;
bool firstSyllable = timeTag.FirstSyllable;
string? romanizedSyllable = timeTag.RomanizedSyllable;

switch (timeTag.Index.State)
{
case TextIndex.IndexState.Start:
// if input the romaji text, should be valid.
if (romajiText != null && !isRomajiTextValid(romajiText))
// if input the romanized syllable, should be valid.
if (romanizedSyllable != null && !isRomanizedSyllableValid(romanizedSyllable))
yield return new IssueTemplateLyricTimeTagRomajiInvalidText(this).Create(lyric, timeTag);

// if is first romaji text, should not be null.
if (initialRomaji && romajiText == null)
// if is first romanized syllable, should not be null.
if (firstSyllable && romanizedSyllable == null)
yield return new IssueTemplateLyricTimeTagRomajiInvalidTextIfFirst(this).Create(lyric, timeTag);

break;

case TextIndex.IndexState.End:
if (romajiText != null)
if (romanizedSyllable != null)
yield return new IssueTemplateLyricTimeTagRomajiNotHaveEmptyTextIfEnd(this).Create(lyric, timeTag);

if (initialRomaji)
if (firstSyllable)
yield return new IssueTemplateLyricTimeTagRomajiNotFistRomajiTextIfEnd(this).Create(lyric, timeTag);

break;
Expand All @@ -119,7 +119,7 @@ protected IEnumerable<Issue> CheckTimeTagRomaji(Lyric lyric)

yield break;

static bool isRomajiTextValid(string text)
static bool isRomanizedSyllableValid(string text)
{
// should not be white-space only.
if (string.IsNullOrWhiteSpace(text))
Expand Down
4 changes: 2 additions & 2 deletions osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void initInternalBindingEvent()
foreach (var c in args.NewItems.Cast<TimeTag>())
{
c.TimingChanged += timingInvalidate;
c.RomajiChanged += romajiInvalidate;
c.SyllableChanged += romajiInvalidate;
}

break;
Expand All @@ -73,7 +73,7 @@ private void initInternalBindingEvent()
foreach (var c in args.OldItems.Cast<TimeTag>())
{
c.TimingChanged -= timingInvalidate;
c.RomajiChanged -= romajiInvalidate;
c.SyllableChanged -= romajiInvalidate;
}

break;
Expand Down
25 changes: 13 additions & 12 deletions osu.Game.Rulesets.Karaoke/Objects/TimeTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ public class TimeTag : IDeepCloneable<TimeTag>
public event Action? TimingChanged;

/// <summary>
/// Invoked when <see cref="InitialRomaji"/> or <see cref="RomajiText"/> of this <see cref="TimeTag"/> is changed.
/// Invoked when <see cref="FirstSyllable"/> or <see cref="RomanizedSyllable"/> of this <see cref="TimeTag"/> is changed.
/// </summary>
public event Action? RomajiChanged;
public event Action? SyllableChanged;

public TimeTag(TextIndex index, double? time = null)
{
Index = index;
Time = time;

TimeBindable.ValueChanged += _ => TimingChanged?.Invoke();
InitialRomajiBindable.ValueChanged += _ => RomajiChanged?.Invoke();
RomajiTextBindable.ValueChanged += _ => RomajiChanged?.Invoke();
FirstSyllableBindable.ValueChanged += _ => SyllableChanged?.Invoke();
RomanizedSyllableBindable.ValueChanged += _ => SyllableChanged?.Invoke();
}

/// <summary>
Expand All @@ -50,7 +50,7 @@ public double? Time
}

[JsonIgnore]
public readonly Bindable<bool> InitialRomajiBindable = new();
public readonly Bindable<bool> FirstSyllableBindable = new();

/// <summary>
/// Mark if this romaji is the first letter of the romaji word.
Expand All @@ -65,22 +65,23 @@ public double? Time
/// If this is the first or(4th) time-tag, then this value should be true.<br/>
/// If this ts the 2th or 3th time-tag, then this value should be false.<br/>
/// </example>
public bool InitialRomaji
public bool FirstSyllable
{
get => InitialRomajiBindable.Value;
set => InitialRomajiBindable.Value = value;
get => FirstSyllableBindable.Value;
set => FirstSyllableBindable.Value = value;
}

[JsonIgnore]
public readonly Bindable<string?> RomajiTextBindable = new();
public readonly Bindable<string?> RomanizedSyllableBindable = new();

/// <summary>
/// Romaji
/// </summary>
public string? RomajiText
public string? RomanizedSyllable
{
get => RomajiTextBindable.Value;
set => RomajiTextBindable.Value = value;
// todo: rename
get => RomanizedSyllableBindable.Value;
set => RomanizedSyllableBindable.Value = value;
}

public TimeTag DeepClone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,6 @@ public class CheckLyricTimeTagRomaji : CheckLyricTimeTag
{
protected override IEnumerable<Issue> Check(Lyric lyric)
{
return CheckTimeTagRomaji(lyric);
return CheckTimeTagRomanizedSyllable(lyric);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected override Drawable CreateDrawable(TimeTag item)
},
RomajiEditPropertyMode.Initial => new LabelledInitialSwitchButton(item)
{
Label = item.RomajiText ?? string.Empty,
Label = item.RomanizedSyllable ?? string.Empty,
},
_ => throw new ArgumentOutOfRangeException(nameof(bindableRomajiEditPropertyMode.Value)),
};
Expand Down Expand Up @@ -98,7 +98,7 @@ protected override void TriggerSelect(TimeTag item)
=> editRomajiModeState.Select(item);

protected override string GetFieldValue(TimeTag timeTag)
=> timeTag.RomajiText ?? string.Empty;
=> timeTag.RomanizedSyllable ?? string.Empty;

protected override void ApplyValue(TimeTag timeTag, string value)
=> lyricTimeTagsChangeHandler.SetTimeTagRomajiText(timeTag, value);
Expand All @@ -121,7 +121,7 @@ public LabelledInitialSwitchButton(TimeTag item)
}

protected override bool GetFieldValue(TimeTag timeTag)
=> timeTag.InitialRomaji;
=> timeTag.FirstSyllable;

protected override void ApplyValue(TimeTag timeTag, bool value)
=> lyricTimeTagsChangeHandler.SetTimeTagInitialRomaji(timeTag, value);
Expand Down

0 comments on commit b84e915

Please sign in to comment.