From d15a0f567b71a2af108691437ddf46e8677ec7f6 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 5 Sep 2022 00:00:36 +0800 Subject: [PATCH 1/4] Implement the base class for able to check the forbidden change in the hit-object property related change handler. --- .../BaseHitObjectPropertyChangeHandlerTest.cs | 18 ++++++++++++++++++ .../Lyrics/LyricPropertyChangeHandlerTest.cs | 8 +------- 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/BaseHitObjectPropertyChangeHandlerTest.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/BaseHitObjectPropertyChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/BaseHitObjectPropertyChangeHandlerTest.cs new file mode 100644 index 000000000..0563e1042 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/BaseHitObjectPropertyChangeHandlerTest.cs @@ -0,0 +1,18 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers; +using osu.Game.Rulesets.Objects; + +namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers +{ + public abstract class BaseHitObjectPropertyChangeHandlerTest : BaseHitObjectChangeHandlerTest + where TChangeHandler : HitObjectPropertyChangeHandler, new() where THitObject : HitObject + { + protected void TriggerHandlerChangedWithChangeForbiddenException(Action c) + { + TriggerHandlerChangedWithException.ChangeForbiddenException>(c); + } + } +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyChangeHandlerTest.cs index ce59fed3c..1c95a0895 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyChangeHandlerTest.cs @@ -1,14 +1,13 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using System; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Objects.Properties; namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics { - public abstract class LyricPropertyChangeHandlerTest : BaseHitObjectChangeHandlerTest + public abstract class LyricPropertyChangeHandlerTest : BaseHitObjectPropertyChangeHandlerTest where TChangeHandler : LyricPropertyChangeHandler, new() { protected Lyric PrepareLyricWithSyncConfig(Lyric referencedLyric, IReferenceLyricPropertyConfig? config = null, bool selected = true) @@ -23,10 +22,5 @@ protected Lyric PrepareLyricWithSyncConfig(Lyric referencedLyric, IReferenceLyri return lyric; } - - protected void TriggerHandlerChangedWithChangeForbiddenException(Action c) - { - TriggerHandlerChangedWithException(c); - } } } From e271026449b5001c329990cc91ddbb0f0a2519bb Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 5 Sep 2022 00:02:23 +0800 Subject: [PATCH 2/4] Apply the base class into note and lock property test case. --- .../Editor/ChangeHandlers/LockChangeHandlerTest.cs | 2 +- .../ChangeHandlers/Notes/NotePropertyChangeHandlerTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs index 492bb27bb..f650f1dea 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs @@ -8,7 +8,7 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers { - public class LockChangeHandlerTest : BaseHitObjectChangeHandlerTest + public class LockChangeHandlerTest : BaseHitObjectPropertyChangeHandlerTest { [Test] public void TestLock() diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotePropertyChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotePropertyChangeHandlerTest.cs index 36591b9ad..1b0991c34 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotePropertyChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotePropertyChangeHandlerTest.cs @@ -7,7 +7,7 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Notes { - public class NotePropertyChangeHandlerTest : BaseHitObjectChangeHandlerTest + public class NotePropertyChangeHandlerTest : BaseHitObjectPropertyChangeHandlerTest { [Test] public void TestChangeText() From 51d65f220f8fb5e9a679bdd19a1e0d3a959d1635 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 4 Sep 2022 23:56:12 +0800 Subject: [PATCH 3/4] Apply the check property lock logic. --- .../Edit/ChangeHandlers/LockChangeHandler.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/LockChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/LockChangeHandler.cs index 38ccd67e3..950d56de0 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/LockChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/LockChangeHandler.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using osu.Game.Rulesets.Karaoke.Edit.Utils; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Objects.Types; @@ -25,11 +26,10 @@ public void Unlock() protected override bool IsWritePropertyLocked(KaraokeHitObject hitObject) { - // todo: implement. return hitObject switch { - Lyric => false, - Note => false, + Lyric lyric => HitObjectWritableUtils.IsWriteLyricPropertyLocked(lyric, nameof(Lyric.Lock)), + Note note => HitObjectWritableUtils.IsWriteNotePropertyLocked(note, nameof(Lyric.Lock)), _ => throw new NotSupportedException() }; } From 4b73fd403d60e0eac02ce4a8a658147708fefce4 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 5 Sep 2022 00:13:02 +0800 Subject: [PATCH 4/4] Add the missing test case. --- .../ChangeHandlers/LockChangeHandlerTest.cs | 14 ++++++++++++++ .../Notes/NotePropertyChangeHandlerTest.cs | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs index f650f1dea..513aed2be 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers; using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Objects.Properties; using osu.Game.Rulesets.Karaoke.Objects.Types; namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers @@ -55,5 +56,18 @@ public void TestUnlock() Assert.AreEqual(LockState.None, hasLock.Lock); }); } + + [Test] + public void TestLockToReferenceLyric() + { + PrepareHitObject(new Lyric + { + Text = "カラオケ", + ReferenceLyric = new Lyric(), + ReferenceLyricConfig = new SyncLyricConfig(), + }); + + TriggerHandlerChangedWithChangeForbiddenException(c => c.Lock(LockState.Full)); + } } } diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotePropertyChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotePropertyChangeHandlerTest.cs index 1b0991c34..e1c5a2fb8 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotePropertyChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotePropertyChangeHandlerTest.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Notes; using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Objects.Properties; namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Notes { @@ -71,5 +72,22 @@ public void TestChangeDisplayStateToNonVisible() Assert.AreEqual(new Tone(), h.Tone); }); } + + [Test] + [Ignore("Waiting to implement the lock rules.")] + public void TestWithReferenceLyric() + { + PrepareHitObject(new Note + { + Text = "カラオケ", + ReferenceLyric = new Lyric + { + ReferenceLyric = new Lyric(), + ReferenceLyricConfig = new ReferenceLyricConfig() + } + }); + + TriggerHandlerChangedWithChangeForbiddenException(c => c.ChangeText("からおけ")); + } } }