Skip to content

Commit

Permalink
Should have time-tags romaji version in the lyric.
Browse files Browse the repository at this point in the history
Also, rename from `TimeTagsVersion` into `TimeTagsTimingVersion`.
  • Loading branch information
andy840119 committed Jul 16, 2023
1 parent 1ca70d1 commit 51859f5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 23 deletions.
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Karaoke.Tests/Objects/LyricTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void TestClone()
Assert.AreNotSame(clonedLyric.TextBindable, lyric.TextBindable);
Assert.AreEqual(clonedLyric.Text, lyric.Text);

Assert.AreNotSame(clonedLyric.TimeTagsVersion, lyric.TimeTagsVersion);
Assert.AreNotSame(clonedLyric.TimeTagsTimingVersion, lyric.TimeTagsTimingVersion);
Assert.AreNotSame(clonedLyric.TimeTagsBindable, lyric.TimeTagsBindable);
TimeTagAssert.ArePropertyEqual(clonedLyric.TimeTags, lyric.TimeTags);

Expand Down Expand Up @@ -202,7 +202,7 @@ public void TestReferenceLyricListPropertyChanged()
TextTagAssert.ArePropertyEqual(referencedLyric.RomajiTags, lyric.RomajiTags);

// and because there's no change inside the tag, so there's version change.
Assert.AreEqual(0, lyric.TimeTagsVersion.Value);
Assert.AreEqual(0, lyric.TimeTagsTimingVersion.Value);
Assert.AreEqual(0, lyric.RubyTagsVersion.Value);
Assert.AreEqual(0, lyric.RomajiTagsVersion.Value);

Expand All @@ -217,7 +217,7 @@ public void TestReferenceLyricListPropertyChanged()
TextTagAssert.ArePropertyEqual(referencedLyric.RomajiTags, lyric.RomajiTags);

// and note that because only one property is different, so version should change once.
Assert.AreEqual(1, lyric.TimeTagsVersion.Value);
Assert.AreEqual(1, lyric.TimeTagsTimingVersion.Value);
Assert.AreEqual(1, lyric.RubyTagsVersion.Value);
Assert.AreEqual(1, lyric.RomajiTagsVersion.Value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace osu.Game.Rulesets.Karaoke.Graphics.Sprites;
private const int whole_chunk_index = -1;

private readonly IBindable<string> textBindable = new Bindable<string>();
private readonly IBindable<int> timeTagsVersion = new Bindable<int>();
private readonly IBindable<int> timeTagsTimingVersion = new Bindable<int>();
private readonly IBindableList<TimeTag> timeTagsBindable = new BindableList<TimeTag>();
private readonly IBindable<int> rubyTagsVersion = new Bindable<int>();
private readonly IBindableList<RubyTag> rubyTagsBindable = new BindableList<RubyTag>();
Expand All @@ -29,15 +29,15 @@ protected DrawableKaraokeSpriteText(Lyric lyric, int chunkIndex = whole_chunk_in
this.chunkIndex = chunkIndex;

textBindable.BindValueChanged(_ => UpdateText(), true);
timeTagsVersion.BindValueChanged(_ => UpdateTimeTags());
timeTagsTimingVersion.BindValueChanged(_ => UpdateTimeTags());
timeTagsBindable.BindCollectionChanged((_, _) => UpdateTimeTags());
rubyTagsVersion.BindValueChanged(_ => UpdateRubies());
rubyTagsBindable.BindCollectionChanged((_, _) => UpdateRubies());
romajiTagsVersion.BindValueChanged(_ => UpdateRomajies());
romajiTagsBindable.BindCollectionChanged((_, _) => UpdateRomajies());

textBindable.BindTo(lyric.TextBindable);
timeTagsVersion.BindTo(lyric.TimeTagsVersion);
timeTagsTimingVersion.BindTo(lyric.TimeTagsTimingVersion);
timeTagsBindable.BindTo(lyric.TimeTagsBindable);
rubyTagsVersion.BindTo(lyric.RubyTagsVersion);
rubyTagsBindable.BindTo(lyric.RubyTagsBindable);
Expand Down
28 changes: 21 additions & 7 deletions osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ namespace osu.Game.Rulesets.Karaoke.Objects;
public partial class Lyric
{
[JsonIgnore]
public IBindable<int> TimeTagsVersion => timeTagsVersion;
public IBindable<int> TimeTagsTimingVersion => timeTagsTimingVersion;

private readonly Bindable<int> timeTagsVersion = new();
private readonly Bindable<int> timeTagsTimingVersion = new();

[JsonIgnore]
public IBindable<int> TimeTagsRomajiVersion => timeTagsRomajiVersion;

private readonly Bindable<int> timeTagsRomajiVersion = new();

[JsonIgnore]
public IBindable<int> RubyTagsVersion => rubyTagsVersion;
Expand Down Expand Up @@ -54,24 +59,33 @@ private void initInternalBindingEvent()
Debug.Assert(args.NewItems != null);

foreach (var c in args.NewItems.Cast<TimeTag>())
c.TimingChanged += invalidate;
{
c.TimingChanged += timingInvalidate;
c.RomajiChanged += romajiInvalidate;
}

break;

case NotifyCollectionChangedAction.Reset:
case NotifyCollectionChangedAction.Remove:
Debug.Assert(args.OldItems != null);

foreach (var c in args.OldItems.Cast<TimeTag>())
c.TimingChanged -= invalidate;
{
c.TimingChanged -= timingInvalidate;
c.RomajiChanged -= romajiInvalidate;
}

break;
}

updateLyricTime();

void invalidate() => timeTagsVersion.Value++;
void timingInvalidate() => timeTagsTimingVersion.Value++;
void romajiInvalidate() => timeTagsRomajiVersion.Value++;
};

TimeTagsVersion.ValueChanged += _ =>
TimeTagsTimingVersion.ValueChanged += _ =>
{
updateLyricTime();
};
Expand Down Expand Up @@ -194,7 +208,7 @@ private void initReferenceLyricEvent()
}).ToArray();
});

