53 lines
1.1 KiB
GDScript
53 lines
1.1 KiB
GDScript
tool
|
|
class_name ParallelState, "parallel_state.svg"
|
|
extends State
|
|
|
|
var _sub_states: Array = []
|
|
|
|
func _state_init() -> void:
|
|
._state_init()
|
|
|
|
for child in get_children():
|
|
if child is State:
|
|
_sub_states.append(child)
|
|
child._state_init()
|
|
|
|
func _state_enter() -> void:
|
|
._state_enter()
|
|
# enter all children
|
|
for child in _sub_states:
|
|
child._state_enter()
|
|
|
|
func _state_exit() -> void:
|
|
# exit all children
|
|
for child in _sub_states:
|
|
child._state_exit()
|
|
._state_exit()
|
|
|
|
func _state_event(event: String) -> bool:
|
|
if not active:
|
|
return false
|
|
|
|
# forward to all children
|
|
var handled := false
|
|
for child in _sub_states:
|
|
var child_handled = child._state_event(event)
|
|
handled = handled or child_handled
|
|
|
|
# if child handled event, no more touchy
|
|
if handled:
|
|
emit_signal("event_received", event)
|
|
return true
|
|
|
|
# otherwise handle ourselves
|
|
return ._state_event(event)
|
|
|
|
func _get_configuration_warning() -> String:
|
|
var warning := ._get_configuration_warning()
|
|
if not warning.empty():
|
|
return warning
|
|
|
|
if get_child_count() == 0:
|
|
return "parallel states should have at least one child state"
|
|
|
|
return ""
|