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; }
Command parseCommand() { var command = new Command(); foreach (string data in fileData) { if (data[0] == Command.MapPrefix) { int bar = int.Parse(data.Substring(1, 3)); int firstColon = data.IndexOf(":"); int secondColon = data.LastIndexOf(":"); string rhythm = data.Substring(data.LastIndexOf(":") + 1); string commandType = data.Substring(4, 2); switch (commandType) { case Command.Channel.BPMSetter: var bpm = new BPM(); int valueLength = (secondColon - 1) - firstColon; bpm.Bar = bar; bpm.Rhythm = rhythm; bpm.Value = double.Parse(data.Substring(firstColon + 1, valueLength)); command.BPMs.Add(bpm); break; case Command.Channel.MeasureSetter: var measure = new Measure(); int numerLength = (data.IndexOf("/")- 1) - firstColon ; int denomLength = (secondColon - 1) - data.IndexOf("/"); measure.Bar = bar; measure.Rhythm = rhythm; measure.Numer = int.Parse(data.Substring(firstColon + 1, numerLength)); measure.Denom = int.Parse(data.Substring(data.IndexOf("/") + 1, denomLength)); command.Measures.Add(measure); break; } } } return command; }
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"); } } }