public void Load(string musicId, Difficulty difficulty) { string line; fileData = new List<string>(); setFileInfo(musicId, difficulty); using (FileStream fs = new FileStream(MapFilePath, FileMode.Open)) using (StreamReader sr = new StreamReader(fs, Encoding.UTF8)) { while ((line = sr.ReadLine()) != null) { if (line == string.Empty) continue; fileData.Add(line); } } Header = parseHeader(); Notes = parseNotes(); Command = parseCommand(); RhythmsZeroPadding(); this.JacketFilePath = Application.dataPath + "/Jackets/" + Header.JacketFile; this.MusicFilePath = Application.dataPath + "/Musics/" + Header.MusicFile; }
Header parseHeader() { var header = new Header(); foreach (string data in fileData) { if (data[0] == Header.MapPrefix) { string key = data.Substring(1, data.IndexOf(":") - 1); string value = data.Substring(data.IndexOf(":") + 1); switch (key) { case "genre": header.Genre = value; break; case "title": header.Title = value; break; case "music_artist": header.MusicArtist = value; break; case "map_creator": header.MapCreator = value; break; case "min_bpm": header.MinBPM = double.Parse(value); break; case "max_bpm": header.MaxBPM = double.Parse(value); break; case "play_level": header.PlayLevel = int.Parse(value); break; case "offset": header.Offset = double.Parse(value); break; case "music_file": header.MusicFile = value; break; case "jacket_file": header.JacketFile = value; break; case "movie_file": header.MovieFile = value; break; } } } return header; }
public void Save(Header header, Command command, List<Note> notes, string musicId, Difficulty difficulty) { setFileInfo(musicId, difficulty); using (FileStream fs = new FileStream(MapFilePath, FileMode.Create)) using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) { sw.Write(header); sw.Write(command); foreach (var noteData in notes) { sw.Write(noteData + "\n"); } } }