Example #1
0
        public TCell this[int x, int y]
        {
            get
            {
                CheckLocation(ref x, ref y);

                TGridBlock block = null;
                ShortPoint blockLocation = default(ShortPoint);
                int        cellX, cellY;
                int        blockSize = BlockSize;

                GridBlock.GetBlockCellLocation(ref x, ref y, ref blockSize, out blockLocation, out cellX, out cellY);

                if (Blocks.TryGetItem(blockLocation, out block))
                {
                    return(block.GetCell(cellX, cellY));
                }

                return(default(TCell));
            }

            set
            {
                CheckLocation(ref x, ref y);

                TGridBlock block = null;
                ShortPoint blockLocation = default(ShortPoint);
                int        tileX, tileY;
                int        blockSize = BlockSize;

                GridBlock.GetBlockCellLocation(ref x, ref y, ref blockSize, out blockLocation, out tileX, out tileY);

                if (!Blocks.TryGetItem(blockLocation, out block))
                {
                    if (CellEqualityComparer.Equals(value, default(TCell)))
                    {
                        return;
                    }
                    block = CreateBlock(blockLocation);
                    AddBlock(block);
                }

                var currentValue = block.GetCell(tileX, tileY);

                if (block.SetCell(tileX, tileY, value))
                {
                    OnCellContentChanged(tileX, tileY, block, currentValue, value);
                }
            }
        }