/// <summary> /// This method will add a note to the list of custom notes /// </summary> public static void AddNote(Note note, Note newNote) { if (!CheckNoteExists(note, newNote)) { CustomNotes.Add(note, newNote); } else { throw new AutoplayerCustomNoteException("Trying to add already existing note"); } }
/// <summary> /// This method will set a new note to the value of a specified note from the list of custom notes /// </summary> public static void ChangeNote(Note note, Note newNote) { if (CheckNoteExists(note)) { CustomNotes.Remove(note); CustomNotes.Add(note, newNote); } else { throw new AutoplayerCustomNoteException("Trying to modify non-existent note"); } }
/// <summary> /// This method will load a song and its settings from a file at the "path" variable's destination /// This loading method handles all previous save formats for backwards compatibility /// </summary> public static void LoadSong(string path) { Song.Clear(); bool errorWhileLoading = true; StreamReader sr = new StreamReader(path); string firstLine = sr.ReadLine(); #region 2.1+ save format if (SupportedVersionsSave.Contains(firstLine)) { if (sr.ReadLine() == "DELAYS") { int delayCount = 0; if (int.TryParse(sr.ReadLine(), out delayCount) && delayCount > 0) { for (int i = 0; i < delayCount; i++) { char delayChar; int delayTime = 0; if (char.TryParse(sr.ReadLine(), out delayChar)) { if (int.TryParse(sr.ReadLine(), out delayTime)) { Delays.Add(new Delay(delayChar, delayTime)); } } } } } if (sr.ReadLine() == "CUSTOM NOTES") { int noteCount = 0; if (int.TryParse(sr.ReadLine(), out noteCount) && noteCount > 0) { for (int i = 0; i < noteCount; i++) { char origNoteChar; char replaceNoteChar; if (char.TryParse(sr.ReadLine(), out origNoteChar)) { if (char.TryParse(sr.ReadLine(), out replaceNoteChar)) { WindowsInput.Native.VirtualKeyCode vkOld; WindowsInput.Native.VirtualKeyCode vkNew; try { VirtualDictionary.TryGetValue(origNoteChar, out vkOld); VirtualDictionary.TryGetValue(replaceNoteChar, out vkNew); if (vkOld == 0 || vkNew == 0) { return; } } catch (ArgumentNullException) { return; } CustomNotes.Add(new Note(origNoteChar, vkOld, char.IsUpper(origNoteChar)), new Note(replaceNoteChar, vkNew, char.IsUpper(replaceNoteChar))); } } } } } if (sr.ReadLine() == "SPEEDS") { int normalSpeed, fastSpeed; int.TryParse(sr.ReadLine(), out normalSpeed); int.TryParse(sr.ReadLine(), out fastSpeed); DelayAtNormalSpeed = normalSpeed; DelayAtFastSpeed = fastSpeed; } if (sr.ReadLine() == "NOTES") { int noteCount = 0; if (int.TryParse(sr.ReadLine(), out noteCount) && noteCount > 0) { AddNotesFromString(sr.ReadToEnd()); } errorWhileLoading = false; } } #endregion #region 2.0 save format (for backwards compatibility) if (firstLine == "DELAYS") { int delayCount = 0; if (int.TryParse(sr.ReadLine(), out delayCount) && delayCount > 0) { for (int i = 0; i < delayCount; i++) { char delayChar; int delayTime = 0; if (char.TryParse(sr.ReadLine(), out delayChar)) { if (int.TryParse(sr.ReadLine(), out delayTime)) { Delays.Add(new Delay(delayChar, delayTime)); } } } } if (sr.ReadLine() == "NOTES") { int noteCount = 0; if (int.TryParse(sr.ReadLine(), out noteCount) && noteCount > 0) { AddNotesFromString(sr.ReadToEnd()); } errorWhileLoading = false; } } #endregion #region 1.2.2 save format (For backwards compatibility) else if (firstLine == "CUSTOM DELAYS") { int delayCount = 0; if (int.TryParse(sr.ReadLine(), out delayCount)) { if (sr.ReadLine() == "NORMAL DELAY") { if (int.TryParse(sr.ReadLine(), out delayAtNormalSpeed)) { Delays.Add(new Delay(' ', DelayAtNormalSpeed)); if (sr.ReadLine() == "FAST DELAY") { if (int.TryParse(sr.ReadLine(), out delayAtFastSpeed)) { if (delayCount != 0) { for (int i = 0; i < delayCount; i++) { int customDelayIndex = 0; int customDelayTime = 0; char customDelayChar; if (sr.ReadLine() == "CUSTOM DELAY INDEX") { if (int.TryParse(sr.ReadLine(), out customDelayIndex)) { if (sr.ReadLine() == "CUSTOM DELAY CHARACTER") { if (char.TryParse(sr.ReadLine(), out customDelayChar)) { if (sr.ReadLine() == "CUSTOM DELAY TIME") { if (int.TryParse(sr.ReadLine(), out customDelayTime)) { Delays.Add(new Delay(customDelayChar, customDelayTime)); } } } } } } } } if (sr.ReadLine() == "NOTES") { AddNotesFromString(sr.ReadToEnd()); errorWhileLoading = false; } } } } } } } #endregion #region 1.0 save format (For backwards compatibility) else if (firstLine == "NORMAL DELAY") { if (int.TryParse(sr.ReadLine(), out delayAtNormalSpeed)) { if (sr.ReadLine() == "FAST DELAY") { if (int.TryParse(sr.ReadLine(), out delayAtFastSpeed)) { if (sr.ReadLine() == "NOTES") { AddNotesFromString(sr.ReadToEnd()); errorWhileLoading = false; } } } } } #endregion sr.Close(); if (errorWhileLoading) { LoadFailed?.Invoke(); throw new AutoplayerLoadFailedException("No compatible save format was found!"); } LoadCompleted?.Invoke(); }