コード例 #1
0
        public void AddTileOutOfBounds()
        {
            TileGridLayer layer = new MultiTileGridLayer("tiles", 16, 16, 10, 10);

            try {
                layer.AddTile(-1, 2, _tile1);
                Assert.Fail();
            }
            catch { }

            try {
                layer.AddTile(2, -1, _tile1);
                Assert.Fail();
            }
            catch { }

            try {
                layer.AddTile(10, 8, _tile1);
                Assert.Fail();
            }
            catch { }

            try {
                layer.AddTile(8, 10, _tile1);
                Assert.Fail();
            }
            catch { }
        }
コード例 #2
0
        public void GetTilesAtLocation()
        {
            TileGridLayer layer = new MultiTileGridLayer("tiles", 16, 16, 10, 10);

            layer.AddTile(2, 3, _tile1);
            layer.AddTile(6, 7, _tile2);

            Assert.AreEqual(1, layer.TilesAt(new TileCoord(2, 3)).Count());
            Assert.AreEqual(0, layer.TilesAt(new TileCoord(1, 3)).Count());
            Assert.AreEqual(0, layer.TilesAt(new TileCoord(3, 3)).Count());
            Assert.AreEqual(0, layer.TilesAt(new TileCoord(1, 2)).Count());
            Assert.AreEqual(0, layer.TilesAt(new TileCoord(1, 4)).Count());
        }
コード例 #3
0
        public void GetTilesInRegion()
        {
            TileGridLayer layer = new MultiTileGridLayer("tiles", 16, 16, 10, 10);

            layer.AddTile(2, 3, _tile1);
            layer.AddTile(6, 7, _tile2);

            Assert.AreEqual(2, layer.TilesAt(new Rectangle(2, 2, 5, 6)).Count());
            Assert.AreEqual(1, layer.TilesAt(new Rectangle(3, 2, 5, 6)).Count());
            Assert.AreEqual(1, layer.TilesAt(new Rectangle(2, 4, 5, 6)).Count());
            Assert.AreEqual(1, layer.TilesAt(new Rectangle(2, 2, 4, 6)).Count());
            Assert.AreEqual(1, layer.TilesAt(new Rectangle(2, 2, 5, 5)).Count());
            Assert.AreEqual(0, layer.TilesAt(new Rectangle(3, 2, 5, 5)).Count());
        }
コード例 #4
0
        private void InitializeBrush(DynamicTileBrush brush)
        {
            _layerControl.ReferenceWidth  = brush.BrushClass.TemplateWidth * brush.TileWidth + 1;
            _layerControl.ReferenceHeight = brush.BrushClass.TemplateHeight * brush.TileHeight + 1;

            _layer = new MultiTileGridLayer("Default", brush.TileWidth, brush.TileHeight, brush.BrushClass.TemplateWidth, brush.BrushClass.TemplateHeight);
            for (int i = 0; i < brush.BrushClass.SlotCount; i++)
            {
                LocatedTile tile = brush.GetLocatedTile(i);
                if (tile.Tile != null)
                {
                    _layer.AddTile(tile.X, tile.Y, tile.Tile);
                }
            }

            _rootLayer.Layers.Clear();
            _rootLayer.Layers.Add(new TileGridLayerPresenter(_layerContext, _layer));
            _rootLayer.Layers.Add(new LocalRenderLayerPresenter(new OverlayRenderCore(this)));
            _rootLayer.Layers.Add(new GridLayerPresenter()
            {
                GridSpacingX = brush.TileWidth,
                GridSpacingY = brush.TileHeight,
            });

            _nameField.Text = brush.Name;

            _brush = brush;

            SelectCurrentPrototype();
            SelectCurrentTileSize();
        }
コード例 #5
0
        private void InitializeBrush(StaticTileBrush brush)
        {
            int tilesW = brush.TilesWide + 12;
            int tilesH = brush.TilesHigh + 12;

            _layerControl.ReferenceWidth  = tilesW * brush.TileWidth + 1;
            _layerControl.ReferenceHeight = tilesH * brush.TileHeight + 1;

            _layer = new MultiTileGridLayer("Default", brush.TileWidth, brush.TileHeight, tilesW, tilesH);
            foreach (LocatedTile tile in brush.Tiles)
            {
                if (tile.Tile != null)
                {
                    _layer.AddTile(tile.X, tile.Y, tile.Tile);
                }
            }

            _rootLayer.Layers.Clear();
            _rootLayer.Layers.Add(new TileGridLayerPresenter(_layerContext, _layer));
            _rootLayer.Layers.Add(new GridLayerPresenter()
            {
                GridSpacingX = brush.TileWidth,
                GridSpacingY = brush.TileHeight,
            });

            _nameField.Text = brush.Name;

            _brush = brush;

            SelectCurrentTileSize();
        }
コード例 #6
0
ファイル: LevelProcessor.cs プロジェクト: Jorch72/CS-Treefrog
        private TileGridLayer ProcessTileLayer(TileGridLayer layer, TilePool layerTilePool, Dictionary <Guid, Guid> tileUidMap)
        {
            MultiTileGridLayer outLayer = new MultiTileGridLayer(layer.Name, layer.TileWidth, layer.TileHeight, layer.TilesWide, layer.TilesHigh)
            {
                IsVisible  = layer.IsVisible,
                Opacity    = layer.Opacity,
                RasterMode = layer.RasterMode,
            };

            foreach (Property prop in layer.PropertyManager.CustomProperties)
            {
                outLayer.PropertyManager.CustomProperties.Add(prop);
            }

            foreach (LocatedTile tile in layer.Tiles)
            {
                Guid tileUid;
                if (!tileUidMap.TryGetValue(tile.Tile.Uid, out tileUid))
                {
                    Tile mappedTile = layerTilePool.Tiles.Add(tile.Tile.Pool.Tiles.GetTileTexture(tile.Tile.Uid));
                    tileUidMap[tile.Tile.Uid] = mappedTile.Uid;
                    tileUid = mappedTile.Uid;

                    foreach (Property prop in tile.Tile.PropertyManager.CustomProperties)
                    {
                        mappedTile.PropertyManager.CustomProperties.Add(prop);
                    }
                }

                outLayer.AddTile(tile.X, tile.Y, layerTilePool.Tiles[tileUid]);
            }

            return(outLayer);
        }
コード例 #7
0
        public void RemoveTile()
        {
            TileGridLayer layer = new MultiTileGridLayer("tiles", 16, 16, 10, 10);

            layer.AddTile(2, 4, _tile1);
            layer.AddTile(6, 7, _tile2);

            AttachEvents(layer);

            layer.TileRemoved += (s, e) =>
            {
                Assert.AreEqual(2, e.X);
                Assert.AreEqual(4, e.Y);
                Assert.AreSame(_tile1, e.Tile);
                Assert.AreEqual(1, layer.Tiles.Count());
                Assert.AreEqual(0, layer.TilesAt(new TileCoord(2, 4)).Count());
            };

            layer.RemoveTile(2, 4, _tile1);

            Assert.AreEqual(EventFlags.TileRemoved | EventFlags.Modified, _eventsFired);
        }