From cef77ba43428b634d097386a06dbd0dfde7f93b4 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 8 Mar 2022 21:41:32 +0800 Subject: [PATCH] temp. --- .../BaseCaretPositionAlgorithmTest.cs | 13 ++++++++++++ .../TimeTagCaretPositionAlgorithm.cs | 20 +++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/Lyrics/CaretPosition/Algorithms/BaseCaretPositionAlgorithmTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/Lyrics/CaretPosition/Algorithms/BaseCaretPositionAlgorithmTest.cs index 0f2c45bc7..8c62ecd41 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/Lyrics/CaretPosition/Algorithms/BaseCaretPositionAlgorithmTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/Lyrics/CaretPosition/Algorithms/BaseCaretPositionAlgorithmTest.cs @@ -7,6 +7,7 @@ using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition.Algorithms; using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Tests.Helper; namespace osu.Game.Rulesets.Karaoke.Tests.Editor.Lyrics.CaretPosition.Algorithms { @@ -115,6 +116,18 @@ protected Lyric[] GetLyricsByMethodName(string methodName) throw new MissingMethodException("Test method is not exist."); return (Lyric[])theMethod.GetValue(this)!; + + /* + var lyrics = theMethod.GetValue(this) as Lyric[] ?? Array.Empty(); + + foreach (var lyric in lyrics) + { + // because time-tag will not always sort by order, so we need to shuffle the time-tag in the list for testing. + lyric.TimeTags = TestCaseListHelper.Shuffle(lyric.TimeTags); + } + + return lyrics; + */ } } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/TimeTagCaretPositionAlgorithm.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/TimeTagCaretPositionAlgorithm.cs index 81c851e4e..ede6640ce 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/TimeTagCaretPositionAlgorithm.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/TimeTagCaretPositionAlgorithm.cs @@ -2,10 +2,12 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics.Sprites; using osu.Game.Rulesets.Karaoke.Extensions; using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Utils; namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.CaretPosition.Algorithms { @@ -41,7 +43,7 @@ public override bool PositionMovable(TimeTagCaretPosition position) if (previousLyric == null) return null; - var timeTags = previousLyric.TimeTags.Where(timeTagMovable).ToArray(); + var timeTags = sortTimeTag(previousLyric.TimeTags.Where(timeTagMovable)).ToArray(); var upTimeTag = timeTags.FirstOrDefault(x => x.Index >= currentTimeTag.Index) ?? timeTags.LastOrDefault(); @@ -65,7 +67,7 @@ public override bool PositionMovable(TimeTagCaretPosition position) if (nextLyric == null) return null; - var timeTags = nextLyric.TimeTags.Where(timeTagMovable).ToArray(); + var timeTags = sortTimeTag(nextLyric.TimeTags.Where(timeTagMovable)).ToArray(); var downTimeTag = timeTags.FirstOrDefault(x => x.Index >= currentTimeTag.Index) ?? timeTags.LastOrDefault(); @@ -77,7 +79,7 @@ public override bool PositionMovable(TimeTagCaretPosition position) public override TimeTagCaretPosition? MoveLeft(TimeTagCaretPosition currentPosition) { - var timeTags = Lyrics.SelectMany(x => x.TimeTags).ToArray(); + var timeTags = getAllSortedTimeTag(); var previousTimeTag = timeTags.GetPreviousMatch(currentPosition.TimeTag, timeTagMovable); if (previousTimeTag == null) return null; @@ -87,7 +89,7 @@ public override bool PositionMovable(TimeTagCaretPosition position) public override TimeTagCaretPosition? MoveRight(TimeTagCaretPosition currentPosition) { - var timeTags = Lyrics.SelectMany(x => x.TimeTags).ToArray(); + var timeTags = getAllSortedTimeTag(); var nextTimeTag = timeTags.GetNextMatch(currentPosition.TimeTag, timeTagMovable); if (nextTimeTag == null) return null; @@ -97,7 +99,7 @@ public override bool PositionMovable(TimeTagCaretPosition position) public override TimeTagCaretPosition? MoveToFirst() { - var timeTags = Lyrics.SelectMany(x => x.TimeTags).ToArray(); + var timeTags = getAllSortedTimeTag(); var firstTimeTag = timeTags.FirstOrDefault(timeTagMovable); if (firstTimeTag == null) return null; @@ -107,7 +109,7 @@ public override bool PositionMovable(TimeTagCaretPosition position) public override TimeTagCaretPosition? MoveToLast() { - var timeTags = Lyrics.SelectMany(x => x.TimeTags).ToArray(); + var timeTags = getAllSortedTimeTag(); var lastTimeTag = timeTags.LastOrDefault(timeTagMovable); if (lastTimeTag == null) return null; @@ -123,6 +125,12 @@ public override bool PositionMovable(TimeTagCaretPosition position) return targetTimeTag == null ? null : new TimeTagCaretPosition(lyric, targetTimeTag); } + private IEnumerable sortTimeTag(IEnumerable timeTags) + => TimeTagsUtils.Sort(timeTags); + + private IEnumerable getAllSortedTimeTag() + => sortTimeTag(Lyrics.SelectMany(x => x.TimeTags)); + private TimeTagCaretPosition? timeTagToPosition(TimeTag timeTag) { var lyric = timeTagInLyric(timeTag);