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

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

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

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

		`in`.endArray()

		return Vector4d(x, y, z, w)
	}
}