Skip to content

Commit

Permalink
Merge pull request #1559 from andy840119/implement-lyric-property-wri…
Browse files Browse the repository at this point in the history
…table-version-bindable

Add the `LyricPropertyWritableVersion` property in the lyric.
  • Loading branch information
andy840119 authored Sep 4, 2022
2 parents edd4d12 + 67dd4f2 commit ef11731
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
28 changes: 28 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/Objects/LyricTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,33 @@ public void TestConfigChange()
}

#endregion

#region MyRegion

[Test]
public void TestLyricPropertyWritableVersion()
{
var lyric = new Lyric();
Assert.AreEqual(0, lyric.LyricPropertyWritableVersion.Value);

lyric.Lock = LockState.Partial;
Assert.AreEqual(1, lyric.LyricPropertyWritableVersion.Value);

lyric.ReferenceLyric = new Lyric();
Assert.AreEqual(2, lyric.LyricPropertyWritableVersion.Value);

lyric.ReferenceLyricConfig = new SyncLyricConfig();
Assert.AreEqual(3, lyric.LyricPropertyWritableVersion.Value);

(lyric.ReferenceLyricConfig as SyncLyricConfig)!.OffsetTime = 200;
Assert.AreEqual(4, lyric.LyricPropertyWritableVersion.Value);

// version number will not increase if change not related property or assign the same value.
lyric.Lock = LockState.Partial;
lyric.Text = "karaoke";
Assert.AreEqual(4, lyric.LyricPropertyWritableVersion.Value);
}

#endregion
}
}
3 changes: 3 additions & 0 deletions osu.Game.Rulesets.Karaoke/Objects/Lyric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ public IReferenceLyricPropertyConfig? ReferenceLyricConfig
set => ReferenceLyricConfigBindable.Value = value;
}

[JsonIgnore]
public readonly Bindable<int> LyricPropertyWritableVersion = new();

public Lyric()
{
initInternalBindingEvent();
Expand Down
7 changes: 7 additions & 0 deletions osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ private void initInternalBindingEvent()
void invalidate() => RomajiTagsVersion.Value++;
};

LockBindable.ValueChanged += e =>
{
LyricPropertyWritableVersion.Value++;
};

ReferenceLyricConfigBindable.ValueChanged += e =>
{
if (e.OldValue != null)
Expand Down Expand Up @@ -102,6 +107,8 @@ private void initReferenceLyricEvent()

ReferenceLyricBindable.ValueChanged += e =>
{
LyricPropertyWritableVersion.Value++;

// text.
bindValueChange(e, l => l.TextBindable, (lyric, config) =>
{
Expand Down

0 comments on commit ef11731

Please sign in to comment.