示例#1
0
        public static MapContainer Load(Stream stream, out string error)
        {
            var dataFile = DataFileReader.Read(stream, out error);

            if (dataFile == null)
            {
                return(null);
            }
            return(new MapContainer(dataFile));
        }
示例#2
0
        public static MapContainer Load(Stream stream, out string error)
        {
            var dataFile = DataFileReader.Read(stream, out error);
            var item     = dataFile?.FindItem <MapItemVersion>(MapItemTypes.Version, 0);

            if (item == null || item.Version != 1)
            {
                return(null);
            }

            dataFile.GetType(MapItemTypes.Group, out var groupsStart, out var groupsNum);
            dataFile.GetType(MapItemTypes.Layer, out var layersStart, out var layersNum);

            for (var g = 0; g < groupsNum; g++)
            {
                var group = dataFile.GetItem <MapItemGroup>(groupsStart + g, out _, out _);
                for (var l = 0; l < group.NumLayers; l++)
                {
                    var layer = dataFile.GetItem <MapItemLayer>(layersStart + group.StartLayer + l, out _, out _);
                    if (layer.Type == LayerType.Tiles)
                    {
                        var tilemap = dataFile.GetItem <MapItemLayerTilemap>(
                            layersStart + group.StartLayer + l,
                            out _,
                            out _
                            );

                        if (tilemap.Version > 3)
                        {
                            var tiles      = new Tile[tilemap.Width * tilemap.Height];
                            var savedTiles = dataFile.GetData <Tile[]>(tilemap.Data);
                            var i          = 0;
                            var sIndex     = 0;

                            while (i < tilemap.Width * tilemap.Height)
                            {
                                for (var counter = 0;
                                     counter <= savedTiles[sIndex].Skip && i < tilemap.Width * tilemap.Height;
                                     counter++)
                                {
                                    tiles[i]        = savedTiles[sIndex];
                                    tiles[i++].Skip = 0;
                                }

                                sIndex++;
                            }

                            dataFile.ReplaceData <Tile[]>(tilemap.Data, tiles);
                        }
                    }
                }
            }

            return(new MapContainer(dataFile));
        }