bindValueChange(e, l => l.TimeTagsVersion, (_, config) =>
bindValueChange(e, l => l.TimeTagsTimingVersion, (_, config) =>
{
if (config is not SyncLyricConfig syncLyricConfig || !syncLyricConfig.SyncTimeTagProperty)
return;
Expand Down
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Karaoke/Objects/Note_Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ private void initReferenceLyricEvent()
ReferenceLyricBindable.ValueChanged += e =>
{
if (e.OldValue != null)
e.OldValue.TimeTagsVersion.ValueChanged -= timeTagVersionChanged;
e.OldValue.TimeTagsTimingVersion.ValueChanged -= timeTagsTimingVersionChanged;

if (e.NewValue != null)
e.NewValue.TimeTagsVersion.ValueChanged += timeTagVersionChanged;
e.NewValue.TimeTagsTimingVersion.ValueChanged += timeTagsTimingVersionChanged;

syncStartTimeAndDurationFromTimeTag();
syncReferenceLyricSingers();
};

void timeTagVersionChanged(ValueChangedEvent<int> e) => syncStartTimeAndDurationFromTimeTag();
void timeTagsTimingVersionChanged(ValueChangedEvent<int> e) => syncStartTimeAndDurationFromTimeTag();
}

private void syncStartTimeAndDurationFromTimeTag()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract partial class TimeTagScrollContainer : BindableScrollContainer
{
private readonly IBindable<Lyric?> bindableFocusedLyric = new Bindable<Lyric?>();

private readonly IBindable<int> timeTagsVersion = new Bindable<int>();
private readonly IBindable<int> timeTagsTimingVersion = new Bindable<int>();

[Cached]
private readonly BindableList<TimeTag> timeTagsBindable = new();
Expand All @@ -42,19 +42,19 @@ protected TimeTagScrollContainer()
{
RelativeSizeAxes = Axes.X;

timeTagsVersion.BindValueChanged(_ => updateTimeRange());
timeTagsTimingVersion.BindValueChanged(_ => updateTimeRange());
timeTagsBindable.BindCollectionChanged((_, _) => updateTimeRange());

bindableFocusedLyric.BindValueChanged(e =>
{
timeTagsVersion.UnbindBindings();
timeTagsTimingVersion.UnbindBindings();
timeTagsBindable.UnbindBindings();

var lyric = e.NewValue;
if (lyric == null)
return;

timeTagsVersion.BindTo(lyric.TimeTagsVersion);
timeTagsTimingVersion.BindTo(lyric.TimeTagsTimingVersion);
timeTagsBindable.BindTo(lyric.TimeTagsBindable);

Schedule(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.LyricList.Rows.

public partial class TimeTagInfo : SubInfo
{
private readonly IBindable<int> bindableTimeTagsVersion;
private readonly IBindable<int> bindableTimeTagsTimingVersion;
private readonly IBindableList<TimeTag> bindableTimeTags;

public TimeTagInfo(Lyric lyric)
: base(lyric)
{
bindableTimeTagsVersion = lyric.TimeTagsVersion.GetBoundCopy();
bindableTimeTagsTimingVersion = lyric.TimeTagsTimingVersion.GetBoundCopy();
bindableTimeTags = lyric.TimeTagsBindable.GetBoundCopy();
}

Expand All @@ -26,7 +26,7 @@ private void load(OsuColour colours)
{
BadgeColour = colours.Green;

bindableTimeTagsVersion.BindValueChanged(_ => updateBadgeText());
bindableTimeTagsTimingVersion.BindValueChanged(_ => updateBadgeText());
bindableTimeTags.BindCollectionChanged((_, _) => updateBadgeText());

updateBadgeText();
Expand Down

0 comments on commit 51859f5

Please sign in to comment.