Conversation
This commit is contained in:
76
scripts/Events/Flow/EventGroup.gd
Normal file
76
scripts/Events/Flow/EventGroup.gd
Normal file
@@ -0,0 +1,76 @@
|
||||
class_name EventGroup extends "res://scripts/Events/Flow/EventWithChildren.gd"
|
||||
|
||||
enum ProcessType {
|
||||
SEQUENTIAL,
|
||||
PARALLEL,
|
||||
}
|
||||
|
||||
@export var processType:ProcessType = ProcessType.SEQUENTIAL;
|
||||
|
||||
var childIndex:int = 0
|
||||
|
||||
func start() -> void:
|
||||
super.start()
|
||||
|
||||
# If sequential, start first child
|
||||
if processType == ProcessType.SEQUENTIAL:
|
||||
childIndex = -1
|
||||
nextChild()
|
||||
|
||||
# If parallel, start all children
|
||||
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 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:
|
||||
super.end()
|
||||
for child in childEvents:
|
||||
if child.ended || !child.started:
|
||||
continue
|
||||
child.end()
|
||||
|
||||
func reset() -> void:
|
||||
super.reset()
|
||||
childIndex = -1
|
||||
for child in childEvents:
|
||||
child.reset()
|
||||
|
||||
func startChild(child:Event) -> void:
|
||||
# Inherits some properties from this event.
|
||||
child.interactee = self.interactee
|
||||
child.interactor = self.interactor
|
||||
child.start()
|
1
scripts/Events/Flow/EventGroup.gd.uid
Normal file
1
scripts/Events/Flow/EventGroup.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bb1qpptyr1rec
|
26
scripts/Events/Flow/EventWithChildren.gd
Normal file
26
scripts/Events/Flow/EventWithChildren.gd
Normal file
@@ -0,0 +1,26 @@
|
||||
class_name EventWithChildren extends "res://scripts/Events/Event.gd"
|
||||
|
||||
var childEvents:Array[Event] = []
|
||||
|
||||
func _init() -> void:
|
||||
super._init()
|
||||
_updateChildEvents()
|
||||
_updateChildEvents()
|
||||
self.child_entered_tree.connect(onChildEntered)
|
||||
self.child_exiting_tree.connect(onChildExited)
|
||||
self.child_order_changed.connect(onChildOrderChanged)
|
||||
|
||||
func _updateChildEvents() -> void:
|
||||
childEvents = []
|
||||
for child in get_children():
|
||||
if child is Event:
|
||||
childEvents.append(child)
|
||||
|
||||
func onChildEntered(child:Node) -> void:
|
||||
_updateChildEvents()
|
||||
|
||||
func onChildExited(child:Node) -> void:
|
||||
_updateChildEvents()
|
||||
|
||||
func onChildOrderChanged() -> void:
|
||||
_updateChildEvents()
|
1
scripts/Events/Flow/EventWithChildren.gd.uid
Normal file
1
scripts/Events/Flow/EventWithChildren.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bs78jtft61ro6
|
Reference in New Issue
Block a user