public void InitEdges() { if (edges == null) { edges = new List <Edge>(); } int count = vertices.Count; //if (vertices[0] == vertices[vertices.Count-1]) // count--; //In case for last Vertex to be the same as first vertex, we do reduce to count by one to not have a for (int i = 0; i < count - 1; i++) { edges.Add(new Edge(variation.FindVertex(vertices[i]), variation.FindVertex(vertices[i + 1]))); } if (vertices.Count == 4) { edges.Add(new Edge(variation.FindVertex(vertices[3]), variation.FindVertex(vertices[0]))); } }
/// <summary> /// Parse Xml.Floor into our fileformat /// </summary> /// <param name="path">The path we are reading from and into</param> /// <param name="fileStatus">read and write</param> public static void ParseFloor(string path, FileStatus fileStatus, Variation variation, Floor floor) { XmlDocument tempXmlDoc = Globals.xmlDoc; //copy our document, so that if we save the changes it doesnt get defined if (fileStatus == FileStatus.input) { tempXmlDoc = Globals.xmlInput; } foreach (string objectType in Globals.objectTypes) //Iterate through all simObjs (wall, door ...) { XmlNodeList genericNodes = tempXmlDoc.SelectNodes("//floor/layer/" + objectType); { foreach (XmlNode genericNode in genericNodes) { Face tempObj = new Face(genericNode.Attributes["id"].Value, ref variation, SetObjectType(genericNode.Attributes["id"].Value)); XmlNodeList pointNodes = genericNode.ChildNodes; switch (fileStatus) { case FileStatus.read: { List <Vertex> vertices = new List <Vertex>(); //Empty list containing the vertices of the face beeing created foreach (XmlNode pointNode in pointNodes) { Vertex tempVertex = new Vertex(); //Empty Vertex object float x = float.Parse(pointNode.Attributes["x"].Value, Globals.culture); float y = float.Parse(pointNode.Attributes["y"].Value, Globals.culture); if (variation.FindVertex(x, y) != null) //Check if thge vertex was already created { vertices.Add(variation.FindVertex(x, y)); //if so, add the vertex to the list } else { tempVertex = new Vertex(x, y); variation.AddVertex(tempVertex); vertices.Add(tempVertex); //ifnot, create a new vertex and add it to the list } } Face testObj = new Face(genericNode.Attributes["id"].Value, ref variation, SetObjectType(genericNode.Attributes["id"].Value)); testObj.AddVertex(vertices); //add the vertex list to our tempObj variation.SetFacesVertices(testObj); //setup the face reference for the vertices in the globals.vertices floor.AddFace(testObj); //add the face to our floors facelist break; } case FileStatus.write: { int i = 0; foreach (XmlNode pointNode in pointNodes) { pointNode.Attributes["x"].Value = floor.GetFace(genericNode.Attributes["id"].Value).GetVertices()[i].ToVector2().X.ToString().Replace(",", "."); pointNode.Attributes["y"].Value = floor.GetFace(genericNode.Attributes["id"].Value).GetVertices()[i].ToVector2().Y.ToString().Replace(",", "."); i++; } break; } case FileStatus.input: { foreach (Face face in floor.GetFaces()) { if (face.GetFaceName() == genericNode.Attributes["id"].Value) { floor.AddFacesToMove(); foreach (XmlNode pointNode in pointNodes) { if (pointNode.Attributes["Type"].Value == "Move") { float x = float.Parse(pointNode.Attributes["x"].Value, Globals.culture); float y = float.Parse(pointNode.Attributes["y"].Value, Globals.culture); face.SetMoveVector(new Vector2(x, y)); } if (pointNode.Attributes["Type"].Value == "Scale") { float scaleFactor = float.Parse(pointNode.Attributes["factor"].Value, Globals.culture); face.SetScale(scaleFactor); } } } } break; } } } } } if (fileStatus == FileStatus.write) { Globals.xmlDoc.Save(Path.Combine(path + "\\" + floor.GetID())); Console.WriteLine("Successfully created and updated: " + path); //Console.ReadLine(); } }