void Save() { XmlData scoreFile=new XmlData(highscorePath, true); XmlNode root=scoreFile.AddRoot("xml"); foreach(KeyValuePair<string, int> pair in userHighscore) { XmlNode score=scoreFile.AddElement(root, "Score"); scoreFile.AddAttribute(score, "name", pair.Key); scoreFile.AddAttribute(score, "value", pair.Value); } scoreFile.Save(); }
public void Save(string filename, bool compressed=true) { XmlData fileData=new XmlData(); #region Root speichern und Attribute anhängen XmlNode root=fileData.AddRoot("map"); fileData.AddAttribute(root, "version", MapVersion); fileData.AddAttribute(root, "orientation", Orientation); fileData.AddAttribute(root, "width", Width); fileData.AddAttribute(root, "height", Height); fileData.AddAttribute(root, "tilewidth", TileWidth); fileData.AddAttribute(root, "tileheight", TileHeight); #endregion #region Properties speichern if(Properties.Count>0) { XmlNode properties=fileData.AddElement(root, "properties"); foreach(Property prop in Properties) { XmlNode propertyXml=fileData.AddElement(properties, "property"); fileData.AddAttribute(propertyXml, "name", prop.Name); fileData.AddAttribute(propertyXml, "value", prop.Value); } } #endregion #region Tilesets foreach(TilesetData tileset in Tilesets) { XmlNode tilesetXml=fileData.AddElement(root, "tileset"); fileData.AddAttribute(tilesetXml, "firstgid", tileset.firstgid); fileData.AddAttribute(tilesetXml, "name", tileset.name); fileData.AddAttribute(tilesetXml, "tilewidth", tileset.tilewidth); fileData.AddAttribute(tilesetXml, "tileheight", tileset.tileheight); XmlNode imageTag=fileData.AddElement(tilesetXml, "image"); fileData.AddAttribute(imageTag, "source", tileset.imgsource); foreach(Tile tile in tileset.Tiles) { XmlNode tileTag=fileData.AddElement(tilesetXml, "tile"); fileData.AddAttribute(tileTag, "id", tile.ID); if(tile.Properties.Count>0) { XmlNode properties=fileData.AddElement(tileTag, "properties"); foreach(Property prop in tile.Properties) { XmlNode propertyXml=fileData.AddElement(properties, "property"); fileData.AddAttribute(propertyXml, "name", prop.Name); fileData.AddAttribute(propertyXml, "value", prop.Value); } } } } #endregion #region Layer foreach(LayerData layer in Layers) { XmlNode layerXml=fileData.AddElement(root, "layer"); fileData.AddAttribute(layerXml, "name", layer.name); fileData.AddAttribute(layerXml, "width", layer.width); fileData.AddAttribute(layerXml, "height", layer.height); XmlNode dataTag=fileData.AddElement(layerXml, "data", ConvertLayerDataToString(layer, compressed)); fileData.AddAttribute(dataTag, "encoding", "base64"); if(compressed) { fileData.AddAttribute(dataTag, "compression", "gzip"); } } #endregion #region Objectlayer foreach(Objectgroup objGroup in ObjectLayers) { XmlNode objGroupXml=fileData.AddElement(root, "objectgroup"); fileData.AddAttribute(objGroupXml, "name", objGroup.Name); fileData.AddAttribute(objGroupXml, "width", objGroup.Width); fileData.AddAttribute(objGroupXml, "height", objGroup.Height); fileData.AddAttribute(objGroupXml, "x", objGroup.X); fileData.AddAttribute(objGroupXml, "y", objGroup.Y); foreach(Object obj in objGroup.Objects) { XmlNode objXml=fileData.AddElement(objGroupXml, "object"); fileData.AddAttribute(objXml, "name", obj.Name); fileData.AddAttribute(objXml, "type", obj.Type); fileData.AddAttribute(objXml, "x", obj.X); fileData.AddAttribute(objXml, "y", obj.Y); fileData.AddAttribute(objXml, "width", obj.Width); fileData.AddAttribute(objXml, "height", obj.Height); XmlNode objPropertiesXml=fileData.AddElement(objXml, "properties"); foreach(Property objProp in obj.Properties) { XmlNode propertyXml=fileData.AddElement(objPropertiesXml, "property"); fileData.AddAttribute(propertyXml, "name", objProp.Name); fileData.AddAttribute(propertyXml, "value", objProp.Value); } } } #endregion fileData.Save(filename); }