extends Node2D

onready var activatorArea = $"%ActivatorArea"
onready var signalManager := get_tree().root.get_child(3).get_node("%SignalManager")
onready var levelState := get_tree().root.get_child(3).get_node("%LevelState")
onready var blobby := $"../%Blobby"
onready var unactivatable_timer := $Timer
export var cost := 3

var activatable = false


func _process(delta):
	# TODO Global currency count?? Maybe just level intern currency
	if activatable && Input.is_action_just_released("interact"):
		if(levelState.spend_currency(cost)):
			signalManager.emit_signal("currency_updated")
			selfActivate()

func selfActivate():
	#TODO Is a event for blobby himself
	#blobby.get_node("BubbleShieldViewport/IridescenceBall").visible = true
	signalManager.emit_signal("power_up_collected", "shield")
	#TODO dis importante
	activatorArea.set_deferred("monitoring", false)


func _on_ActivatorArea_area_entered(area:Area2D) -> void:
		$Label.visible = true
		activatable = true

func _on_ActivatorArea_area_exited(area:Area2D) -> void:
		unactivatable_timer.start()

func _on_Timer_timeout():
	if($ActivatorArea.get_overlapping_bodies().size() == 0):
		$Label.visible = false
		activatable = false
