示例#1
0
        public virtual XmlElement asXML(XmlDocument doc)
        {
            XmlElement element = doc.CreateElement("gameItem");

            switch (polygonType)
            {
            case PhysicsPolygonType.Rectangle:
                element.AppendChild(XMLUtil.asXMLVector2(doc, sideLengths, "sideLengths"));
                break;

            case PhysicsPolygonType.Circle:
                XMLUtil.addElementValue(doc, element, "radius", radius.ToString());
                break;
            }
            XMLUtil.addElementValue(doc, element, "name", name);
            XMLUtil.addElementValue(doc, element, "location", loc.X + "," + loc.Y);
            XMLUtil.addElementValue(doc, element, "polygonType", polygonType.ToString());
            XMLUtil.addElementValue(doc, element, "width", width.ToString());
            XMLUtil.addElementValue(doc, element, "weight", weight.ToString());
            XMLUtil.addElementValue(doc, element, "startdepth", startdepth.ToString());
            XMLUtil.addElementValue(doc, element, "immovable", immovable.ToString());
            element.SetAttribute("guid", guid.ToString());
            element.SetAttribute("rotation", rotation.ToString());
            return(element);
        }
示例#2
0
        public virtual XmlElement asXML(XmlNode parentNode)
        {
            XmlElement element         = parentNode.OwnerDocument.CreateElement("gameItem"),
                       locationNode    = parentNode.OwnerDocument.CreateElement("loc"),
                       nameNode        = parentNode.OwnerDocument.CreateElement("name"),
                       radiusNode      = parentNode.OwnerDocument.CreateElement("radius"),
                       startDepthNode  = parentNode.OwnerDocument.CreateElement("startdepth"),
                       weightNode      = parentNode.OwnerDocument.CreateElement("weight"),
                       widthNode       = parentNode.OwnerDocument.CreateElement("width"),
                       immovableNode   = parentNode.OwnerDocument.CreateElement("immovable"),
                       polygonTypeNode = parentNode.OwnerDocument.CreateElement("polygonType"),
                       verticesNode    = parentNode.OwnerDocument.CreateElement("vertices");

            element.SetAttribute("guid", guid.ToString());
            nameNode.InnerText        = name;
            radiusNode.InnerText      = radius.ToString();
            startDepthNode.InnerText  = startdepth.ToString();
            weightNode.InnerText      = weight.ToString();
            widthNode.InnerText       = width.ToString();
            immovableNode.InnerText   = immovable.ToString();
            polygonTypeNode.InnerText = polygonType.ToString();
            locationNode.InnerText    = loc.X + "," + loc.Y;
            //if (vertices != null)
            //    foreach (Vector2 vertex in vertices)
            //        verticesNode.AppendChild(XMLUtil.asXMLVector2(verticesNode, vertex, "vertex"));
            switch (polygonType)
            {
            case PhysicsPolygonType.Rectangle:
                element.AppendChild(XMLUtil.asXMLVector2(element, sideLengths, "sideLengths"));
                break;

            case PhysicsPolygonType.Circle:
                element.AppendChild(radiusNode);
                break;

            case PhysicsPolygonType.Polygon:
                element.AppendChild(verticesNode);
                break;
            }
            element.AppendChild(locationNode);
            element.AppendChild(nameNode);
            element.AppendChild(startDepthNode);
            element.AppendChild(weightNode);
            element.AppendChild(widthNode);
            element.AppendChild(immovableNode);
            element.Attributes.GetNamedItem("rotation").Value = rotation.ToString();
            return(element);
        }