diff --git a/addons/godot_state_charts/state.gd b/addons/godot_state_charts/state.gd index 228d3ef..93cc81f 100644 --- a/addons/godot_state_charts/state.gd +++ b/addons/godot_state_charts/state.gd @@ -84,7 +84,7 @@ func _process(delta: float) -> void: return # emit processing signal - emit_signal("state_processing") + emit_signal("state_processing", delta) # process transitions if mode is IDLE if transition_process_mode == ProcessMode.IDLE: @@ -95,7 +95,7 @@ func _physics_process(delta: float) -> void: return # emit physics processing signal - emit_signal("state_processing") + emit_signal("state_physics_processing", delta) # process transitions if mode is PHYSICS if transition_process_mode == ProcessMode.PHYSICS: diff --git a/addons/godot_state_charts/state_chart.gd b/addons/godot_state_charts/state_chart.gd index dbb6716..3baaa82 100644 --- a/addons/godot_state_charts/state_chart.gd +++ b/addons/godot_state_charts/state_chart.gd @@ -2,11 +2,15 @@ tool class_name StateChart, "state_chart.svg" extends Node +## whether chart should propagate processing events every frame +export var idle_frame_event: bool = false +export var physics_frame_event: bool = false + # root state of the state chart var _state: State = null # values available to expression guards -var _expression_properties: Dictionary = {} +var _guard_properties: Dictionary = {} func _ready() -> void: if Engine.editor_hint: @@ -39,13 +43,22 @@ func send_event(event: String) -> void: _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 set_guard_property(property: String, value) -> void: + _guard_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: + if not get_child(0) is State: return "StateChart's child must be a State" - else: - return "" + return "" + +# send frame events that transition can listen to if it should evaluate +# its guard every frame +func _process(delta: float) -> void: + if idle_frame_event: + send_event("idle_frame") + +func _physics_process(delta: float) -> void: + if physics_frame_event: + send_event("physics_frame") diff --git a/addons/godot_state_charts/transition.gd b/addons/godot_state_charts/transition.gd index 715104e..0329da8 100644 --- a/addons/godot_state_charts/transition.gd +++ b/addons/godot_state_charts/transition.gd @@ -56,7 +56,7 @@ func evaluate_guard() -> bool: return false # combine monitored states with expression properties - var properties: Dictionary = root._expression_properties.duplicate() + var properties: Dictionary = root._guard_properties.duplicate() for node in checked_states: var state = get_node_or_null(node) if is_instance_valid(state) and state is _State: