Exemple #1
0
        /// <summary>
        ///     Builds the border.
        /// </summary>
        /// <param name="blocks">The blocks.</param>
        public void BuildBorder(Blocks blocks)
        {
            var startX = MapPoint.X - 2;
            var startY = MapPoint.Y - 2;

            Action <int, int, Foreground.Id> placeBlock
                = (x, y, block) =>
                {
                blocks.Place(startX + x, startY + y, block);
                blocks.Place(startX + x, startY + y, Background.Empty);
                };

            for (var y = 0; y < Height + 4; y++)
            {
                for (var x = 0; x < Width + 4; x++)
                {
                    // Do not remove map sign
                    if (x == 1 && y == 1 &&
                        blocks.At(startX + x, startY + y).Foreground.Block.Id == Foreground.Sign.Block)
                    {
                        continue;
                    }

                    if (x == 0 || x == Width + 3 || y == 0 || y == Height + 3)
                    {
                        placeBlock(x, y, Foreground.Gravity.InvisibleDot);
                    }
                    else if (x == 1 || x == Width + 2 || y == 1 || y == Height + 2)
                    {
                        placeBlock(x, y, Foreground.Basic.Black);
                    }
                }
            }
        }
Exemple #2
0
        public MapSpot(int id, Blocks blocks, int width, int height, ISignFormat signFormat)
        {
            Id     = id;
            Width  = width;
            Height = height;

            var spotWidth  = Width + 4;
            var spotHeight = Height + 4;
            var mapsInRow  = (blocks.Width - 2) / spotWidth;
            var x          = spotWidth * (id % mapsInRow);
            var y          = spotHeight * (id / mapsInRow);

            SignPoint = new Point(x + 2, y + 2);
            MapPoint  = new Point(x + 3, y + 3);

            var block = blocks.At(SignPoint).Foreground.Block;

            if (block.Type != ForegroundType.Sign)
            {
                return;
            }

            MapData mapData;

            if (!signFormat.TryGetMapData(block.Text, "", out mapData))
            {
                return;
            }
            Map = new Map(blocks, new Rectangle(MapPoint.X, MapPoint.Y, Width, Height), mapData.Name, mapData.Creators);
        }
Exemple #3
0
        private void ReadFrom(Blocks source, int startX, int startY)
        {
            background = new BackgroundBlock[Area.Width, Area.Height];
            foreground = new ForegroundBlock[Area.Width, Area.Height];

            for (var x = 0; x < Area.Width; x++)
            {
                for (var y = 0; y < Area.Height; y++)
                {
                    var block = source.At(startX + x, startY + y);
                    background[x, y] = block.Background.Block;
                    foreground[x, y] = block.Foreground.Block;
                }
            }
        }
Exemple #4
0
        /// <summary>
        ///     Builds the map at the specified target.
        /// </summary>
        /// <param name="blocks">Blocks.</param>
        /// <param name="target">Target.</param>
        /// <param name="uploadValidator">
        ///     Block uploading validator. Every time when it returns <code>false</code> no map block is
        ///     uploaded at the resulting position.
        /// </param>
        public void BuildAt(Blocks blocks, Point target, Func <BlocksItem, bool> uploadValidator = null)
        {
            for (var x = 0; x < Area.Width; x++)
            {
                for (var y = 0; y < Area.Height; y++)
                {
                    if (uploadValidator != null && !uploadValidator(blocks.At(target.X + x, target.Y + y)))
                    {
                        continue;
                    }

                    blocks.Place(target.X + x, target.Y + y, background[x, y]);
                    blocks.Place(target.X + x, target.Y + y, foreground[x, y]);
                }
            }
        }
Exemple #5
0
        public MapSpot(int id, Blocks blocks, int width, int height, ISignFormat signFormat)
        {
            Id = id;
            Width = width;
            Height = height;

            var spotWidth = Width + 4;
            var spotHeight = Height + 4;
            var mapsInRow = (blocks.Width - 2)/spotWidth;
            var x = spotWidth*(id%mapsInRow);
            var y = spotHeight*(id/mapsInRow);

            SignPoint = new Point(x + 2, y + 2);
            MapPoint = new Point(x + 3, y + 3);

            var block = blocks.At(SignPoint).Foreground.Block;
            if (block.Type != ForegroundType.Sign)
                return;

            MapData mapData;
            if (!signFormat.TryGetMapData(block.Text, "", out mapData))
                return;
            Map = new Map(blocks, new Rectangle(MapPoint.X, MapPoint.Y, Width, Height), mapData.Name, mapData.Creators);
        }
Exemple #6
0
        /// <summary>
        ///     Builds the border.
        /// </summary>
        /// <param name="blocks">The blocks.</param>
        public void BuildBorder(Blocks blocks)
        {
            var startX = MapPoint.X - 2;
            var startY = MapPoint.Y - 2;

            Action<int, int, Foreground.Id> placeBlock
                = (x, y, block) =>
                {
                    blocks.Place(startX + x, startY + y, block);
                    blocks.Place(startX + x, startY + y, Background.Empty);
                };

            for (var y = 0; y < Height + 4; y++)
            {
                for (var x = 0; x < Width + 4; x++)
                {
                    // Do not remove map sign
                    if (x == 1 && y == 1 &&
                        blocks.At(startX + x, startY + y).Foreground.Block.Id == Foreground.Sign.Block)
                        continue;

                    if (x == 0 || x == Width + 3 || y == 0 || y == Height + 3)
                    {
                        placeBlock(x, y, Foreground.Gravity.InvisibleDot);
                    }
                    else if (x == 1 || x == Width + 2 || y == 1 || y == Height + 2)
                    {
                        placeBlock(x, y, Foreground.Basic.Black);
                    }
                }
            }
        }
 public bool IsBlockAvailable(Point point)
 {
     return(!Blocks.At(point).IsOccupied);
 }