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

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

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

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

		`in`.endArray()

		return Vector3f(x, y, z)
	}
}