Attempt2/lib/components/GenericSender.gd

42 lines
1.3 KiB
GDScript3

extends Area2D
export(String) var receiver_node_name = ""
# 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():
# pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
##TODO: maybe guarantee type with receiver node type instead of just the name.
# The the name helps keep the receiver type generic.
func _on_GenericSender_body_entered(body):
if body.has_node(receiver_node_name):
body.get_node(receiver_node_name).on_body_entered(self)
#func _on_Hurtbox_Component_area_shape_entered(area_rid, area, area_shape_index, local_shape_index):
# #print(area.get_parent().name, "hit", owner.name)
## if area.get_parent().has_method("gotcha"):
# print(area.get_parent().name, " you can do it.", owner.name)
#
# if owner.has_method("_on_Hurtbox_area_entered"):
# owner.call("_on_Hurtbox_area_entered")
# print(area.get_parent().name, " just hit me: ", owner.name)
func _on_GenericSender_area_shape_entered(area_rid, area, area_shape_index, local_shape_index):
if area.get_parent().has_node(receiver_node_name):
area.get_parent().get_node(receiver_node_name).on_body_entered(self)