class_name ColorVariant extends TextureRect

enum Types{
	SKIN,
	HAIR,
	EYES
}
static var eye_colors = {
	"blue":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(l)fair.tres"),
		},
	"green":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/eyes/(c)green.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(l)default.tres"),
		},
	"brown":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
	"gold":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
	"red":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
	"grey":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
}

static var hair_colors = {
	"blue":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
	"blonde":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/hair/(c)blonde.tres"),
		"luminosity": preload("res://external/test portrait/gradients/hair/(l)fair.tres"),
		},
	"brown":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/hair/(c)brown.tres"),
		"luminosity": preload("res://external/test portrait/gradients/hair/(l)mid.tres"),
		},
	"black":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/hair/(c)black.tres"),
		"luminosity": preload("res://external/test portrait/gradients/hair/(l)black.tres"),
		},
	"red":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/hair/(c)red.tres"),
		"luminosity": preload("res://external/test portrait/gradients/hair/(l)red.tres"),
		},
	"silver":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
}

static var skin_colors = {
	"pale":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/skin/(c)pale.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
	"medium":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/skin/(c)medium.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
	"olive":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/skin/(c)blue.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
	"brown":{
		"weight": 100,
		"color": preload("res://external/Test Portrait/gradients/skin/(c)brown.tres"),
		"luminosity": preload("res://external/Test Portrait/gradients/skin/(l)dark.tres"),
		},
	"dark":{
		"weight": 100,
		"color": preload("res://external/test portrait/gradients/skin/(c)dark.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(l)default.tres"),
		},
	"white":{
		"weight": 0,
		"color": preload("res://external/test portrait/gradients/skin/(c)white.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
	"red":{
		"weight": 0,
		"color": preload("res://external/test portrait/gradients/skin/(c)red.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
	"blue":{
		"weight": 0,
		"color": preload("res://external/test portrait/gradients/skin/(c)blue.tres"),
		"luminosity": preload("res://external/test portrait/gradients/eyes/(c)blue.tres"),
		},
}
@export var type : Types

#@onready var variant_material : ShaderMaterial = material

func set_color(color : String) -> void:
	var col_gradients
	match(type):
		Types.SKIN:
			if !skin_colors.has(color):
				printerr("Tried to set a color '%s' that isn't part of the skin color list!" % color)
				return
			col_gradients = skin_colors[color]
		Types.HAIR:
			if !hair_colors.has(color):
				printerr("Tried to set a color '%s' that isn't part of the hair color list!" % color)
				return
			col_gradients = hair_colors[color]
		Types.EYES:
			if !eye_colors.has(color):
				printerr("Tried to set a color '%s' that isn't part of the eye color list!" % color)
				return
			col_gradients = eye_colors[color]
	var mat = material
	mat.set_shader_parameter("color_gradient",col_gradients.color)
	mat.set_shader_parameter("luminosity_gradient",col_gradients.luminosity)

func flash(flashing : bool) -> void:
	material.set_shader_parameter("flash",flashing)
