private static void SerializeTiles(BinaryWriter writer, Extent extent) { var dimensions = extent.Dimensions; for (var x = 0; x < dimensions.X; ++x) { for (var y = 0; y < dimensions.Y;) { var tile = extent.GetTile(new Vector(x, y)); var data = SerializeTile(tile, out var dataIndex, out var headerIndex); short repeat = 0; while (++y < dimensions.Y && tile == extent.GetTile(new Vector(x, y))) { ++repeat; } if (repeat > 0) { data[dataIndex++] = (byte)repeat; if (repeat <= 255) { data[headerIndex] |= 64; } else { data[headerIndex] |= 128; data[dataIndex++] = (byte)(repeat >> 8); } } writer.Write(data, headerIndex, dataIndex - headerIndex); } } }
public static Clipboard CopyFrom([NotNull] Extent extent, [NotNull] Region region) { if (extent == null) { throw new ArgumentNullException(nameof(extent)); } if (region == null) { throw new ArgumentNullException(nameof(region)); } var dimensions = region.Dimensions; var clipboard = new Clipboard(new Tile?[dimensions.X, dimensions.Y]); foreach (var position in region.Where(extent.IsInBounds)) { var offsetPosition = position - region.LowerBound; clipboard.SetTile(offsetPosition, extent.GetTile(position)); } foreach (var entity in extent.GetTileEntities().Where(e => region.Contains(e.Position))) { var offsetPosition = entity.Position - region.LowerBound; clipboard.AddTileEntity(entity.WithPosition(offsetPosition)); } return(clipboard); }
/// <inheritdoc /> public override bool Test(Extent extent, Vector position) => _template.Matches(extent.GetTile(position));