diff --git a/CHANGES.md b/CHANGES.md index d575111..fd472d9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.1] - 2023-04-12 +### Fixed +- Transitioning from a child to a parent state should no longer throw an error when the parent is the root node ([#3](https://github.com/derkork/godot-statecharts/issues/3)). +- Transitioning from a child to a parent compound / parallel state now properly counts as [self transition](https://statecharts.dev/glossary/self-transition.html), so that the parent node is exited and re-entered. + + ## [0.1.0] - 2023-04-06 ### Breaking changes - The state chart debugger now is no longer a single node but a full scene. This allows to have more complex UI in the debugger. Please replace the old debugger node with the new scene which is located at `addons/godot-statecharts/utilities/state_chart_debugger.tscn`. The debugger will no longer appear in the node list. You can quickly add it using the "Instatiate child scene" button in the scene inspector. diff --git a/addons/godot_state_charts/compound_state.gd b/addons/godot_state_charts/compound_state.gd index d8e180e..1e5c2f3 100644 --- a/addons/godot_state_charts/compound_state.gd +++ b/addons/godot_state_charts/compound_state.gd @@ -125,6 +125,8 @@ func _handle_transition(transition:Transition, source:State): return # the target state can be + # 0. this state. in this case exit this state and re-enter it. This can happen when + # a child state transfers to its parent state. # 1. a direct child of this state. this is the easy case in which # we will deactivate the current _active_state and activate the target # 2. a descendant of this state. in this case we find the direct child which @@ -133,6 +135,12 @@ func _handle_transition(transition:Transition, source:State): # 3. no descendant of this state. in this case, we ask our parent state to # perform the transition + if target == self: + # exit this state and re-enter it + _state_exit() + _state_enter(false) + return + if target in get_children(): # all good, now first deactivate the current state if is_instance_valid(_active_state): diff --git a/addons/godot_state_charts/parallel_state.gd b/addons/godot_state_charts/parallel_state.gd index 106bd91..96e3459 100644 --- a/addons/godot_state_charts/parallel_state.gd +++ b/addons/godot_state_charts/parallel_state.gd @@ -28,6 +28,8 @@ func _handle_transition(transition:Transition, source:State): return # the target state can be + # 0. this state. in this case just activate the state and all its children. + # this can happen when a child state transfers back to its parent state. # 1. a direct child of this state. this is the easy case in which # we will do nothing, because our direct children are always active. # 2. a descendant of this state. in this case we find the direct child which @@ -36,6 +38,13 @@ func _handle_transition(transition:Transition, source:State): # 3. no descendant of this state. in this case, we ask our parent state to # perform the transition + if target == self: + # exit this state + _state_exit() + # then re-enter it + _state_enter(false) + return + if target in get_children(): # all good, nothing to do. return