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

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

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

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

		`in`.endArray()

		return Vector2f(x, y)
	}
}