Files
Dawn-Godot/scripts/Event/Flow/EventWithChildren.gd
2025-05-06 16:08:46 -05:00

37 lines
816 B
GDScript

class_name EventWithChildren extends "res://scripts/Event/Event.gd"
var childEvents:Array[Event] = []
var extraEvents:Array[Event] = []
func start():
super.start()
_updateChildEvents()
func reset() -> void:
super.reset()
_cleanupExtraEvents()
func end() -> void:
super.end()
_cleanupExtraEvents()
func _updateChildEvents() -> void:
childEvents = []
for child in get_children():
if child is Event:
childEvents.append(child)
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()