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

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

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

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

		`in`.endArray()

		return Vector2d(x, y)
	}
}
