Beispiel #1
0
        public static IList<MapLayer> LoadMapLayers(XElement map, TileIdLoader tileIdLoader)
        {
            if (map == null)
            {
                throw new ArgumentNullException("map");
            }

            if (tileIdLoader == null)
            {
                throw new ArgumentNullException("tileIdLoader");
            }

            IList<MapLayer> layers = new List<MapLayer>();

            foreach (XElement layer in map.Elements("layer"))
            {
                MapLayer mapLayer = GetLayerMetadata(layer);

                tileIdLoader.LoadLayer(mapLayer, layer.Element("data"));

                layers.Add(mapLayer);
            }

            return layers;
        }
Beispiel #2
0
        public static TileMap Parse(XDocument document)
        {
            XElement map = document.Element("map");

            if (map == null)
            {
                throw new InvalidDataException("Missing 'map' element");
            }

            AssertRequirements(map);

            TileMapSize tileMapSize = TileMapSizeLoader.LoadTileMapSize(map);

            IList<TileSet> tileSets = TileSetLoader.LoadTileSets(map.Elements("tileset"));

            TileIdLoader tileIdLoader = new TileIdLoader(tileMapSize);

            IList<MapLayer> layers = MapLayerLoader.LoadMapLayers(map, tileIdLoader);

            return new TileMap(tileMapSize, tileSets, layers);
        }