statecharts ehehehehehe

This commit is contained in:
Haze Weathers 2023-04-13 14:24:41 -04:00
parent 4d59717b88
commit 6eff1601a9
23 changed files with 895 additions and 2 deletions

View file

@ -0,0 +1,51 @@
tool
class_name StateChart, "state_chart.svg"
extends Node
# root state of the state chart
var _state: State = null
# values available to expression guards
var _expression_properties: Dictionary = {}
func _ready() -> void:
if Engine.editor_hint:
return
# make sure only one child exists
if get_child_count() != 1:
push_error("StateChart must have exactly one child")
return
# verify child is a State
var child = get_child(0)
if not child is State:
push_error("StateChart's child must be a State")
return
# initialize states
_state = child as State
_state._state_init()
# enter root state
_state._state_enter()
## sends an event to be propagated through the states
func send_event(event: String) -> void:
if not is_instance_valid(_state):
push_error("StateChart is not initialized properly")
return
_state._state_event(event)
## sets a property available to guard expressions in transitions
func set_expression_property(property: String, value) -> void:
_expression_properties[property] = value
func _get_configuration_warning() -> String:
if get_child_count() != 1:
return "StateChart must have exactly one child"
elif not get_child(0) is State:
return "StateChart's child must be a State"
else:
return ""