Skip to content

Commit

Permalink
temp.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Mar 12, 2022
1 parent 1d01179 commit 0980de5
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 @@ -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<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 @@ -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);
Expand All @@ -57,36 +59,36 @@ 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);
}

public override TimeTagCaretPosition MoveLeft(TimeTagCaretPosition currentPosition)
{
var timeTags = Lyrics.SelectMany(x => x.TimeTags ?? Array.Empty<TimeTag>()).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<TimeTag>()).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<TimeTag>()).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<TimeTag>()).ToArray();
var timeTags = getAllSortedTimeTag();
var lastTag = timeTags.LastOrDefault(timeTagMovable);
return timeTagToPosition(lastTag);
}
Expand All @@ -99,6 +101,12 @@ public override TimeTagCaretPosition MoveToTarget(Lyric lyric)
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 ?? Array.Empty<TimeTag>()));

private TimeTagCaretPosition timeTagToPosition(TimeTag timeTag)
{
if (timeTag == null)
Expand Down

0 comments on commit 0980de5

Please sign in to comment.