diff --git a/addons/godot_state_charts/state.gd b/addons/godot_state_charts/state.gd index 93cc81f..d204c1a 100644 --- a/addons/godot_state_charts/state.gd +++ b/addons/godot_state_charts/state.gd @@ -22,6 +22,8 @@ enum ProcessMode {IDLE, PHYSICS} ## whether to process transition delays during physics or idle frames export (ProcessMode) var transition_process_mode: int = ProcessMode.PHYSICS +## events to consume so that parent state can not +export (Array, String) var consumed_events: Array = [] ## whether the current state is active var active: bool setget _set_active @@ -77,6 +79,10 @@ func _state_event(event: String) -> bool: # first match is taken _queue_transition(transition) return true + + if event in consumed_events: + return true + return false func _process(delta: float) -> void: @@ -113,6 +119,7 @@ func _process_transition(delta: float) -> void: _queued_transition_time -= delta # if ready, handle transition and clear queue if _queued_transition_time <= 0.0: + print(_queued_transition.name) var transition = _queued_transition _queued_transition = null _queued_transition_time = 0.0 diff --git a/addons/godot_state_charts/state_chart.gd b/addons/godot_state_charts/state_chart.gd index 3baaa82..857259a 100644 --- a/addons/godot_state_charts/state_chart.gd +++ b/addons/godot_state_charts/state_chart.gd @@ -2,6 +2,8 @@ tool class_name StateChart, "state_chart.svg" extends Node +## whether chart should initialize on its own or be done manually +export var auto_initialize: bool = true ## whether chart should propagate processing events every frame export var idle_frame_event: bool = false export var physics_frame_event: bool = false @@ -15,7 +17,10 @@ var _guard_properties: Dictionary = {} func _ready() -> void: if Engine.editor_hint: return - + if auto_initialize: + initialize() + +func initialize() -> void: # make sure only one child exists if get_child_count() != 1: push_error("StateChart must have exactly one child")