From 67dd4f25d442c757fec7f77e9d70565f841819f8 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 4 Sep 2022 15:13:49 +0800 Subject: [PATCH] Add the LyricPropertyWritableVersion property in the lyric. Will increase the number if related property changed. --- .../Objects/LyricTest.cs | 28 +++++++++++++++++++ osu.Game.Rulesets.Karaoke/Objects/Lyric.cs | 3 ++ .../Objects/Lyric_Binding.cs | 7 +++++ 3 files changed, 38 insertions(+) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Objects/LyricTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Objects/LyricTest.cs index 153456090..93473e460 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Objects/LyricTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Objects/LyricTest.cs @@ -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 } } diff --git a/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs b/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs index ea1f0a590..e9bb809ce 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs @@ -228,6 +228,9 @@ public IReferenceLyricPropertyConfig? ReferenceLyricConfig set => ReferenceLyricConfigBindable.Value = value; } + [JsonIgnore] + public readonly Bindable LyricPropertyWritableVersion = new(); + public Lyric() { initInternalBindingEvent(); diff --git a/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs b/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs index 8a3e5f419..f98362c69 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Lyric_Binding.cs @@ -72,6 +72,11 @@ private void initInternalBindingEvent() void invalidate() => RomajiTagsVersion.Value++; }; + LockBindable.ValueChanged += e => + { + LyricPropertyWritableVersion.Value++; + }; + ReferenceLyricConfigBindable.ValueChanged += e => { if (e.OldValue != null) @@ -102,6 +107,8 @@ private void initReferenceLyricEvent() ReferenceLyricBindable.ValueChanged += e => { + LyricPropertyWritableVersion.Value++; + // text. bindValueChange(e, l => l.TextBindable, (lyric, config) => {