package ru.dbotthepony.mc.otm.core.math

import com.mojang.serialization.Codec
import com.mojang.serialization.codecs.RecordCodecBuilder
import net.minecraft.ChatFormatting
import ru.dbotthepony.kommons.math.RGBAColor

@JvmField
val RGBAColorDFUCodec: Codec<RGBAColor> = RecordCodecBuilder.create {
	it.group(
		Codec.floatRange(0f, 1f).fieldOf("red").forGetter(RGBAColor::red),
		Codec.floatRange(0f, 1f).fieldOf("green").forGetter(RGBAColor::green),
		Codec.floatRange(0f, 1f).fieldOf("blue").forGetter(RGBAColor::blue),
		Codec.floatRange(0f, 1f).optionalFieldOf("alpha", 1f).forGetter(RGBAColor::alpha),
	).apply(it, ::RGBAColor)
}

@JvmField
val RGBColorDFUCodec: Codec<RGBAColor> = RecordCodecBuilder.create {
	it.group(
		Codec.floatRange(0f, 1f).fieldOf("red").forGetter(RGBAColor::red),
		Codec.floatRange(0f, 1f).fieldOf("green").forGetter(RGBAColor::green),
		Codec.floatRange(0f, 1f).fieldOf("blue").forGetter(RGBAColor::blue),
	).apply(it, ::RGBAColor)
}
