extends ESCItemComponent
class_name ESCItemComponentOutline

var outline: ItemOutline

var isHighlighted: bool
var lastHighlightState: bool

func get_component_type():
	return "outline"

func _ready():
	var collision = get_parent().collision
	if collision is CollisionPolygon2D:
		outline = ItemOutline.new()
		outline.polygon =  collision.get("polygon")
		outline.color = Color(1,1,1,0.2)
		outline.set_outline_width(2.0)
		outline.set_outline_color(Color(1,1,1,1))
		collision.add_child(outline)
		outline.hide()


func highlight(value: bool):
	isHighlighted = value

func _process(_delta: float):
	if not outline is ItemOutline:
	   return
	if isHighlighted != lastHighlightState:
		if isHighlighted:
			outline.show()
		else:
			outline.hide()
		lastHighlightState = isHighlighted

func _input(event):
	if(event.is_action_pressed("ui_show_hints")):
		highlight(true)
	elif (event.is_action_released("ui_show_hints")):
		highlight(false)
