extends Node3D

var rng = RandomNumberGenerator.new()

@export var shirt_cols = []
@export var skin_cols = []

# Called when the node enters the scene tree for the first time.
func _ready():
	var hair_type = rng.randf_range(0.0, 10.0)

	var fro = false

	if hair_type < 3:
		get_node("body/head/hair").visible = true
		get_node("body/head/hair_long").visible = false
		get_node("body/head/fro").visible = false
	elif hair_type < 6:
		get_node("body/head/hair").visible = false
		get_node("body/head/hair_long").visible = true
		get_node("body/head/fro").visible = false
	elif hair_type < 8.5:
		get_node("body/head/hair").visible = false
		get_node("body/head/hair_long").visible = false
		get_node("body/head/fro").visible = true
		fro = true
	else:
		get_node("body/head/hair").visible = false
		get_node("body/head/hair_long").visible = false
		get_node("body/head/fro").visible = false
		
	get_node("body/head/beard").visible = (rng.randf_range(0.0, 1.0) < 0.1)
	get_node("body/head/mustache").visible = (rng.randf_range(0.0, 1.0) < 0.1)
	get_node("body/chest").visible = (rng.randf_range(0.0, 1.0) < 0.5)
	
	var cap_type = rng.randf_range(0.0, 6.0)
	
	if fro:
		cap_type = 5
	
	if cap_type < 1:
		get_node("body/head/cap").visible = true
		get_node("body/head/tophat").visible = false
	elif cap_type < 2:
		get_node("body/head/cap").visible = false
		get_node("body/head/tophat").visible = true
	else:
		get_node("body/head/cap").visible = false
		get_node("body/head/tophat").visible = false
		
	var shirtcol = rng.randi_range(0, shirt_cols.size()-1)
	
	get_node("body")["surface_material_override/1"] = shirt_cols[shirtcol]
	get_node("body/chest")["surface_material_override/0"] = shirt_cols[shirtcol]
		
	var skincol = rng.randi_range(0, skin_cols.size()-1)
	
	get_node("body")["surface_material_override/0"] = skin_cols[skincol]
	get_node("body/head")["surface_material_override/0"] = skin_cols[skincol]
	get_node("body/hand_l")["surface_material_override/0"] = skin_cols[skincol]
	get_node("body/hand_r")["surface_material_override/0"] = skin_cols[skincol]
	
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass
