コード例 #1
0
        protected override void ResizeLayer(int newOriginX, int newOriginY, int newTilesWide, int newTilesHigh)
        {
            int originDiffX = newOriginX - TileOriginX;
            int originDiffY = newOriginY - TileOriginY;

            int maxOriginX = Math.Max(newOriginX, TileOriginX);
            int maxOriginY = Math.Max(newOriginY, TileOriginY);
            int minEndX    = Math.Min(newOriginX + newTilesWide, TileOriginX + TilesWide);
            int minEndY    = Math.Min(newOriginY + newTilesHigh, TileOriginY + TilesHigh);

            int startX = maxOriginX - TileOriginX;
            int startY = maxOriginY - TileOriginY;
            int limitX = minEndX - maxOriginX;
            int limitY = minEndY - maxOriginY;

            TileStack[,] newTiles = new TileStack[newTilesHigh, newTilesWide];

            for (int y = startY; y < limitY; y++)
            {
                for (int x = startX; x < limitX; x++)
                {
                    newTiles[y - originDiffY, x - originDiffX] = _tiles[y, x];
                }
            }

            _tiles = newTiles;
        }
コード例 #2
0
        public TileStack this[int x, int y]
        {
            get
            {
                CheckBoundsFail(x, y);
                return(_tiles[YIndex(y), XIndex(x)]);
            }

            set
            {
                CheckBoundsFail(x, y);

                int xi = XIndex(x);
                int yi = YIndex(y);

                if (_tiles[yi, xi] != null)
                {
                    _tiles[yi, xi].Modified -= TileStackModifiedHandler;
                }

                if (value != null)
                {
                    _tiles[yi, xi]           = new TileStack(value);
                    _tiles[yi, xi].Modified += TileStackModifiedHandler;
                }
                else
                {
                    _tiles[yi, xi] = null;
                }

                OnModified(EventArgs.Empty);
            }
        }
コード例 #3
0
        private string BuildTileBlockString(int xStart, int yStart, int width, int height)
        {
            StringBuilder builder = new StringBuilder();

            int xLimit = Math.Min(xStart + width, TilesWide);
            int yLimit = Math.Min(yStart + height, TilesHigh);

            for (int y = yStart; y < yLimit; y++)
            {
                for (int x = xStart; x < xLimit; x++)
                {
                    TileStack stack = this[x, y];
                    if (stack != null)
                    {
                        builder.Append(x + " " + y + " " + stack.Count + " ");
                        foreach (Tile tile in stack)
                        {
                            builder.Append(Level.TileIndex[tile.Uid] + " ");
                        }
                    }
                }
            }

            if (builder.Length > 0)
            {
                builder.Remove(builder.Length - 1, 1);
            }

            return(builder.ToString());
        }
コード例 #4
0
        /// <summary>
        /// Creates a new <see cref="TileStack"/> containing the same <see cref="Tile"/> objects as <paramref name="stack"/>.
        /// </summary>
        /// <param name="stack">The <see cref="TileStack"/> to copy <see cref="Tile"/> references from.</param>
        public TileStack(TileStack stack)
        {
            if (stack == null)
            {
                stack = new TileStack();
            }

            _tiles = new List <Tile>(stack._tiles);
        }
コード例 #5
0
 public void AddTileStack(int x, int y, TileStack stack)
 {
     if (stack != null)
     {
         foreach (Tile t in stack)
         {
             AddTile(x, y, t);
         }
     }
 }
コード例 #6
0
        public override bool Equals(object obj)
        {
            TileStack other = obj as TileStack;

            if (other != null)
            {
                return(Equals(other));
            }

            return(false);
        }
コード例 #7
0
        protected override void AddTileImpl(int x, int y, Tile tile)
        {
            int xi = XIndex(x);
            int yi = YIndex(y);

            if (_tiles[yi, xi] == null)
            {
                _tiles[yi, xi]           = new TileStack();
                _tiles[yi, xi].Modified += TileStackModifiedHandler;
            }

            _tiles[yi, xi].Remove(tile);
            _tiles[yi, xi].Add(tile);
        }
コード例 #8
0
        public bool Equals(TileStack other)
        {
            if (other == null || _tiles.Count != other.Count)
            {
                return(false);
            }

            for (int i = 0; i < _tiles.Count; i++)
            {
                if (_tiles[i].Uid != other[i].Uid)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #9
0
 public static bool NullOrEmpty(TileStack stack)
 {
     return(stack == null || stack.Count == 0);
 }