public void startPlayingBack(string Filename) { _history = new List <bool[]>(); string x = FlxU.loadFromDevice(Filename); string[] y = x.Split('\n'); int line = 0; foreach (var item in y) { string[] item1 = item.Split(','); line++; if (item1.Length == 14) { try { _history.Add(new bool[] { bool.Parse(item1[0]), bool.Parse(item1[1]), bool.Parse(item1[2]), bool.Parse(item1[3]), bool.Parse(item1[4]), bool.Parse(item1[5]), bool.Parse(item1[6]), bool.Parse(item1[7]), bool.Parse(item1[8]), bool.Parse(item1[9]), bool.Parse(item1[10]), bool.Parse(item1[11]), bool.Parse(item1[12]), bool.Parse(item1[13]) }); } catch (Exception) { Console.WriteLine("History Not Added " + item1.Length + " -- " + item1[1]); } } } //_rec = Recording.Playback; control = Controls.file; frameCount = 0; }
/// <summary> /// Loads animations from a Graphics Gale .csv with the values: "Name","Delay(1/60)","Column","Row" /// </summary> /// <param name="file">addAnimationsFromGraphicsGaleCSV("content/fourchambers/heart_16x16.csv", null, null, false);</param> /// <param name="Looped">A List of animations that should loop</param> /// <param name="NotLooped">A List of animations that will not loop</param> /// <param name="DefaultLoopingValue">A default looping.</param> public void addAnimationsFromGraphicsGaleCSV(string file, List <string> Looped, List <string> NotLooped, bool DefaultLoopingValue) { //Console.WriteLine("Loading: " + file); string anims = FlxU.loadFromDevice(file); string[] split = anims.Split('\n'); Dictionary <string, List <int> > animations = new Dictionary <string, List <int> >(); Dictionary <string, int> frameRates = new Dictionary <string, int>(); foreach (var item in split) { //Console.WriteLine(item); if (item.StartsWith("\"Name")) { // initialize. } else { string[] elements = item.Split(','); string name = elements[0].Substring(1, elements[0].Length - 2); string fr = elements[1].Substring(1, elements[1].Length - 2); string col = elements[2].Substring(1, elements[2].Length - 2); string row = elements[3].Substring(1, elements[3].Length - 3); //Console.WriteLine("Name {0} Frame {1} Col {2} Row {3} ", name,fr,col,row); // Assumes you output in grids of 10 across. int position = Convert.ToInt16(col) + (10 * Convert.ToInt16(row)); int frameRate = 31 - Convert.ToInt16(fr); //Console.WriteLine("n: {0} fr: {1} pos: {2}x{3}, Frame: {4}", name, frameRate, col, row, position); if (animations.ContainsKey(name)) { List <int> o = animations[name]; o.Add(position); //animations.Add(name, new int[] { Convert.ToInt16(elements[1]) }); //Convert.ToInt16( elements[0] ) animations[name] = o; } else { //animations.Add(name, new int[] { Convert.ToInt16(elements[1]) }); //Convert.ToInt16( elements[0] ) animations[name] = new List <int>() { position }; } frameRates[name] = frameRate; } } foreach (var xx in animations) { //Console.WriteLine("--> item {0} value {1}", xx.Key, xx.Value.ToArray().ToString() ); //foreach (var xxx in xx.Value) //{ // Console.WriteLine(xxx); //} if (Looped != null) { if (Looped.Contains(xx.Key)) { addAnimation(xx.Key, xx.Value.ToArray(), frameRates[xx.Key], true); } else { addAnimation(xx.Key, xx.Value.ToArray(), frameRates[xx.Key], DefaultLoopingValue); } } if (NotLooped != null) { if (NotLooped.Contains(xx.Key)) { addAnimation(xx.Key, xx.Value.ToArray(), frameRates[xx.Key], false); } else { addAnimation(xx.Key, xx.Value.ToArray(), frameRates[xx.Key], DefaultLoopingValue); } } else { addAnimation(xx.Key, xx.Value.ToArray(), frameRates[xx.Key], DefaultLoopingValue); } } }