Esempio n. 1
0
        public Map Load(System.IO.Stream stream)
        {
            XmlTextReader xmlReader = new XmlTextReader(stream);

            xmlReader.WhitespaceHandling = WhitespaceHandling.None;

            XmlHelper xmlHelper = new XmlHelper(xmlReader);

            xmlHelper.AdvanceDeclaration();
            xmlHelper.AdvanceStartElement("Map");
            string mapId = xmlHelper.GetAttribute("Id");
            Map    map   = new Map(mapId);

            xmlHelper.AdvanceStartElement("Description");
            string mapDescription = xmlHelper.GetCData();

            xmlHelper.AdvanceEndElement("Description");
            map.Description = mapDescription;

            LoadTileSheets(xmlHelper, map);

            LoadLayers(xmlHelper, map);

            LoadProperties(xmlHelper, map);

            return(map);
        }
        public Map Load(Stream stream)
        {
            XmlTextReader xmlReader = new XmlTextReader(stream);

            xmlReader.WhitespaceHandling = WhitespaceHandling.None;

            XmlHelper xmlHelper = new XmlHelper(xmlReader);

            xmlHelper.AdvanceDeclaration();
            xmlHelper.AdvanceStartElement("map");

            string orientation = xmlHelper.GetAttribute("orientation");

            if (orientation != "orthogonal")
            {
                throw new Exception("Only orthogonal Tiled maps are supported.");
            }

            int mapWidth  = xmlHelper.GetIntAttribute("width");
            int mapHeight = xmlHelper.GetIntAttribute("height");

            int tileWidth  = xmlHelper.GetIntAttribute("tilewidth");
            int tileHeight = xmlHelper.GetIntAttribute("tileheight");

            Map map = new Map();

            while (true)
            {
                XmlNodeType xmlNodeType = xmlHelper.AdvanceNode();
                if (xmlNodeType == XmlNodeType.EndElement)
                {
                    break;
                }

                if (xmlReader.Name == "properties")
                {
                    LoadProperties(xmlHelper, map);
                }
                else if (xmlReader.Name == "tileset")
                {
                    LoadTileSet(xmlHelper, map);
                }
                else if (xmlReader.Name == "layer")
                {
                    LoadLayer(xmlHelper, map);
                }
                else
                {
                    xmlHelper.SkipToEndElement(xmlReader.Name);
                }
            }

            // try to obtain map description via custom property
            if (map.Properties.ContainsKey("@Description"))
            {
                map.Description = map.Properties["@Description"];
            }

            return(map);
        }
Esempio n. 3
0
        public Map Load(Stream stream)
        {
            // not implemented yet
            throw new Exception("This format is not supported yet");

            XmlTextReader xmlReader = new XmlTextReader(stream);

            xmlReader.WhitespaceHandling = WhitespaceHandling.None;

            XmlHelper xmlHelper = new XmlHelper(xmlReader);

            xmlHelper.AdvanceDeclaration();
            xmlHelper.AdvanceStartElement("map");

            string orientation = xmlHelper.GetAttribute("orientation");

            if (orientation != "orthogonal")
            {
                throw new Exception("Only orthogonal Tiled maps are supported.");
            }

            int mapWidth  = xmlHelper.GetIntAttribute("width");
            int mapHeight = xmlHelper.GetIntAttribute("height");

            int tileWidth  = xmlHelper.GetIntAttribute("tilewidth");
            int tileHeight = xmlHelper.GetIntAttribute("tileheight");

            Map map = new Map();

            while (true)
            {
                XmlNodeType xmlNodeType = xmlHelper.AdvanceNode();
                if (xmlNodeType == XmlNodeType.EndElement)
                {
                    break;
                }

                if (xmlReader.Name == "tileset")
                {
                    LoadTileSet(xmlHelper, map);
                }
                else if (xmlReader.Name == "layer")
                {
                    LoadLayer(xmlHelper, map);
                }
            }

            LoadProperties(xmlHelper, map);

            return(map);
        }