package ru.dbotthepony.kstarbound.math

import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import ru.dbotthepony.kstarbound.math.vector.Vector3i

object Vector3iTypeAdapter : TypeAdapter<Vector3i>() {
	override fun write(out: JsonWriter, value: Vector3i) {
		`out`.beginArray()
		`out`.value(value.x)
		`out`.value(value.y)
		`out`.value(value.z)
		`out`.endArray()
	}

	override fun read(`in`: JsonReader): Vector3i {
		`in`.beginArray()

		val x = `in`.nextInt()
		val y = `in`.nextInt()
		val z = `in`.nextInt()

		`in`.endArray()

		return Vector3i(x, y, z)
	}
}