Attempt2/lib/components/Modifier_Receiver.gd

54 lines
1.8 KiB
GDScript3

class_name Modifier_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 modifier_parent_callback = ""
export var debug_receiver :bool = false
var call_function: FuncRef
#var interactable_function_callables = []
var modifier_collection = []
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
##NOTE:
## Call function should be implemented as two parameters, one expecting a modifier
## and the other expecting a boolean as to whether its being added
# Called when the node enters the scene tree for the first time.
func _ready():
if modifier_parent_callback:
call_function = funcref(owner, modifier_parent_callback)
else:
print("Warning: No modifier receiver function defined on ", owner.name)
# Switching to a new model that starts with Hitbox
func register_modifier(modifier: StateModifier):
if modifier_collection.has(modifier) == false:
print("New Modifier Registered " + modifier.name)
modifier_collection.append(modifier)
if call_function.is_valid():
call_function.call_func(modifier, true)
func remove_modifier(modifier):
print("Modifier Removal " + modifier.name)
if modifier_collection.has(modifier):
var modifier_index = modifier_collection.rfind(modifier)
if modifier_index != -1:
modifier_collection.remove(modifier_index)
if call_function.is_valid():
call_function.call_func(modifier, false)