diff --git a/addons/godot_state_charts/compound_state.gd b/addons/godot_state_charts/compound_state.gd index bc4dd3a..3ea7d13 100644 --- a/addons/godot_state_charts/compound_state.gd +++ b/addons/godot_state_charts/compound_state.gd @@ -70,7 +70,7 @@ func _handle_transition(transition: Transition, source: State) -> void: if self.is_a_parent_of(target): # find which child is also ancestor for child in get_children(): - if child.is_parent_of(target): + if child.is_a_parent_of(target): # change state if necessary if _active_state != child: if is_instance_valid(_active_state): diff --git a/addons/godot_state_charts/state.gd b/addons/godot_state_charts/state.gd index ffef661..228d3ef 100644 --- a/addons/godot_state_charts/state.gd +++ b/addons/godot_state_charts/state.gd @@ -1,5 +1,5 @@ tool -class_name State +class_name State, "state.svg" extends Node ## called when state is entered diff --git a/addons/godot_state_charts/state.svg b/addons/godot_state_charts/state.svg new file mode 100644 index 0000000..d2a9d95 --- /dev/null +++ b/addons/godot_state_charts/state.svg @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + diff --git a/addons/godot_state_charts/state.svg.import b/addons/godot_state_charts/state.svg.import new file mode 100644 index 0000000..97f5e64 --- /dev/null +++ b/addons/godot_state_charts/state.svg.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/state.svg-282f80c2b8fcf2d526aa3e32719babaf.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/godot_state_charts/state.svg" +dest_files=[ "res://.import/state.svg-282f80c2b8fcf2d526aa3e32719babaf.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/addons/godot_state_charts/state_chart_debug.gd b/addons/godot_state_charts/state_chart_debug.gd new file mode 100644 index 0000000..60e126c --- /dev/null +++ b/addons/godot_state_charts/state_chart_debug.gd @@ -0,0 +1,21 @@ +class_name StateChartDebug +extends Tree + +var target: StateChart = null + +func _physics_process(delta: float) -> void: + if target is StateChart: + clear() + var root_state = target.get_child(0) + if root_state is State: + var item = create_item(null) + item.set_text(0, root_state.name) + _find_active_states(root_state, item) + +func _find_active_states(state: State, state_item: TreeItem): + for child in state.get_children(): + if child is State: + if child.active: + var item := create_item(state_item) + item.set_text(0, child.name) + _find_active_states(child, item) diff --git a/addons/godot_state_charts/transition.svg b/addons/godot_state_charts/transition.svg index c7c6c3a..4843d61 100644 --- a/addons/godot_state_charts/transition.svg +++ b/addons/godot_state_charts/transition.svg @@ -1,22 +1,92 @@ - - - - - - - + + + + + + - - - + + + - - + + - - + + diff --git a/project.godot b/project.godot index 37c2e5f..3c56a22 100644 --- a/project.godot +++ b/project.godot @@ -39,6 +39,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/godot_state_charts/state_chart.gd" }, { +"base": "Tree", +"class": "StateChartDebug", +"language": "GDScript", +"path": "res://addons/godot_state_charts/state_chart_debug.gd" +}, { "base": "Node", "class": "Transition", "language": "GDScript", @@ -49,8 +54,9 @@ _global_script_class_icons={ "CompoundState": "res://addons/godot_state_charts/compound_state.svg", "LevelEntry": "", "ParallelState": "res://addons/godot_state_charts/parallel_state.svg", -"State": "", +"State": "res://addons/godot_state_charts/state.svg", "StateChart": "res://addons/godot_state_charts/state_chart.svg", +"StateChartDebug": "", "Transition": "res://addons/godot_state_charts/transition.svg" } @@ -91,7 +97,7 @@ window/handheld/orientation="sensor_landscape" [editor_plugins] -enabled=PoolStringArray( ) +enabled=PoolStringArray( "res://addons/godot_state_charts/plugin.cfg" ) [global]