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 e831d1fe0..4851176d3 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 { @@ -96,6 +97,18 @@ protected Lyric[] GetLyricsByMethodName(string methodName) throw new MissingMethodException("Test method is not exist."); return theMethod.GetValue(this) as Lyric[]; + + /* + 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 7e875e53a..aa0c2c4e1 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 { @@ -37,7 +39,7 @@ public override TimeTagCaretPosition MoveUp(TimeTagCaretPosition currentPosition 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(); return timeTagToPosition(upTimeTag); @@ -57,7 +59,7 @@ public override TimeTagCaretPosition MoveDown(TimeTagCaretPosition currentPositi 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(); return timeTagToPosition(downTimeTag); @@ -65,28 +67,28 @@ public override TimeTagCaretPosition MoveDown(TimeTagCaretPosition currentPositi public override TimeTagCaretPosition MoveLeft(TimeTagCaretPosition currentPosition) { - var timeTags = Lyrics.SelectMany(x => x.TimeTags ?? Array.Empty()).ToArray(); + var timeTags = getAllSortedTimeTag(); var previousTimeTag = timeTags.GetPreviousMatch(currentPosition.TimeTag, timeTagMovable); return timeTagToPosition(previousTimeTag); } public override TimeTagCaretPosition MoveRight(TimeTagCaretPosition currentPosition) { - var timeTags = Lyrics.SelectMany(x => x.TimeTags ?? Array.Empty()).ToArray(); + var timeTags = getAllSortedTimeTag(); var nextTimeTag = timeTags.GetNextMatch(currentPosition.TimeTag, timeTagMovable); return timeTagToPosition(nextTimeTag); } public override TimeTagCaretPosition MoveToFirst() { - var timeTags = Lyrics.SelectMany(x => x.TimeTags ?? Array.Empty()).ToArray(); + var timeTags = getAllSortedTimeTag(); var firstTimeTag = timeTags.FirstOrDefault(timeTagMovable); return timeTagToPosition(firstTimeTag); } public override TimeTagCaretPosition MoveToLast() { - var timeTags = Lyrics.SelectMany(x => x.TimeTags ?? Array.Empty()).ToArray(); + var timeTags = getAllSortedTimeTag(); var lastTag = timeTags.LastOrDefault(timeTagMovable); return timeTagToPosition(lastTag); } @@ -97,6 +99,12 @@ public override TimeTagCaretPosition MoveToTarget(Lyric lyric) return new TimeTagCaretPosition(lyric, targetTimeTag); } + private IEnumerable sortTimeTag(IEnumerable timeTags) + => TimeTagsUtils.Sort(timeTags); + + private IEnumerable getAllSortedTimeTag() + => sortTimeTag(Lyrics.SelectMany(x => x.TimeTags ?? Array.Empty())); + private TimeTagCaretPosition timeTagToPosition(TimeTag timeTag) { if (timeTag == null)