Exemplo n.º 1
0
        /// <summary>
        /// Runs a flood-fill algorithm with the passed co-ordinates of the root.
        /// Returns an enumerable list of points based on the results.
        /// </summary>
        /// <param name="tileset">Tileset to replace with.</param>
        /// <param name="selection">Tile selection to replace with.</param>
        /// <param name="x">X co-ordinate of the root tile.</param>
        /// <param name="y">Y co-ordinate of the root tile.</param>
        /// <returns>An enumerable list of points.</returns>
        public List<Point> FillCache(Tileset tileset, PointSelection selection, int x, int y)
        {
            if (x < 0 || x > Width - 1 || y < 0 || y > Height - 1) return null;

            _tileCache = new List<Point>();

            _cacheMap = new FillTile[Width, Height];
            for (var x2 = 0; x2 < Width; x2++)
            {
                for (var y2 = 0; y2 < Height; y2++)
                {
                    var tile = SelectedLayer.Tiles[x2, y2];
                    _cacheMap[x2, y2] = new FillTile(tile.Tileset, tile.SrcX, tile.SrcY, tile.Terrain);
                }
            }

            _tileChecked = new bool[Width, Height];

            var point = selection.GetTopLeftMostPoint();
            var replacementTile = new FillTile(tileset.ID, point.X, point.Y, 0);
            var currTile = GetFillCacheTile(x, y, replacementTile);
            var originalFillTile = new FillTile(currTile.Tileset, currTile.X, currTile.Y, currTile.Terrain);

            FillCacheTiles(originalFillTile, replacementTile, x, y);

            return _tileCache;
        }
Exemplo n.º 2
0
        public void Fill(Tileset tileset, PointSelection selection, int x, int y)
        {
            if (x < 0 || x > Width - 1 || y < 0 || y > Height - 1) return;

            using (UndoRedoArea.Start("Fill Tool"))
            {
                _tileChecked = new bool[Width, Height];
                _tileMap = SelectedLayer.Tiles;
                _tilesToCache = new List<Point>();

                var tile = selection.GetTopLeftMostPoint();
                var replacementTile = new FillTile(tileset.ID, tile.X, tile.Y, 0);
                var currTile = GetFillTile(x, y, replacementTile);
                var originalFillTile = new FillTile(currTile.Tileset, currTile.SrcX, currTile.SrcY, currTile.Terrain);

                FillTiles(currTile, originalFillTile, replacementTile);

                UndoRedoArea.Commit();
            }
        }