Skip to content

Commit

Permalink
temp.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Sep 6, 2022
1 parent be35dc6 commit cef77ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<Lyric>();
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;
*/
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -123,6 +125,12 @@ public override bool PositionMovable(TimeTagCaretPosition position)
return targetTimeTag == null ? null : new TimeTagCaretPosition(lyric, targetTimeTag);
}

private IEnumerable<TimeTag> sortTimeTag(IEnumerable<TimeTag> timeTags)
=> TimeTagsUtils.Sort(timeTags);

private IEnumerable<TimeTag> getAllSortedTimeTag()
=> sortTimeTag(Lyrics.SelectMany(x => x.TimeTags));

private TimeTagCaretPosition? timeTagToPosition(TimeTag timeTag)
{
var lyric = timeTagInLyric(timeTag);
Expand Down

0 comments on commit cef77ba

Please sign in to comment.