/// <summary> /// Pastes the clipboard to the specified extent and position. /// </summary> /// <param name="extent">The extent to paste to, which must not be <c>null</c>.</param> /// <param name="position">The position.</param> /// <returns>The number of modifications.</returns> /// <exception cref="ArgumentNullException"><paramref name="extent" /> is <c>null</c>.</exception> /// <remarks> /// Null tiles in the array will be ignored when pasting. /// </remarks> public int PasteTo([NotNull] Extent extent, Vector position) { if (extent == null) { throw new ArgumentNullException(nameof(extent)); } var count = 0; for (var x = 0; x < Dimensions.X; ++x) { for (var y = 0; y < Dimensions.Y; ++y) { var tile = _tiles[x, y]; if (tile != null) { var offsetPosition = new Vector(x, y) + position; if (extent.IsInBounds(offsetPosition) && extent.SetTile(offsetPosition, tile.Value)) { ++count; } } } } foreach (var tileEntity in _tileEntities) { var offsetPosition = tileEntity.Position + position; if (extent.IsInBounds(offsetPosition) && extent.AddTileEntity(tileEntity.WithPosition(offsetPosition))) { ++count; } } return(count); }
/// <inheritdoc /> public bool Undo(Extent extent) => extent.AddTileEntity(TileEntity);