Files
Dawn-Godot/scripts/Event/Flow/EventWithChildren.gd

51 lines
1.1 KiB
GDScript

class_name EventWithChildren extends "res://scripts/Event/Event.gd"
var childEvents:Array[Event] = []
var addedEvents: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 addedEvents:
remove_child(event)
event.queue_free()
addedEvents = []
_updateChildEvents()
func addChildEvent(child:Event, position:int = -1) -> void:
assert(started == false || ended == true)
if position < 0:
position = childEvents.size() + position + 1
add_child(child)
move_child(child, position)
addedEvents.append(child)
_updateChildEvents()
func startChild(child:Event) -> void:
assert(child.get_parent() == self)
# Inherits some properties from this event.
child.interactee = self.interactee
child.interactor = self.interactor
child.start()
if child.isEndingEvent():
self.end()