/// <summary> /// Sets the value of a group of tiles. /// </summary> /// <param name="startX">Left-most position of the tiles to be changed.</param> /// <param name="startY">Top-most position of the tiles to be changed.</param> /// <param name="tileBuffer">The tile buffer.</param> public void SetTiles(int startX, int startY, IMapBuffer tileBuffer) { bool dataChanged = false; int yLimit = Math.Min(tileBuffer.Height, TrackMap.Size - startY); int xLimit = Math.Min(tileBuffer.Width, TrackMap.Size - startX); for (int y = 0; y < yLimit; y++) { int positionY = startY + y; for (int x = 0; x < xLimit; x++) { int positionX = startX + x; if (this.SetTileInternal(positionX, positionY, tileBuffer[x, y])) { dataChanged = true; } } } if (dataChanged) { this.OnDataChanged(); } }
public TileChange(int x, int y, int width, int height, IMapBuffer buffer) { this.X = x; this.Y = y; this.data = new byte[height][]; for (int yIter = 0; yIter < height; yIter++) { this.data[yIter] = new byte[width]; for (int xIter = 0; xIter < width; xIter++) { this.data[yIter][xIter] = buffer[x + xIter, y + yIter]; } } }
/// <summary> /// Consolidates all changes into a single one. /// </summary> /// <param name="changes">The tile changes.</param> /// <param name="buffer">The map buffer the changes are applied on.</param> public TileChange(IEnumerable <TileChange> changes, IMapBuffer buffer) { int xStart = buffer.Width; int yStart = buffer.Height; int xEnd = 0; int yEnd = 0; foreach (TileChange change in changes) { xStart = Math.Min(xStart, change.X); xEnd = Math.Max(xEnd, change.X + change.Width); yStart = Math.Min(yStart, change.Y); yEnd = Math.Max(yEnd, change.Y + change.Height); } int width = xEnd - xStart; int height = yEnd - yStart; byte[][] data = new byte[height][]; for (int y = 0; y < height; y++) { data[y] = new byte[width]; for (int x = 0; x < width; x++) { data[y][x] = buffer[xStart + x, yStart + y]; } } foreach (TileChange change in changes) { int offsetY = change.Y - yStart; int offsetX = change.X - xStart; for (int y = 0; y < change.Height; y++) { for (int x = 0; x < change.Width; x++) { data[offsetY + y][offsetX + x] = change[x, y]; } } } this.X = xStart; this.Y = yStart; this.data = data; }
/// <summary> /// Sets the value of a group of tiles. /// </summary> /// <param name="startingPosition">Top-left position of tiles to be changed.</param> /// <param name="tileBuffer">The tile buffer.</param> public void SetTiles(Point startingPosition, IMapBuffer tileBuffer) { this.SetTiles(startingPosition.X, startingPosition.Y, tileBuffer); }