-
-
Notifications
You must be signed in to change notification settings - Fork 75
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 #244 from UltraStar-Deluxe/anst/fixes
Anst/fixes
- Loading branch information
Showing
28 changed files
with
278 additions
and
83 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
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
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
52 changes: 52 additions & 0 deletions
52
UltraStar Play/Assets/Scenes/SongEditor/Actions/MoveNoteToOwnSentenceAction.cs
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UniInject; | ||
|
||
// Disable warning about fields that are never assigned, their values are injected. | ||
#pragma warning disable CS0649 | ||
|
||
public class MoveNoteToOwnSentenceAction : INeedInjection | ||
{ | ||
[Inject] | ||
private SongMetaChangeEventStream songMetaChangeEventStream; | ||
|
||
[Inject] | ||
private DeleteSentencesAction deleteSentencesAction; | ||
|
||
public bool CanMoveToOwnSentence(List<Note> notes) | ||
{ | ||
if (notes.IsNullOrEmpty()) | ||
{ | ||
return false; | ||
} | ||
return notes.AnyMatch(note => note.Sentence?.Voice != null); | ||
} | ||
|
||
public void MoveToOwnSentence(List<Note> notes) | ||
{ | ||
List<Sentence> affectedSentences = notes.Select(note => note.Sentence).ToList(); | ||
|
||
Sentence newSentence = new Sentence(); | ||
Voice voice = notes | ||
.Select(note => note.Sentence?.Voice) | ||
.FirstOrDefault(); | ||
newSentence.SetVoice(voice); | ||
|
||
notes.ForEach(note => note.SetSentence(newSentence)); | ||
newSentence.FitToNotes(); | ||
|
||
// Remove old sentence if not more notes left | ||
List<Sentence> sentencesWithoutNotes = affectedSentences.Where(it => it.Notes.IsNullOrEmpty()).ToList(); | ||
deleteSentencesAction.Execute(sentencesWithoutNotes); | ||
|
||
// Fit sentences to notes | ||
List<Sentence> sentencesWithNotes = affectedSentences.Where(it => !it.Notes.IsNullOrEmpty()).ToList(); | ||
sentencesWithNotes.ForEach(it => it.FitToNotes()); | ||
} | ||
|
||
public void MoveToOwnSentenceAndNotify(List<Note> notes) | ||
{ | ||
MoveToOwnSentence(notes); | ||
songMetaChangeEventStream.OnNext(new SentencesChangedEvent()); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
UltraStar Play/Assets/Scenes/SongEditor/Actions/MoveNoteToOwnSentenceAction.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Oops, something went wrong.