package ru.dbotthepony.kstarbound.world

import ru.dbotthepony.kommons.io.StreamCodec
import ru.dbotthepony.kommons.vector.Vector2d
import ru.dbotthepony.kstarbound.json.builder.IStringSerializable

// uint8_t
enum class Direction(val normal: Vector2d, override val jsonName: String, val luaValue: Long, val isRight: Boolean, val isLeft: Boolean) : IStringSerializable {
	LEFT(Vector2d.NEGATIVE_X, "left", -1L, false, true) {
		override val opposite: Direction
			get() = RIGHT
	},
	RIGHT(Vector2d.POSITIVE_X, "right", 1L, true, false) {
		override val opposite: Direction
			get() = LEFT
	};

	abstract val opposite: Direction

	operator fun unaryPlus() = opposite

	override fun match(name: String): Boolean {
		return name.lowercase() == jsonName
	}

	companion object {
		val CODEC = StreamCodec.Enum(Direction::class.java)
	}
}
