Skip to content

Commit

Permalink
Use deep clone instead of copy the property in the utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Jul 31, 2022
1 parent ab9ea5e commit 58086c3
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions osu.Game.Rulesets.Karaoke/Utils/LyricsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,20 @@ public static Tuple<Lyric, Lyric> SplitLyric(Lyric lyric, int splitIndex)
}
}

var firstLyric = new Lyric
{
Text = lyric.Text[..splitIndex],
TimeTags = firstTimeTag.ToArray(),
RubyTags = lyric.RubyTags.Where(x => x.StartIndex < splitIndex && x.EndIndex <= splitIndex).ToArray(),
RomajiTags = lyric.RomajiTags.Where(x => x.StartIndex < splitIndex && x.EndIndex <= splitIndex).ToArray(),
// todo : should implement time and duration
Singers = lyric.Singers,
Language = lyric.Language,
};

// todo : should implement time and duration
var firstLyric = lyric.DeepClone();
firstLyric.Text = lyric.Text[..splitIndex];
firstLyric.TimeTags = firstTimeTag.ToArray();
firstLyric.RubyTags = lyric.RubyTags.Where(x => x.StartIndex < splitIndex && x.EndIndex <= splitIndex).ToArray();
firstLyric.RomajiTags = lyric.RomajiTags.Where(x => x.StartIndex < splitIndex && x.EndIndex <= splitIndex).ToArray();

// todo : should implement time and duration
string secondLyricText = lyric.Text[splitIndex..];
var secondLyric = new Lyric
{
Text = secondLyricText,
TimeTags = shiftingTimeTag(secondTimeTag.ToArray(), -splitIndex),
RubyTags = shiftingTextTag(lyric.RubyTags.Where(x => x.StartIndex >= splitIndex && x.EndIndex > splitIndex).ToArray(), secondLyricText, -splitIndex),
RomajiTags = shiftingTextTag(lyric.RomajiTags.Where(x => x.StartIndex >= splitIndex && x.EndIndex > splitIndex).ToArray(), secondLyricText, -splitIndex),
// todo : should implement time and duration
Singers = lyric.Singers,
Language = lyric.Language,
};
var secondLyric = lyric.DeepClone();
secondLyric.Text = secondLyricText;
secondLyric.TimeTags = shiftingTimeTag(secondTimeTag.ToArray(), -splitIndex);
secondLyric.RubyTags = shiftingTextTag(lyric.RubyTags.Where(x => x.StartIndex >= splitIndex && x.EndIndex > splitIndex).ToArray(), secondLyricText, -splitIndex);
secondLyric.RomajiTags = shiftingTextTag(lyric.RomajiTags.Where(x => x.StartIndex >= splitIndex && x.EndIndex > splitIndex).ToArray(), secondLyricText, -splitIndex);

return new Tuple<Lyric, Lyric>(firstLyric, secondLyric);
}
Expand Down

0 comments on commit 58086c3

Please sign in to comment.