class_name EventGroup extends "res://scripts/Event/Flow/EventWithChildren.gd" enum ProcessType { SEQUENTIAL, PARALLEL, } @export var processType:ProcessType = ProcessType.SEQUENTIAL; var childIndex:int = 0 var eventGroupStarted:bool = false func shouldAutoStart() -> bool: return true func start() -> void: super.start() if shouldAutoStart(): startEventGroup() func startEventGroup() -> void: eventGroupStarted = true # This is called by the parent event to start the group if processType == ProcessType.SEQUENTIAL: childIndex = -1 nextChild() elif processType == ProcessType.PARALLEL: for child in childEvents: startChild(child) func update(delta:float) -> void: super.update(delta) # If sequential, see if the current child is done, if so go to next child if processType == ProcessType.SEQUENTIAL: if childIndex < 0 || childIndex >= childEvents.size(): return if childEvents[childIndex].isDone(): nextChild() func nextChild() -> void: childIndex += 1 if childIndex >= childEvents.size(): return startChild(childEvents[childIndex]) func isDone() -> bool: if !super.isDone(): return false if started && !eventGroupStarted: return true # If sequential, check if we've reached the end of the children if processType == ProcessType.SEQUENTIAL: return childIndex >= childEvents.size() # If parallel, check if all children are done elif processType == ProcessType.PARALLEL: for child in childEvents: if !child.isDone(): return false return true return false func end() -> void: for child in childEvents: if child.ended || !child.started: continue child.end() # Send to the parent to end the extra events super.end() func reset() -> void: childIndex = -1 eventGroupStarted = false for child in childEvents: child.reset() # Send to the parent to reset the extra events super.reset() func startChild(child:Event) -> void: # Inherits some properties from this event. child.interactee = self.interactee child.interactor = self.interactor child.start() if child.isEndingEvent(): self.end()