-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1502 from andy840119/refactor-note-utils
Refactor the Note or Notes utils.
- Loading branch information
Showing
5 changed files
with
58 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,12 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using osu.Game.Rulesets.Karaoke.Objects; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Utils | ||
{ | ||
public static class NoteUtils | ||
{ | ||
public static Note SliceNote(Note note, double startPercentage, double durationPercentage) | ||
{ | ||
if (startPercentage < 0 || startPercentage + durationPercentage > 1) | ||
throw new ArgumentOutOfRangeException($"{nameof(Note)} cannot assign split range of start from {startPercentage} and duration {durationPercentage}"); | ||
|
||
double startTime = note.StartTime + note.Duration * startPercentage; | ||
double duration = note.Duration * durationPercentage; | ||
|
||
return CopyByTime(note, startTime, duration); | ||
} | ||
|
||
public static Note CopyByTime(Note originNote, double startTime, double duration) | ||
{ | ||
double fixedStartTime = originNote.StartTime - originNote.StartTimeOffset; | ||
double fixedEndTime = originNote.EndTime - originNote.EndTimeOffset; | ||
double endTime = startTime + duration; | ||
|
||
var note = originNote.DeepClone(); | ||
note.StartTimeOffset = startTime - fixedStartTime; | ||
note.EndTimeOffset = endTime - fixedEndTime; | ||
|
||
return note; | ||
} | ||
|
||
/// <summary> | ||
/// Get the display text while gameplay or in editor. | ||
/// </summary> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters