public int AddLayer(LayerLayout layout, Bitmap tilesBitmap, Bitmap wrapBitmap) { int index = _Layers.Count; if (index >= 32) { throw new InvalidOperationException("Too many layers."); } int mask = 1 << index; _Layers.Add(new Layer(mask, layout, tilesBitmap, wrapBitmap)); return(mask); }
public Layer(int mask, LayerLayout layout, Bitmap tilesBitmap, Bitmap wrapBitmap) { Mask = mask; ConnectionsMask = mask; Layout = layout; TilesBitmap = tilesBitmap; WrapBitmap = wrapBitmap; for (int i = 0; i < _CodeToTileCoords.Length; ++i) { _CodeToTileCoords[i] = new List <Point>(); } if (Layout == LayerLayout.Sides) { BitmapTileSize = TilesBitmap.Height / _SidesLayoutHeight; if (TilesBitmap.Height != _SidesLayoutHeight * BitmapTileSize || TilesBitmap.Width % (_SidesLayoutWidth * BitmapTileSize) != 0) { throw new InvalidOperationException("Invalid size of tiles bitmap."); } for (int y = 0; y < _SidesLayoutHeight; ++y) { for (int x = 0; x < TilesBitmap.Width / BitmapTileSize; ++x) { int code = _SidesLayout[(x % _SidesLayoutWidth) + y * _SidesLayoutWidth]; _CodeToTileCoords[code].Add(new Point(x, y)); } } } else { BitmapTileSize = TilesBitmap.Height / _CornersLayoutHeight; if (TilesBitmap.Height != _CornersLayoutHeight * BitmapTileSize || TilesBitmap.Width % (_CornersLayoutWidth * BitmapTileSize) != 0) { throw new InvalidOperationException("Invalid size of tiles bitmap."); } for (int y = 0; y < _CornersLayoutHeight; ++y) { for (int x = 0; x < TilesBitmap.Width / BitmapTileSize; ++x) { int code = _CornersLayout[(x % _CornersLayoutWidth) + y * _CornersLayoutWidth]; _CodeToTileCoords[code].Add(new Point(x, y)); } } } }