diff --git a/CHANGES.md b/CHANGES.md index 88a21af..96f0362 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,14 @@ 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.11.0] - 2023-12-14 +### Added +- When adding the first child state to a compound state in the editor, this will now automatically be set as the initial state of the compound state. A big thanks goes out to [Roger](https://github.com/RogerRandomDev) for submitting a PR with this feature. + +### Fixed +- Some of the node warnings have been clarified to make it easier to understand what is going on. +- Some fringe errors that may happen when you add unrelated nodes below state or transition nodes have been addressed. + ## [0.10.0] - 2023-12-13 ### Added diff --git a/addons/godot_state_charts/compound_state.gd b/addons/godot_state_charts/compound_state.gd index 83fad45..cbf6e3f 100644 --- a/addons/godot_state_charts/compound_state.gd +++ b/addons/godot_state_charts/compound_state.gd @@ -207,6 +207,20 @@ func _handle_transition(transition:Transition, source:State): get_parent()._handle_transition(transition, source) +func add_child(node:Node, force_readable_name:bool = false, internal:InternalMode = INTERNAL_MODE_DISABLED) -> void: + super.add_child(node, force_readable_name, internal) + # when a child is added in the editor and the child is a state + # and we don't have an initial state yet, set the initial state + # to the newly added child + if Engine.is_editor_hint() and node is State: + if initial_state.is_empty(): + # the newly added node may have a random name now, + # so we need to defer the call to build a node path + # to the next frame, so the editor has time to rename + # the node to its final name + (func(): initial_state = get_path_to(node)).call_deferred() + + func _get_configuration_warnings() -> PackedStringArray: var warnings = super._get_configuration_warnings() diff --git a/addons/godot_state_charts/plugin.cfg b/addons/godot_state_charts/plugin.cfg index f259713..e28e611 100644 --- a/addons/godot_state_charts/plugin.cfg +++ b/addons/godot_state_charts/plugin.cfg @@ -3,5 +3,5 @@ name="Godot State Charts" description="A simple, yet powerful state charts library for Godot" author="Jan Thomä & Contributors" -version="0.10.0" +version="0.11.0" script="godot_state_charts.gd"