コード例 #1
0
ファイル: MapDefinition.cs プロジェクト: jo215/Iso
        /// <summary>
        /// Reads a map from the given stream.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="iso"></param>
        /// <returns></returns>
        public static MapDefinition ReadMap(TextReader stream, Isometry iso)
        {
            var newMap = new MapDefinition(null, iso, _baseContentDir);
            
            if (stream == null)
                return newMap;
            
            stream.ReadLine(); // <Map>
            newMap.Iso.Style = (IsometricStyle)Enum.Parse(typeof(IsometricStyle), stream.ReadLine());
            newMap.ClearAllCells(int.Parse(stream.ReadLine()), int.Parse(stream.ReadLine()));
            newMap.TileWidth = int.Parse(stream.ReadLine());
            newMap.TileHeight = int.Parse(stream.ReadLine());
            stream.ReadLine(); // </Map>

            stream.ReadLine(); // <TileDictionary>
            var requiredTiles = new List<ZTile>();
            var line = stream.ReadLine();
            while (!line.Equals("</TileDictionary>"))
            {
                requiredTiles.Add(new ZTile("D:\\workspace\\BaseGame\\" + line));

                line = stream.ReadLine();
            }
            Console.WriteLine(requiredTiles[0].Bitmaps.Count());

            stream.ReadLine(); // <Cells>
            for (var x = 0; x < newMap.Cells.GetLength(0); x++)
                for (var y = 0; y < newMap.Cells.GetLength(1); y++)
                {
                    newMap.Cells[x, y] = MapCell.FromStream(stream, requiredTiles, newMap, new Point(x,y));
                }
            stream.ReadLine(); // </Cells>

            //  Remake Parent links
            for (var x = 0; x < newMap.Cells.GetLength(0); x++)
                for (var y = 0; y < newMap.Cells.GetLength(1); y++)
                {
                    if (newMap.Cells[x, y].TempPoint.X != -1)
                    {
                        newMap.Cells[x, y].ParentCell = newMap.Cells[newMap.Cells[x, y].TempPoint.X, newMap.Cells[x, y].TempPoint.Y];
                    }
                }
            return newMap;
        }