class_name PawnDisplay extends Panel

@onready var pawn_name : Label = %PawnName
@onready var trap_container : HBoxContainer = %TrapContainer
@onready var portrait : TextureRect = $Portrait
@onready var portrait_blinder : TextureRect = $PortraitBlinder
var traps : Array = []
var swap_portrait_tween : Tween = null

func _ready() -> void:
	for child in trap_container.get_children():
		traps.append(child)

func set_traps(trap_list : Array[TrapSet]) -> void:
	var tcount = 0
	if len(trap_list) != 3:
		return
	for trap in traps:
		trap.setup(trap_list[tcount].type, trap_list[tcount].qty)
		tcount+=1

func set_portrait(picture : Texture2D) -> void:
	if swap_portrait_tween != null and swap_portrait_tween.is_running():
		swap_portrait_tween.stop()
	swap_portrait_tween = create_tween()
	
	swap_portrait_tween.tween_property(portrait_blinder, "visible", true, 0)
	swap_portrait_tween.tween_method(tv_blur, 1.0, 0.0, .1)
	swap_portrait_tween.tween_property(portrait, "texture", picture, 0)
	swap_portrait_tween.tween_method(tv_blur, 0.0, 1.0, .1)
	swap_portrait_tween.tween_property(portrait_blinder, "visible", false, 0)
	portrait.texture = picture

func tv_blur(amount : float) -> void:
	var blinder_mat : ShaderMaterial = portrait_blinder.material
	blinder_mat.set_shader_parameter("opacity_limit", amount)
	
func set_pawn_name(name : String) -> void:
	pawn_name.text = name
