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

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

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

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

		`in`.endArray()

		return Vector2i(x, y)
	}
}