extends Node2D

const LIST_OF_ENTITIES = ["ArcherTower", "WizardTower", "MortarTower", "Mine", "StickTrap", "Wall"]
func _ready() -> void:
	set_process_input(true)

func _process(delta: float) -> void:
	position = get_viewport().get_mouse_position()
	
func _input(event):
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
		if abs(position) <= get_viewport().get_mouse_position():
			var list_of_entities = get_node("Area2D").get_overlapping_bodies()
			for i in list_of_entities:
				for j in LIST_OF_ENTITIES:
					if i.get_parent().name.contains(j):
						match j:
							"ArcherTower":
								get_parent().get_node("SidePanel").Update_Coins(60)
							"WizardTower":
								get_parent().get_node("SidePanel").Update_Coins(30)
							"MortarTower":
								get_parent().get_node("SidePanel").Update_Coins(80)
							"Mine":
								get_parent().get_node("SidePanel").Update_Coins(10)
							"StickTrap":
								get_parent().get_node("SidePanel").Update_Coins(5)
							"Wall":
								get_parent().get_node("SidePanel").Update_Coins(0)
								i.get_parent().WallRelease()
						i.get_parent().queue_free()
			queue_free()
			
