/// <summary> /// Parses JSON data to a Sound_Data class instance. /// </summary> Sound_Data Parse_Sound(Sound_Data.Sound_Type sound_type, string raw_sound_data) { SimpleJSON.JSONNode raw = SimpleJSON.JSON.Parse(raw_sound_data); Sound_Data new_sound = new Sound_Data { Type = sound_type }; // Add Sound instances foreach (SimpleJSON.JSONNode element in raw[sound_type.ToString()][0]) { string[] tokens = Utils.Split(element, '*'); string notes = ""; if (tokens.Length >= 3) { notes = tokens[2]; } Sound_Data.Instance instance = new Sound_Data.Instance { Fire_Time = float.Parse(tokens[0], CultureInfo.InvariantCulture), Volume = float.Parse(tokens[1], CultureInfo.InvariantCulture), Note = notes }; if (!new_sound.Instances.Exists(a => a.Fire_Time == instance.Fire_Time)) { new_sound.Instances.Add(instance); } } // Add Loop instances foreach (SimpleJSON.JSONNode element in raw[sound_type.ToString()][1]) { string[] tokens = Utils.Split(element, '*'); Sound_Data.Loop loop = new Sound_Data.Loop { Start_Time = float.Parse(tokens[0], CultureInfo.InvariantCulture), End_Time = float.Parse(tokens[1], CultureInfo.InvariantCulture), Repetitions = uint.Parse(tokens[2]) }; if (!new_sound.Loops.Exists(a => a.Start_Time == loop.Start_Time || a.End_Time == loop.End_Time)) { new_sound.Loops.Add(loop); } } return(new_sound); }