package ru.dbotthepony.kstarbound.world.entities.wire

import ru.dbotthepony.kommons.io.StreamCodec
import ru.dbotthepony.kommons.io.readSignedVarInt
import ru.dbotthepony.kommons.io.readVarInt
import ru.dbotthepony.kommons.io.writeSignedVarInt
import ru.dbotthepony.kommons.io.writeVarInt
import ru.dbotthepony.kommons.vector.Vector2i
import ru.dbotthepony.kstarbound.network.syncher.SizeTCodec
import java.io.DataInputStream
import java.io.DataOutputStream

data class WireConnection(val entityLocation: Vector2i, val index: Int = 0) {
	constructor(stream: DataInputStream) : this(Vector2i(stream.readSignedVarInt(), stream.readSignedVarInt()), stream.readVarInt())

	fun write(stream: DataOutputStream) {
		stream.writeSignedVarInt(entityLocation.x)
		stream.writeSignedVarInt(entityLocation.y)
		stream.writeVarInt(index)
	}

	companion object {
		val CODEC = StreamCodec.Impl(::WireConnection, { a, b -> b.write(a) })
	}
}
