class_name Interactable_Receiver
extends Node2D

# This may be stupid but we're going to have two kinds of callbacks here. 
# It's going to be up to the parent/actor/kinematicbody2d/whatever to know
# what conditions have to be met before being able to call that interactible's
# function. 
# This is a nice and generic interface that I might be able to use for 
# things like opening doors in a level, opening chests/flipping switches etc.

# This node can keep an array of various interactibles within a level
# and provide several helper functions for managing them perhaps.

export(String) var interactable_parent_callback = ""

var call_function: FuncRef

var interactable_function_callables = []

# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
	if interactable_parent_callback:
		call_function = funcref(owner, interactable_parent_callback)
	else:
		print("Warning: No interactable receiver function defined on ", owner.name)

# Switching to a new model that starts with Hitbox 
func register_interactable(sender):
	print("Interactable Registered  " + sender.name)
	if call_function.is_valid():
		var should_register: bool = call_function.call_func(sender)
		if should_register:
			interactable_function_callables.append(sender)
		else:
			print("Interactable handled by Player")

func remove_interactable(sender):
	print("Interactable Removal  " + sender.name)
	if interactable_function_callables.has(sender):
		var sender_index = interactable_function_callables.rfind(sender)
		if sender_index != -1:
			interactable_function_callables.remove(sender_index)

