Пример #1
0
        public void SaveTileMatrix(TileType[,] map, string path)
        {
            IList<TileRecord> records = new List<TileRecord>();

            int cols = map.GetLength(0);
            int rows = map.GetLength(1);

            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    TileType type = map[x, y];
                    TileRecord record = Mapper.Map<TileType, TileRecord>(type);

                    record.X = x;
                    record.Y = y;
                    records.Add(record);
                }
            }

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            using (Stream stream = File.OpenWrite(path))
            using (TextWriter textWriter = new StreamWriter(stream))
            using (CsvWriter csvWriter = new CsvWriter(textWriter))
            {
                foreach (TileRecord record in records)
                {
                    csvWriter.WriteRecord(record);
                }
            }
        }
Пример #2
0
        public override void SaveTileMap(TileType[,] map, string format)
        {
            int colTotal = map.GetLength(0);
            int rowTotal = map.GetLength(1);

            int mapWidth = (int)Math.Ceiling(colTotal / (double)fragmentWidth);
            int mapHeight = (int)Math.Ceiling(rowTotal / (double)fragmentHeight);

            for (int i = 0; i < mapWidth; i++)
            {
                int x = fragmentWidth * i;
                int w = fragmentWidth;

                if (i == mapWidth - 1)
                {
                    w = colTotal - fragmentWidth * i;
                }

                for (int j = 0; j < mapHeight; j++)
                {
                    int y = fragmentHeight * j;
                    int h = fragmentHeight;

                    if (j == mapHeight - 1)
                    {
                        h = rowTotal - fragmentHeight * j;
                    }

                    string path = string.Format(format, i, j);
                    BuildBitmap(map, x, y, w, h, path);
                }
            }
        }
Пример #3
0
        public virtual void SaveTileMap(TileType[,] map, string path)
        {
            int cols = map.GetLength(0);
            int rows = map.GetLength(1);

            BuildBitmap(map, 0, 0, cols, rows, path);
        }
Пример #4
0
        public void SaveFragmentMetadata(TileType[,] map, string path, IBuilder builder)
        {
            int colTotal = map.GetLength(0);
            int rowTotal = map.GetLength(1);

            int mapWidth = (int)Math.Ceiling(colTotal / (double)fragmentWidth);
            int mapHeight = (int)Math.Ceiling(rowTotal / (double)fragmentHeight);

            using (Stream stream = File.OpenWrite(path))
            using (TextWriter writer = new StreamWriter(stream))
            {
                writer.WriteLine(mapWidth);
                writer.WriteLine(mapHeight);
                writer.WriteLine(builder.Level);
                writer.WriteLine(builder.StartPosition.X);
                writer.WriteLine(builder.StartPosition.Y);
                writer.WriteLine(builder.ScreenTop);
                writer.WriteLine(builder.ScreenLeft);
                writer.WriteLine(builder.ScreenBottom);
                writer.WriteLine(builder.ScreenRight);
            }
        }
Пример #5
0
        protected void BuildBitmap(TileType[,] map, int startX, int startY, int width, int height, string path)
        {
            Bitmap bitmap = new Bitmap(Tile.Width * width, Tile.Height * height);
            Graphics graphics = Graphics.FromImage(bitmap);

            int lengthX = map.GetLength(0); // just for array-bounds sanity check.
            int lengthY = map.GetLength(1); // just for array-bounds sanity check.

            for (int x = startX; x < startX + width && x < lengthX; x++)
            {
                for (int y = startY; y < startY + height && y < lengthY; y++)
                {
                    Fill(graphics, map[x, y], x - startX, y - startY);
                }
            }

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            bitmap.Save(path, ImageFormat.Png);
        }