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.Vector3d

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

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

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

		`in`.endArray()

		return Vector3d(x, y, z)
	}
}
