forked from team-sg/hero-mark-2
statecharts ehehehehehe
This commit is contained in:
parent
4d59717b88
commit
6eff1601a9
23 changed files with 895 additions and 2 deletions
53
addons/godot_state_charts/parallel_state.gd
Normal file
53
addons/godot_state_charts/parallel_state.gd
Normal file
|
@ -0,0 +1,53 @@
|
|||
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 ""
|
Loading…
Add table
Add a link
Reference in a new issue