From 79c6daa27145a18f4cfeeedd6b83507d1fe4360f Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 26 Mar 2023 21:46:02 +0800 Subject: [PATCH 1/4] Create the invalid working property assign exception. Should throw the exception in the `Note` or `Lyric` if assign the value to the working property(e.g. reference lyric) not matched to the data property(e.g. reference lyric id). --- .../Workings/InvalidWorkingPropertyAssignException.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 osu.Game.Rulesets.Karaoke/Objects/Workings/InvalidWorkingPropertyAssignException.cs diff --git a/osu.Game.Rulesets.Karaoke/Objects/Workings/InvalidWorkingPropertyAssignException.cs b/osu.Game.Rulesets.Karaoke/Objects/Workings/InvalidWorkingPropertyAssignException.cs new file mode 100644 index 000000000..7df86446c --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Objects/Workings/InvalidWorkingPropertyAssignException.cs @@ -0,0 +1,10 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; + +namespace osu.Game.Rulesets.Karaoke.Objects.Workings; + +public class InvalidWorkingPropertyAssignException : Exception +{ +} From 6a5db70cb5fd01468f2aed08004c998bc80e862d Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 26 Mar 2023 10:19:04 +0800 Subject: [PATCH 2/4] Should throw exception if assign the working reference that the ID is not the same as reference lyric id stored in the lyric. --- osu.Game.Rulesets.Karaoke/Objects/Lyric.cs | 1 - osu.Game.Rulesets.Karaoke/Objects/Lyric_Working.cs | 3 ++- osu.Game.Rulesets.Karaoke/Objects/Note.cs | 1 - osu.Game.Rulesets.Karaoke/Objects/Note_Working.cs | 3 ++- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs b/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs index b9871b369..9f08c55a7 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Lyric.cs @@ -183,7 +183,6 @@ public int? ReferenceLyricId return; // should trying to reload the reference lyric. - ReferenceLyric = null; Validator.Invalidate(LyricInvalidation.ReferenceLyric); } } diff --git a/osu.Game.Rulesets.Karaoke/Objects/Lyric_Working.cs b/osu.Game.Rulesets.Karaoke/Objects/Lyric_Working.cs index 92632927d..b0a98d993 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Lyric_Working.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Lyric_Working.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using osu.Framework.Bindables; using osu.Game.Rulesets.Karaoke.Beatmaps; +using osu.Game.Rulesets.Karaoke.Objects.Workings; namespace osu.Game.Rulesets.Karaoke.Objects; @@ -77,7 +78,7 @@ public Lyric? ReferenceLyric if (value?.ID != ReferenceLyricId) { - ReferenceLyricId = value?.ID; + throw new InvalidWorkingPropertyAssignException(); } } } diff --git a/osu.Game.Rulesets.Karaoke/Objects/Note.cs b/osu.Game.Rulesets.Karaoke/Objects/Note.cs index 6c16e907a..0c4a34b1d 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Note.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Note.cs @@ -111,7 +111,6 @@ public int? ReferenceLyricId return; // should trying to reload the reference lyric. - ReferenceLyric = null; Validator.Invalidate(NoteInvalidation.ReferenceLyric); } } diff --git a/osu.Game.Rulesets.Karaoke/Objects/Note_Working.cs b/osu.Game.Rulesets.Karaoke/Objects/Note_Working.cs index f0d6102c4..27fe8d8fc 100644 --- a/osu.Game.Rulesets.Karaoke/Objects/Note_Working.cs +++ b/osu.Game.Rulesets.Karaoke/Objects/Note_Working.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json; using osu.Framework.Bindables; using osu.Game.Rulesets.Karaoke.Beatmaps; +using osu.Game.Rulesets.Karaoke.Objects.Workings; namespace osu.Game.Rulesets.Karaoke.Objects; @@ -80,7 +81,7 @@ public Lyric? ReferenceLyric if (value?.ID != ReferenceLyricId) { - ReferenceLyricId = value?.ID; + throw new InvalidWorkingPropertyAssignException(); } } } From 8ebd39d15c366fd44b1869e2a98d85c23aa6f449 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 26 Mar 2023 11:01:17 +0800 Subject: [PATCH 3/4] Should write the value to the reference lyric id also. --- .../Lyrics/LyricAutoGenerateChangeHandler.cs | 9 ++++++--- .../ChangeHandlers/Lyrics/LyricReferenceChangeHandler.cs | 5 ++++- .../Edit/Generator/Lyrics/Notes/NoteGenerator.cs | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandler.cs index 2d9f9f6c1..f1a549081 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandler.cs @@ -137,10 +137,13 @@ public void AutoGenerate(LyricAutoGenerateProperty autoGenerateProperty) var referenceLyricDetector = createLyricDetector(); PerformOnSelection(lyric => { - var detectedLanguage = referenceLyricDetector.Detect(lyric); - lyric.ReferenceLyric = detectedLanguage; + var referencedLyric = referenceLyricDetector.Detect(lyric); + lyric.ReferenceLyricId = referencedLyric.ID; - if (lyric.ReferenceLyric != null && lyric.ReferenceLyricConfig is not SyncLyricConfig) + // technically this property should be assigned by beatmap processor, but should be OK to assign here for testing purpose. + lyric.ReferenceLyric = referencedLyric; + + if (lyric.ReferenceLyricId != null && lyric.ReferenceLyricConfig is not SyncLyricConfig) lyric.ReferenceLyricConfig = new SyncLyricConfig(); }); break; diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricReferenceChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricReferenceChangeHandler.cs index b39d35e78..4c257aeda 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricReferenceChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricReferenceChangeHandler.cs @@ -24,9 +24,12 @@ public void UpdateReferenceLyric(Lyric? referenceLyric) if (referenceLyric?.ReferenceLyric != null) throw new InvalidOperationException($"{nameof(referenceLyric)} should not contains another reference lyric."); + lyric.ReferenceLyricId = referenceLyric?.ID; + + // technically this property should be assigned by beatmap processor, but should be OK to assign here for testing purpose. lyric.ReferenceLyric = referenceLyric; - if (lyric.ReferenceLyric == null) + if (lyric.ReferenceLyricId == null) { lyric.ReferenceLyricConfig = null; } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Notes/NoteGenerator.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Notes/NoteGenerator.cs index 0fe557648..4cd13ed9a 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Notes/NoteGenerator.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/Lyrics/Notes/NoteGenerator.cs @@ -62,6 +62,8 @@ protected override Note[] GenerateFromItem(Lyric item) { Text = text, RubyText = ruby, + ReferenceLyricId = item.ID, + // technically this property should be assigned by beatmap processor, but should be OK to assign here for testing purpose. ReferenceLyric = item, ReferenceTimeTagIndex = timeTagIndex }); From 11e823789f86b037f649e575e086692e025c9442 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 26 Mar 2023 11:01:56 +0800 Subject: [PATCH 4/4] Fix the test case broken. --- .../KaraokeLegacyBeatmapDecoderTest.cs | 5 +- .../ChangeHandlers/LockChangeHandlerTest.cs | 7 ++- .../Lyrics/LyricPropertyChangeHandlerTest.cs | 3 +- .../Lyrics/LyricReferenceChangeHandlerTest.cs | 29 +++++---- .../Notes/NotesChangeHandlerTest.cs | 27 +++++---- .../Checks/CheckLyricReferenceLyricTest.cs | 12 ++-- .../Checks/CheckNoteReferenceLyricTest.cs | 50 +++++++++------- .../Editor/Checks/CheckNoteTimeTest.cs | 36 ++++++----- .../Utils/HitObjectWritableUtilsTest.cs | 4 +- .../Helper/TestCaseNoteHelper.cs | 3 +- .../Converters/LyricConverterTest.cs | 8 ++- .../Objects/LyricTest.cs | 59 ++++--------------- .../Objects/NoteTest.cs | 55 +++-------------- .../Replays/TestSceneAutoGeneration.cs | 19 ++++-- .../KaraokeBeatmapSkinDecodingTest.cs | 9 +-- .../Skinning/KaraokeSkinDecodingTest.cs | 9 +-- .../Skinning/TestSceneNote.cs | 4 +- .../UI/TestSceneNotePlayfield.cs | 4 +- .../Utils/NotesUtilsTest.cs | 19 +++--- 19 files changed, 176 insertions(+), 186 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/KaraokeLegacyBeatmapDecoderTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/KaraokeLegacyBeatmapDecoderTest.cs index fd58fb860..32a57e9a8 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/KaraokeLegacyBeatmapDecoderTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/Formats/KaraokeLegacyBeatmapDecoderTest.cs @@ -137,7 +137,7 @@ private static void testNote(string expectedText, int expectedTone, bool expecte [TestCase(0.3, 1, null)] // start + duration should not exceed 1 public void TestSliceNoteTime(double startPercentage, double durationPercentage, double[]? expected) { - var lyric = new Lyric + var referencedLyric = new Lyric { TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { "[0,start]:1000", "[1,start]:4000" }), }; @@ -145,7 +145,8 @@ public void TestSliceNoteTime(double startPercentage, double durationPercentage, // start time will be 1000, and duration will be 3000. var note = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = 0 }; diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs index 871a3ef20..53359dd58 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/LockChangeHandlerTest.cs @@ -60,13 +60,16 @@ public void TestUnlock() [Test] public void TestLockToReferenceLyric() { + var referencedLyric = new Lyric { ID = 2 }; + PrepareHitObject(new Lyric { Text = "カラオケ", - ReferenceLyric = new Lyric(), + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceLyricConfig = new SyncLyricConfig(), }); TriggerHandlerChangedWithChangeForbiddenException(c => c.Lock(LockState.Full)); } -} \ No newline at end of file +} 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 293f6894d..94542aa2c 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricPropertyChangeHandlerTest.cs @@ -14,6 +14,7 @@ protected Lyric PrepareLyricWithSyncConfig(Lyric referencedLyric, IReferenceLyri { var lyric = new Lyric { + ReferenceLyricId = referencedLyric.ID, ReferenceLyric = referencedLyric, ReferenceLyricConfig = config ?? new SyncLyricConfig() }; @@ -22,4 +23,4 @@ protected Lyric PrepareLyricWithSyncConfig(Lyric referencedLyric, IReferenceLyri return lyric; } -} \ No newline at end of file +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricReferenceChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricReferenceChangeHandlerTest.cs index 77ba03c9b..15840a1fb 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricReferenceChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricReferenceChangeHandlerTest.cs @@ -13,23 +13,23 @@ public partial class LyricReferenceChangeHandlerTest : LyricPropertyChangeHandle [Test] public void TestUpdateReferenceLyric() { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "Referenced lyric" }; - PrepareHitObject(lyric, false); + PrepareHitObject(referencedLyric, false); PrepareHitObject(new Lyric { Text = "I need the reference lyric." }); - TriggerHandlerChanged(c => c.UpdateReferenceLyric(lyric)); + TriggerHandlerChanged(c => c.UpdateReferenceLyric(referencedLyric)); AssertSelectedHitObject(h => { - Assert.AreEqual(lyric, h.ReferenceLyric); + Assert.AreEqual(referencedLyric, h.ReferenceLyric); Assert.IsTrue(h.ReferenceLyricConfig is ReferenceLyricConfig); }); } @@ -37,7 +37,7 @@ public void TestUpdateReferenceLyric() [Test] public void TestSwitchToReferenceLyricConfig() { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "Referenced lyric" }; @@ -45,14 +45,15 @@ public void TestSwitchToReferenceLyricConfig() PrepareHitObject(new Lyric { Text = "Lyric", - ReferenceLyric = lyric + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric }); TriggerHandlerChanged(c => c.SwitchToReferenceLyricConfig()); AssertSelectedHitObject(h => { - Assert.AreEqual(lyric, h.ReferenceLyric); + Assert.AreEqual(referencedLyric, h.ReferenceLyric); Assert.IsTrue(h.ReferenceLyricConfig is ReferenceLyricConfig); }); } @@ -60,7 +61,7 @@ public void TestSwitchToReferenceLyricConfig() [Test] public void TestSwitchToSyncLyricConfig() { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "Referenced lyric" }; @@ -68,14 +69,15 @@ public void TestSwitchToSyncLyricConfig() PrepareHitObject(new Lyric { Text = "Lyric", - ReferenceLyric = lyric + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric }); TriggerHandlerChanged(c => c.SwitchToSyncLyricConfig()); AssertSelectedHitObject(h => { - Assert.AreEqual(lyric, h.ReferenceLyric); + Assert.AreEqual(referencedLyric, h.ReferenceLyric); Assert.IsTrue(h.ReferenceLyricConfig is SyncLyricConfig); }); } @@ -83,7 +85,7 @@ public void TestSwitchToSyncLyricConfig() [Test] public void TestAdjustLyricConfig() { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "Referenced lyric" }; @@ -91,7 +93,8 @@ public void TestAdjustLyricConfig() PrepareHitObject(new Lyric { Text = "Lyric", - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceLyricConfig = new SyncLyricConfig(), }); @@ -126,4 +129,4 @@ public void TestWithReferenceLyric() TriggerHandlerChanged(c => c.SwitchToSyncLyricConfig()); TriggerHandlerChanged(c => c.AdjustLyricConfig(syncLyricConfig => syncLyricConfig.OffsetTime = 1000)); } -} \ No newline at end of file +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotesChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotesChangeHandlerTest.cs index 2a759e282..bfe2a69c9 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotesChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Notes/NotesChangeHandlerTest.cs @@ -14,10 +14,13 @@ public partial class NotesChangeHandlerTest : BaseHitObjectChangeHandlerTest c.Split()); @@ -45,24 +48,26 @@ public void TestSplit() [Test] public void TestCombine() { - var lyric = TestCaseNoteHelper.CreateLyricForNote("カラオケ", 1000, 1000); + var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "カラオケ", 1000, 1000); // note that lyric and notes should in the selection. - PrepareHitObject(lyric); + PrepareHitObject(referencedLyric); PrepareHitObjects(new[] { new Note { Text = "カラ", RubyText = "から", - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = 0 }, new Note { Text = "オケ", RubyText = "おけ", - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = 0 } }); @@ -85,23 +90,25 @@ public void TestCombine() [Test] public void TestClear() { - var lyric = new Lyric(); + var referencedLyric = new Lyric { ID = 2 }; // note that lyric and notes should in the selection. - PrepareHitObject(lyric); + PrepareHitObject(referencedLyric); PrepareHitObjects(new[] { new Note { Text = "カラ", RubyText = "から", - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, }, new Note { Text = "オケ", RubyText = "おけ", - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, } }, false); @@ -109,4 +116,4 @@ public void TestClear() AssertHitObjects(Assert.IsEmpty); } -} \ No newline at end of file +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckLyricReferenceLyricTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckLyricReferenceLyricTest.cs index ebbc41498..ef7b94459 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckLyricReferenceLyricTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckLyricReferenceLyricTest.cs @@ -16,9 +16,10 @@ public class CheckLyricReferenceLyricTest : HitObjectCheckTest(lyric); @@ -42,9 +44,10 @@ public void TestCheckSelfReference() [Test] public void TestCheckInvalidReferenceLyric() { - var referencedLyric = new Lyric(); + var referencedLyric = new Lyric { ID = 2 }; var lyric = new Lyric { + ReferenceLyricId = referencedLyric.ID, ReferenceLyric = referencedLyric, ReferenceLyricConfig = new ReferenceLyricConfig(), }; @@ -55,9 +58,10 @@ public void TestCheckInvalidReferenceLyric() [Test] public void TestCheckNullReferenceLyricConfig() { - var referencedLyric = new Lyric(); + var referencedLyric = new Lyric { ID = 2 }; var lyric = new Lyric { + ReferenceLyricId = referencedLyric.ID, ReferenceLyric = referencedLyric, }; @@ -75,4 +79,4 @@ public void TestCheckHasReferenceLyricConfigIfNoReferenceLyric() AssertNotOk(lyric); } -} \ No newline at end of file +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckNoteReferenceLyricTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckNoteReferenceLyricTest.cs index 6d93cfaaa..babcc8c9e 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckNoteReferenceLyricTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckNoteReferenceLyricTest.cs @@ -21,18 +21,19 @@ public class CheckNoteReferenceLyricTest : HitObjectCheckTest(new HitObject[] { lyric, note }); + AssertNotOk(new HitObject[] { referencedLyric, note }); } [TestCase(-1, new[] { "[0,start]:1000", "[3,end]:5000" })] [TestCase(-1, new[] { "[0,start]:1000", "[1,start]:2000", "[2,start]:3000", "[3,start]:4000", "[3,end]:5000" })] public void TestCheckMissingStartReferenceTimeTag(int referenceTimeTagIndex, string[] timeTags) { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "カラオケ", TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags) }; var note = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = referenceTimeTagIndex }; - AssertNotOk(new HitObject[] { lyric, note }); + AssertNotOk(new HitObject[] { referencedLyric, note }); } [TestCase(0, new[] { "[0,start]:", "[3,end]:5000" })] @@ -107,36 +112,38 @@ public void TestCheckMissingStartReferenceTimeTag(int referenceTimeTagIndex, str [TestCase(1, new[] { "[0,start]:1000", "[1,start]:", "[2,start]:3000", "[3,start]:4000", "[3,end]:5000" })] public void TestCheckStartReferenceTimeTagMissingTime(int referenceTimeTagIndex, string[] timeTags) { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "カラオケ", TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags) }; var note = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = referenceTimeTagIndex }; - AssertNotOk(new HitObject[] { lyric, note }); + AssertNotOk(new HitObject[] { referencedLyric, note }); } [TestCase(1, new[] { "[0,start]:1000", "[3,end]:5000" })] [TestCase(4, new[] { "[0,start]:1000", "[1,start]:2000", "[2,start]:3000", "[3,start]:4000", "[3,end]:5000" })] public void TestCheckMissingEndReferenceTimeTag(int referenceTimeTagIndex, string[] timeTags) { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "カラオケ", TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags) }; var note = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = referenceTimeTagIndex }; - AssertNotOk(new HitObject[] { lyric, note }); + AssertNotOk(new HitObject[] { referencedLyric, note }); } [TestCase(0, new[] { "[0,start]:1000", "[3,end]:" })] @@ -144,17 +151,18 @@ public void TestCheckMissingEndReferenceTimeTag(int referenceTimeTagIndex, strin [TestCase(2, new[] { "[0,start]:1000", "[1,start]:2000", "[2,start]:3000", "[3,start]:", "[3,end]:5000" })] public void TestCheckEndReferenceTimeTagMissingTime(int referenceTimeTagIndex, string[] timeTags) { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "カラオケ", TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags) }; var note = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = referenceTimeTagIndex }; - AssertNotOk(new HitObject[] { lyric, note }); + AssertNotOk(new HitObject[] { referencedLyric, note }); } -} \ No newline at end of file +} diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckNoteTimeTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckNoteTimeTest.cs index 5f8a6e568..5e824a9ee 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckNoteTimeTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Checks/CheckNoteTimeTest.cs @@ -17,18 +17,19 @@ public class CheckNoteTimeTest : HitObjectCheckTest [TestCase(3, new[] { "[0,start]:1000", "[1,start]:2000", "[2,start]:3000", "[3,start]:4000", "[3,end]:5000" })] public void TestCheck(int referenceTimeTagIndex, string[] timeTags) { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "カラオケ", TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags) }; var note = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = referenceTimeTagIndex }; - AssertOk(new HitObject[] { lyric, note }); + AssertOk(new HitObject[] { referencedLyric, note }); } [Test] @@ -37,6 +38,7 @@ public void TestCheckWithNoReferenceLyric() var note = new Note { Text = "karaoke", + ReferenceLyricId = null, ReferenceLyric = null, }; @@ -48,19 +50,20 @@ public void TestCheckWithNoReferenceLyric() [TestCase(2, new[] { "[0,start]:1000", "[1,start]:2000", "[2,start]:3000", "[3,start]:", "[3,end]:5000" })] // will missing end time-tag. public void TestCheckMissingStartOrEndTimeTag(int referenceTimeTagIndex, string[] timeTags) { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "カラオケ", TimeTags = TestCaseTagHelper.ParseTimeTags(timeTags) }; var note = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = referenceTimeTagIndex }; // should not have error because this check will be handled in other check. - AssertOk(new HitObject[] { lyric, note }); + AssertOk(new HitObject[] { referencedLyric, note }); } [TestCase("[0,start]:2000", "[1,start]:1000")] @@ -70,18 +73,19 @@ public void TestCheckMissingStartOrEndTimeTag(int referenceTimeTagIndex, string[ [TestCase("[1,start]:2000", "[0,start]:1000")] // should have error even if time-tag index is not sorted. we did not care about the time-tag index in here. public void TestCheckInvalidReferenceTimeTagTime(string startTimeTag, string endTimeTag) { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "カラオケ", TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { startTimeTag, endTimeTag }) }; var note = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = 0 }; - AssertNotOk(new HitObject[] { lyric, note }); + AssertNotOk(new HitObject[] { referencedLyric, note }); } [TestCase("[0,start]:", "[1,start]:")] @@ -91,18 +95,19 @@ public void TestCheckInvalidReferenceTimeTagTime(string startTimeTag, string end [TestCase("[1,start]:", "[0,start]:")] // should have error even if time-tag index is not sorted. we did not care about the time-tag index in here. public void TestCheckDurationTooShort(string startTimeTag, string endTimeTag) { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "カラオケ", TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { $"{startTimeTag}0", $"{endTimeTag}{MIN_DURATION - 1}" }) }; var note = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = 0 }; - AssertNotOk(new HitObject[] { lyric, note }); + AssertNotOk(new HitObject[] { referencedLyric, note }); } [TestCase("[0,start]:", "[1,start]:")] @@ -112,17 +117,18 @@ public void TestCheckDurationTooShort(string startTimeTag, string endTimeTag) [TestCase("[1,start]:", "[0,start]:")] // should have error even if time-tag index is not sorted. we did not care about the time-tag index in here. public void TestCheckDurationTooLong(string startTimeTag, string endTimeTag) { - var lyric = new Lyric + var referencedLyric = new Lyric { Text = "カラオケ", TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { $"{startTimeTag}0", $"{endTimeTag}{MAX_DURATION + 1}" }) }; var note = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = 0 }; - AssertNotOk(new HitObject[] { lyric, note }); + AssertNotOk(new HitObject[] { referencedLyric, note }); } } diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Utils/HitObjectWritableUtilsTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Utils/HitObjectWritableUtilsTest.cs index 1bb6eb4ec..5e6472bfa 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Utils/HitObjectWritableUtilsTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Utils/HitObjectWritableUtilsTest.cs @@ -137,9 +137,11 @@ public void TestIsWriteNotePropertyLocked() test(new Note()); // test with reference lyric. + var referencedLyric = new Lyric { ID = 2 }; test(new Note { - ReferenceLyric = new Lyric(), + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, }); static void test(Note note) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseNoteHelper.cs b/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseNoteHelper.cs index 9cd149b49..48aae45b1 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseNoteHelper.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Helper/TestCaseNoteHelper.cs @@ -9,10 +9,11 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Helper; public static class TestCaseNoteHelper { - public static Lyric CreateLyricForNote(string text, double startTime, double duration) + public static Lyric CreateLyricForNote(int id, string text, double startTime, double duration) { return new Lyric { + ID = id, Text = text, TimeTags = new List { diff --git a/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/LyricConverterTest.cs b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/LyricConverterTest.cs index b42d72031..034c7654f 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/LyricConverterTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/IO/Serialization/Converters/LyricConverterTest.cs @@ -57,9 +57,11 @@ public void TestDeserializeWithNoConfig() [Test] public void TestLyricConverterWithSyncConfig() { + var referencedLyric = new Lyric { ID = 0 }; var lyric = new Lyric { - ReferenceLyric = new Lyric(), + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceLyricConfig = new SyncLyricConfig() }; @@ -72,9 +74,11 @@ public void TestLyricConverterWithSyncConfig() [Test] public void TestLyricConverterWithReferenceConfig() { + var referencedLyric = new Lyric { ID = 0 }; var lyric = new Lyric { - ReferenceLyric = new Lyric(), + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceLyricConfig = new ReferenceLyricConfig() }; diff --git a/osu.Game.Rulesets.Karaoke.Tests/Objects/LyricTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Objects/LyricTest.cs index c7223e96b..f696fb5bd 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Objects/LyricTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Objects/LyricTest.cs @@ -19,7 +19,7 @@ public class LyricTest [TestCase] public void TestClone() { - var referencedLyric = new Lyric(); + var referencedLyric = new Lyric { ID = 2 }; var lyric = new Lyric { @@ -38,6 +38,7 @@ public void TestClone() Language = new CultureInfo("ja-JP"), Order = 1, Lock = LockState.None, + ReferenceLyricId = referencedLyric.ID, ReferenceLyric = referencedLyric, ReferenceLyricConfig = new ReferenceLyricConfig { @@ -106,6 +107,7 @@ public void TestSyncFromReferenceLyric() { var referencedLyric = new Lyric { + ID = 2, Text = "karaoke", TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { "[0,start]:1100" }), RubyTags = TestCaseTagHelper.ParseRubyTags(new[] { "[0,1]:か" }), @@ -120,6 +122,7 @@ public void TestSyncFromReferenceLyric() var lyric = new Lyric { + ReferenceLyricId = referencedLyric.ID, ReferenceLyric = referencedLyric, ReferenceLyricConfig = new SyncLyricConfig(), }; @@ -136,10 +139,11 @@ public void TestSyncFromReferenceLyric() [Test] public void TestReferenceLyricPropertyChanged() { - var referencedLyric = new Lyric(); + var referencedLyric = new Lyric { ID = 2 }; var lyric = new Lyric { + ReferenceLyricId = referencedLyric.ID, ReferenceLyric = referencedLyric, ReferenceLyricConfig = new SyncLyricConfig(), }; @@ -175,6 +179,7 @@ public void TestReferenceLyricListPropertyChanged() var referencedLyric = new Lyric { + ID = 2, Text = "karaoke", TimeTags = new[] { timeTag }, RubyTags = new[] { rubyTag }, @@ -189,6 +194,7 @@ public void TestReferenceLyricListPropertyChanged() var lyric = new Lyric { + ReferenceLyricId = referencedLyric.ID, ReferenceLyric = referencedLyric, ReferenceLyricConfig = new SyncLyricConfig(), }; @@ -232,6 +238,7 @@ public void TestConfigChange() var referencedLyric = new Lyric { + ID = 2, Text = "karaoke", TimeTags = TestCaseTagHelper.ParseTimeTags(new[] { "[0,start]:1100" }), RubyTags = TestCaseTagHelper.ParseRubyTags(new[] { "[0,1]:か" }), @@ -246,6 +253,7 @@ public void TestConfigChange() var lyric = new Lyric { + ReferenceLyricId = referencedLyric.ID, ReferenceLyric = referencedLyric, ReferenceLyricConfig = config }; @@ -263,49 +271,6 @@ public void TestConfigChange() Assert.AreEqual(referencedLyric.Singers, lyric.Singers); } - [Test] - public void TestReferenceLyricAffectedByReferenceLyricId() - { - var lyric = new Lyric - { - ReferenceLyric = new Lyric - { - ID = 2, - }, - }; - Assert.AreEqual(lyric.ReferenceLyric.ID, lyric.ReferenceLyricId); - - // Should not affect the reference lyric if reference lyric id is the same. - lyric.ReferenceLyricId = 2; - Assert.AreEqual(lyric.ReferenceLyric.ID, lyric.ReferenceLyricId); - - // Should clear the reference lyric if id changed. - lyric.ReferenceLyricId = 3; - Assert.IsNull(lyric.ReferenceLyric); - } - - [Test] - public void TestReferenceLyricIdAffectedByReferenceLyric() - { - var lyric = new Lyric - { - ReferenceLyric = new Lyric - { - ID = 2, - }, - ReferenceLyricId = 2, - }; - Assert.AreEqual(lyric.ReferenceLyric.ID, lyric.ReferenceLyricId); - - // Should change the reference lyric id if reference lyric changed. - lyric.ReferenceLyric = new Lyric { ID = 3 }; - Assert.AreEqual(lyric.ReferenceLyric.ID, lyric.ReferenceLyricId); - - // Should clear the reference lyric id if remove the reference lyric. - lyric.ReferenceLyric = null; - Assert.IsNull(lyric.ReferenceLyricId); - } - #endregion #region MyRegion @@ -319,7 +284,9 @@ public void TestLyricPropertyWritableVersion() lyric.Lock = LockState.Partial; Assert.AreEqual(1, lyric.LyricPropertyWritableVersion.Value); - lyric.ReferenceLyric = new Lyric(); + var referencedLyric = new Lyric { ID = 2 }; + lyric.ReferenceLyricId = referencedLyric.ID; + lyric.ReferenceLyric = referencedLyric; Assert.AreEqual(2, lyric.LyricPropertyWritableVersion.Value); lyric.ReferenceLyricConfig = new SyncLyricConfig(); diff --git a/osu.Game.Rulesets.Karaoke.Tests/Objects/NoteTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Objects/NoteTest.cs index ff123ee2f..6ae368f6e 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Objects/NoteTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Objects/NoteTest.cs @@ -13,6 +13,7 @@ public class NoteTest [TestCase] public void TestClone() { + var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "ノート", 1000, 1000); var note = new Note { Text = "ノート", @@ -20,7 +21,8 @@ public void TestClone() Display = true, StartTimeOffset = 100, EndTimeOffset = -100, - ReferenceLyric = TestCaseNoteHelper.CreateLyricForNote("ノート", 1000, 1000), + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = 0, }; @@ -71,15 +73,16 @@ public void TestReferenceTime() const double first_time_tag_time = 1000; const double second_time_tag_time = 3000; const double duration = second_time_tag_time - first_time_tag_time; - var lyric = TestCaseNoteHelper.CreateLyricForNote("Lyric", first_time_tag_time, duration); - note.ReferenceLyric = lyric; + var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "Lyric", first_time_tag_time, duration); + note.ReferenceLyricId = referencedLyric.ID; + note.ReferenceLyric = referencedLyric; // Should have calculated time. Assert.AreEqual(first_time_tag_time, note.StartTime); Assert.AreEqual(duration, note.Duration); const double time_tag_offset_time = 500; - lyric.TimeTags.ForEach(x => x.Time += time_tag_offset_time); + referencedLyric.TimeTags.ForEach(x => x.Time += time_tag_offset_time); // Should change the time if time-tag time has been changed. Assert.AreEqual(first_time_tag_time + time_tag_offset_time, note.StartTime); @@ -113,53 +116,11 @@ public void TestReferenceTime() Assert.AreEqual(first_time_tag_time + time_tag_offset_time + note_start_offset_time, note.StartTime); Assert.AreEqual(0, note.Duration); + note.ReferenceLyricId = null; note.ReferenceLyric = null; // time will be zero if lyric has been removed. Assert.AreEqual(0, note.StartTime); Assert.AreEqual(0, note.Duration); } - - [Test] - public void TestReferenceLyricAffectedByReferenceLyricId() - { - var note = new Note - { - ReferenceLyric = new Lyric - { - ID = 2, - }, - }; - Assert.AreEqual(note.ReferenceLyric.ID, note.ReferenceLyricId); - - // Should not affect the reference lyric if reference lyric id is the same. - note.ReferenceLyricId = 2; - Assert.AreEqual(note.ReferenceLyric.ID, note.ReferenceLyricId); - - // Should clear the reference lyric if id changed. - note.ReferenceLyricId = 3; - Assert.IsNull(note.ReferenceLyric); - } - - [Test] - public void TestReferenceLyricIdAffectedByReferenceLyric() - { - var note = new Note - { - ReferenceLyric = new Lyric - { - ID = 2, - }, - ReferenceLyricId = 2, - }; - Assert.AreEqual(note.ReferenceLyric.ID, note.ReferenceLyricId); - - // Should change the reference lyric id if reference lyric changed. - note.ReferenceLyric = new Lyric { ID = 3 }; - Assert.AreEqual(note.ReferenceLyric.ID, note.ReferenceLyricId); - - // Should clear the reference lyric id if remove the reference lyric. - note.ReferenceLyric = null; - Assert.IsNull(note.ReferenceLyricId); - } } diff --git a/osu.Game.Rulesets.Karaoke.Tests/Replays/TestSceneAutoGeneration.cs b/osu.Game.Rulesets.Karaoke.Tests/Replays/TestSceneAutoGeneration.cs index 5ad7d852f..b228dfe73 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Replays/TestSceneAutoGeneration.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Replays/TestSceneAutoGeneration.cs @@ -21,13 +21,16 @@ public void TestSingleShortNote() // | - | // | | + var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "karaoke!", 1000, 50); + var beatmap = new KaraokeBeatmap(); beatmap.HitObjects.Add(new Note { Text = "karaoke!", Display = true, Tone = new Tone(0, true), - ReferenceLyric = TestCaseNoteHelper.CreateLyricForNote("karaoke!", 1000, 50) + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric }); var generated = new KaraokeAutoGenerator(beatmap).Generate(); @@ -46,13 +49,16 @@ public void TestSingleNoteWithLongTime() // | *** | // | | + var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "karaoke!", 1000, 1000); + var beatmap = new KaraokeBeatmap(); beatmap.HitObjects.Add(new Note { Text = "karaoke!", Display = true, Tone = new Tone(0, true), - ReferenceLyric = TestCaseNoteHelper.CreateLyricForNote("karaoke!", 1000, 1000) + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric }); var generated = new KaraokeAutoGenerator(beatmap).Generate(); @@ -71,20 +77,25 @@ public void TestNoteStair() // | - | // | - | + var firstReferencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "karaoke!", 1000, 50); + var secondReferencedLyric = TestCaseNoteHelper.CreateLyricForNote(3, "karaoke!", 1050, 50); + var beatmap = new KaraokeBeatmap(); beatmap.HitObjects.Add(new Note { Text = "kara", Display = true, Tone = new Tone(0, true), - ReferenceLyric = TestCaseNoteHelper.CreateLyricForNote("karaoke!", 1000, 50) + ReferenceLyricId = firstReferencedLyric.ID, + ReferenceLyric = firstReferencedLyric }); beatmap.HitObjects.Add(new Note { Text = "oke!", Display = true, Tone = new Tone(1, true), - ReferenceLyric = TestCaseNoteHelper.CreateLyricForNote("karaoke!", 1050, 50) + ReferenceLyricId = secondReferencedLyric.ID, + ReferenceLyric = secondReferencedLyric }); var generated = new KaraokeAutoGenerator(beatmap).Generate(); diff --git a/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeBeatmapSkinDecodingTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeBeatmapSkinDecodingTest.cs index 35394d606..1c05ccf20 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeBeatmapSkinDecodingTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeBeatmapSkinDecodingTest.cs @@ -18,15 +18,16 @@ public void TestKaraokeBeatmapSkinDefaultValue() var storage = TestResources.CreateSkinStorageResourceProvider(); var skin = new KaraokeBeatmapSkin(new SkinInfo { Name = "special-skin" }, storage); - var testingLyric = new Lyric(); + var referencedLyric = new Lyric { ID = 2 }; var testingNote = new Note { - ReferenceLyric = testingLyric + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric }; // try to get default value from the skin. - var defaultLyricFontInfo = skin.GetConfig(testingLyric)!.Value; - var defaultLyricStyle = skin.GetConfig(testingLyric)!.Value; + var defaultLyricFontInfo = skin.GetConfig(referencedLyric)!.Value; + var defaultLyricStyle = skin.GetConfig(referencedLyric)!.Value; var defaultNoteStyle = skin.GetConfig(testingNote)!.Value; // should be able to get the default value. diff --git a/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeSkinDecodingTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeSkinDecodingTest.cs index 371ebcde5..a5821f54e 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeSkinDecodingTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Skinning/KaraokeSkinDecodingTest.cs @@ -18,15 +18,16 @@ public void TestKaraokeSkinDefaultValue() var storage = TestResources.CreateSkinStorageResourceProvider(); var skin = new KaraokeSkin(new SkinInfo { Name = "special-skin" }, storage); - var testingLyric = new Lyric(); + var referencedLyric = new Lyric { ID = 2 }; var testingNote = new Note { - ReferenceLyric = testingLyric + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric }; // try to get default value from the skin. - var defaultLyricFontInfo = skin.GetConfig(testingLyric)!.Value; - var defaultLyricStyle = skin.GetConfig(testingLyric)!.Value; + var defaultLyricFontInfo = skin.GetConfig(referencedLyric)!.Value; + var defaultLyricStyle = skin.GetConfig(referencedLyric)!.Value; var defaultNoteStyle = skin.GetConfig(testingNote)!.Value; // should be able to get the default value. diff --git a/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneNote.cs b/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneNote.cs index bf17285e0..31b972659 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneNote.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Skinning/TestSceneNote.cs @@ -28,10 +28,12 @@ public TestSceneNote() protected override DrawableHitObject CreateHitObject() { + var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "カラオケ", 100, 800); var note = new Note { Text = "カラオケ", - ReferenceLyric = TestCaseNoteHelper.CreateLyricForNote("カラオケ", 100, 800), + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, }; note.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); diff --git a/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneNotePlayfield.cs b/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneNotePlayfield.cs index 8fcc0c746..85040b105 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneNotePlayfield.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/UI/TestSceneNotePlayfield.cs @@ -111,12 +111,14 @@ private void createNote(double increaseTime = 2000, double duration = 1000, int { notePlayfields.ForEach(x => { + var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "Here", Time.Current + increaseTime, duration); var note = new Note { Text = "Here", Display = true, Tone = new Tone { Scale = tone }, - ReferenceLyric = TestCaseNoteHelper.CreateLyricForNote("Here", Time.Current + increaseTime, duration), + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = 0 }; note.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty()); diff --git a/osu.Game.Rulesets.Karaoke.Tests/Utils/NotesUtilsTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Utils/NotesUtilsTest.cs index 8faea7c33..eaa3bed09 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Utils/NotesUtilsTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Utils/NotesUtilsTest.cs @@ -21,9 +21,11 @@ public class NotesUtilsTest [TestCase(new double[] { 1000, 5000 }, 1, null, null)] public void TestSplitNoteTime(double[] time, double percentage, double[]? firstTime, double[]? secondTime) { + var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "Lyric", time[0], time[1]); var note = new Note { - ReferenceLyric = TestCaseNoteHelper.CreateLyricForNote("Lyric", time[0], time[1]), + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, }; if (firstTime != null && secondTime != null) @@ -47,15 +49,16 @@ public void TestSplitNoteOtherProperty() { const double percentage = 0.3; - var lyric = TestCaseNoteHelper.CreateLyricForNote("Lyric", 1000, 2000); - lyric.Singers = new[] { 0 }; + var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "Lyric", 1000, 2000); + referencedLyric.Singers = new[] { 0 }; var note = new Note { Text = "ka", Display = false, Tone = new Tone(-1, true), - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, ReferenceTimeTagIndex = 0 }; @@ -88,11 +91,12 @@ static void testRemainProperty(Note expect, Note actual) [TestCase(new double[] { 1000, 0 }, new double[] { 1000, 0 }, new double[] { 1000, 0 })] // it's ok to combine if duration is 0. public void TestCombineNoteTime(double[] firstOffset, double[] secondOffset, double[] expectedOffset) { - var lyric = TestCaseNoteHelper.CreateLyricForNote("Lyric", 1000, 5000); + var referencedLyric = TestCaseNoteHelper.CreateLyricForNote(2, "Lyric", 1000, 5000); var firstNote = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, StartTimeOffset = firstOffset[0], EndTimeOffset = firstOffset[1], ReferenceTimeTagIndex = 0, @@ -100,7 +104,8 @@ public void TestCombineNoteTime(double[] firstOffset, double[] secondOffset, dou var secondNote = new Note { - ReferenceLyric = lyric, + ReferenceLyricId = referencedLyric.ID, + ReferenceLyric = referencedLyric, StartTimeOffset = secondOffset[0], EndTimeOffset = secondOffset[1], ReferenceTimeTagIndex = 0,