private void dropExamplesValueChanged() { turtleData tData = exampleTurtleDatas[dropGivenExamples.value]; if (tData.drawSymbols != null) { inputDrawSymbols.text = new string(tData.drawSymbols); } else { inputDrawSymbols.text = ""; } if (tData.leafSymbol != null) { inputLeafSymbol.text = new string(tData.leafSymbol); } else { inputLeafSymbol.text = ""; } if (tData.flowerSymbol != null) { inputFlowerSymbol.text = new string(tData.flowerSymbol); } else { inputFlowerSymbol.text = ""; } if (tData.leafImgPath != null) { dropLeafImgs.value = leafPaths.IndexOf(tData.leafImgPath); } else { dropLeafImgs.value = 0; } if (tData.leafImgPath != null) { dropFlowerImgs.value = flowerPaths.IndexOf(tData.flowerImgPath); } else { dropFlowerImgs.value = 0; } inputAxiom.text = tData.axiom; inputAngle.text = tData.angle.ToString(); for (int i = 0; i < ruleSize; i++) { if (i < tData.rules.Length) { inputRules[i].text = tData.rules[i]; } else { inputRules[i].text = ""; } } inputIteration.text = tData.interation.ToString(); }
public static void ParseRules(string content, out Dictionary <string, turtleData> ruleDic) { ruleDic = new Dictionary <string, turtleData>(); var datas = content.Split('}'); foreach (string rawData in datas) { string key = ""; turtleData td = new turtleData(); var lines = rawData.Split('\n'); foreach (string rawLine in lines) { string line = rawLine.Trim(); if (line == "{") { continue; } if (line.Length == 0) { continue; } else if (line.Length == 1 && line[0] == '\r') { continue; } else if (line[0] == '/' && line[1] == '/') { continue; } string value; if (line.IndexOf("name") != -1) { value = line.Substring(line.IndexOf("=") + 1); value = value.Trim(); key = value; } else if (line.IndexOf("drawSymbols") != -1) { value = line.Substring(line.IndexOf("=") + 1); value = value.Trim(); td.drawSymbols = value.ToCharArray(); } else if (line.IndexOf("leafSymbol") != -1) { value = line.Substring(line.IndexOf("=") + 1); value = value.Trim(); td.leafSymbol = value.ToCharArray(); } else if (line.IndexOf("leafImgPath") != -1) { value = line.Substring(line.IndexOf("=") + 1); value = value.Trim(); td.leafImgPath = value; } else if (line.IndexOf("flowerSymbol") != -1) { value = line.Substring(line.IndexOf("=") + 1); value = value.Trim(); td.flowerSymbol = value.ToCharArray(); } else if (line.IndexOf("flowerImgPath") != -1) { value = line.Substring(line.IndexOf("=") + 1); value = value.Trim(); td.flowerImgPath = value; } else if (line.IndexOf("axiom") != -1) { value = line.Substring(line.IndexOf("=") + 1); value = value.Trim(); td.axiom = value; } else if (line.IndexOf("angle") != -1) { value = line.Substring(line.IndexOf("=") + 1); value = value.Trim(); td.angle = float.Parse(value); } else if (line.IndexOf("rules") != -1) { value = line.Substring(line.IndexOf(":") + 1); value = value.Trim(); td.rules = value.Split(';'); } else if (line.IndexOf("interation") != -1) { value = line.Substring(line.IndexOf("=") + 1); value = value.Trim(); td.interation = Convert.ToInt32(value); } } if (key != "" && !ruleDic.ContainsKey(key)) { ruleDic.Add(key, td); } } }