Made extra events more generic.

This commit is contained in:
2025-05-06 11:41:55 -05:00
parent a3c2c65735
commit b0d9106772
5 changed files with 62 additions and 60 deletions

View File

@@ -1,14 +1,18 @@
class_name EventWithChildren extends "res://scripts/Events/Event.gd"
var childEvents:Array[Event] = []
var extraEvents:Array[Event] = []
func _init() -> void:
super._init()
# _updateChildEvents()
# self.child_entered_tree.connect(onChildEntered)
# self.child_exiting_tree.connect(onChildExited)
# self.child_order_changed.connect(onChildOrderChanged)
func start():
super.start()
_updateChildEvents()
_updateChildEvents()
self.child_entered_tree.connect(onChildEntered)
self.child_exiting_tree.connect(onChildExited)
self.child_order_changed.connect(onChildOrderChanged)
func _updateChildEvents() -> void:
childEvents = []
@@ -24,3 +28,26 @@ func onChildExited(child:Node) -> void:
func onChildOrderChanged() -> void:
_updateChildEvents()
func reset() -> void:
super.reset()
_cleanupExtraEvents()
func end() -> void:
super.end()
_cleanupExtraEvents()
func _cleanupExtraEvents():
for event in extraEvents:
remove_child(event)
event.queue_free()
extraEvents = []
_updateChildEvents()
func addExtraEvent(child:Event, position:int) -> void:
assert(started == false || ended == true)
# Add the child to the extra events list
extraEvents.append(child)
add_child(child)
move_child(child, position)
_updateChildEvents()