state chart updates

This commit is contained in:
Haze Weathers 2023-05-01 00:09:39 -04:00
parent d11ccb37a1
commit 02b85c7dd2
7 changed files with 242 additions and 18 deletions

View file

@ -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):

View file

@ -1,5 +1,5 @@
tool
class_name State
class_name State, "state.svg"
extends Node
## called when state is entered

View file

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="100%"
height="100%"
viewBox="0 0 32 32"
version="1.1"
xml:space="preserve"
style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;"
id="svg132"
sodipodi:docname="state.svg"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:serif="http://www.serif.com/"><defs
id="defs136"><linearGradient
inkscape:collect="always"
id="linearGradient1345"><stop
style="stop-color:#e18e39;stop-opacity:1;"
offset="0"
id="stop1341" /><stop
style="stop-color:#e18e39;stop-opacity:0;"
offset="1"
id="stop1343" /></linearGradient><linearGradient
inkscape:collect="always"
xlink:href="#linearGradient1345"
id="linearGradient1347"
x1="12.971001"
y1="16.312"
x2="20.609001"
y2="16.312"
gradientUnits="userSpaceOnUse" /></defs><sodipodi:namedview
id="namedview134"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="17.46875"
inkscape:cx="5.5241503"
inkscape:cy="16.028623"
inkscape:window-width="1302"
inkscape:window-height="737"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="Artboard11" />
<rect
id="Artboard1"
x="0"
y="0"
width="32"
height="32"
style="fill:none;" />
<g
id="Artboard11"
serif:id="Artboard1">
<g
transform="matrix(1.03705,0,0,1.03705,-0.460588,-0.659827)"
id="g124"
style="stroke-width:0.99995179;stroke-dasharray:none">
<g
id="BG"
style="stroke-width:0.99995179;stroke-dasharray:none">
<path
d="M30.337,8.833C30.337,4.841 27.096,1.601 23.104,1.601L8.64,1.601C4.649,1.601 1.408,4.841 1.408,8.833L1.408,23.297C1.408,27.288 4.649,30.529 8.64,30.529L23.104,30.529C27.096,30.529 30.337,27.288 30.337,23.297L30.337,8.833Z"
style="fill:none;stroke:rgb(225, 142, 57);stroke-width:0.99995179;stroke-dasharray:none"
id="path121" />
</g>
</g>
<g
transform="matrix(3.01177,0,0,3.01177,-34.5681,-33.1274)"
id="g129"
style="fill:none;stroke:#e18e39;stroke-opacity:1;opacity:1;stroke-width:0.83406103;stroke-dasharray:none">
<g
id="AtomicState"
style="fill:none;stroke:#e18e39;stroke-opacity:1;stroke-width:0.83406103;stroke-dasharray:none">
<circle
cx="16.79"
cy="16.312"
r="3.319"
style="fill:none;stroke:#e18e39;stroke-opacity:1;stroke-width:0.83406103;stroke-dasharray:none"
id="circle126" />
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3 KiB

View file

@ -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

View file

@ -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)

View file

@ -1,22 +1,92 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
<rect id="Artboard1" x="0" y="0" width="32" height="32" style="fill:none;"/>
<g id="Artboard11" serif:id="Artboard1">
<g transform="matrix(1.03705,0,0,1.03705,-0.460588,-0.659827)">
<g id="BG">
<path d="M30.337,8.833C30.337,4.841 27.096,1.601 23.104,1.601L8.64,1.601C4.649,1.601 1.408,4.841 1.408,8.833L1.408,23.297C1.408,27.288 4.649,30.529 8.64,30.529L23.104,30.529C27.096,30.529 30.337,27.288 30.337,23.297L30.337,8.833Z" style="fill:none;stroke:rgb(225,142,57);stroke-width:0.96px;"/>
<svg
width="100%"
height="100%"
viewBox="0 0 32 32"
version="1.1"
xml:space="preserve"
style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;"
id="svg86"
sodipodi:docname="transition.svg"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:serif="http://www.serif.com/"><defs
id="defs90" /><sodipodi:namedview
id="namedview88"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="17.46875"
inkscape:cx="16"
inkscape:cy="16.257603"
inkscape:window-width="1302"
inkscape:window-height="737"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="Transition" />
<rect
id="Artboard1"
x="0"
y="0"
width="32"
height="32"
style="fill:none;" />
<g
id="Artboard11"
serif:id="Artboard1">
<g
transform="matrix(1.03705,0,0,1.03705,-0.460588,-0.659827)"
id="g70"
style="stroke:#ffdf00;stroke-opacity:1">
<g
id="BG"
style="stroke:#ffdf00;stroke-opacity:1">
<path
d="M30.337,8.833C30.337,4.841 27.096,1.601 23.104,1.601L8.64,1.601C4.649,1.601 1.408,4.841 1.408,8.833L1.408,23.297C1.408,27.288 4.649,30.529 8.64,30.529L23.104,30.529C27.096,30.529 30.337,27.288 30.337,23.297L30.337,8.833Z"
style="fill:none;stroke:#ffdf00;stroke-width:0.96px;stroke-opacity:1"
id="path67" />
</g>
</g>
<g id="Transition">
<g transform="matrix(0.59386,-0.00129228,-0.00129228,0.999996,1.73018,-0.223543)">
<path d="M14.852,23.427C30.642,25.277 38.781,18.528 34.54,10.944" style="fill:none;stroke:rgb(225,142,57);stroke-width:2.44px;"/>
<g
id="Transition">
<g
transform="matrix(0.59386,-0.00129228,-0.00129228,0.999996,1.73018,-0.223543)"
id="g74"
style="stroke:#ffdf00;stroke-opacity:1">
<path
d="M14.852,23.427C30.642,25.277 38.781,18.528 34.54,10.944"
style="fill:none;stroke:#ffdf00;stroke-width:2.44px;stroke-opacity:1"
id="path72" />
</g>
<g transform="matrix(1.36246,0,0,1.36246,-3.81851,-16.9755)">
<circle cx="19.207" cy="19.263" r="4.404" style="fill:rgb(225,142,57);"/>
<g
transform="matrix(1.36246,0,0,1.36246,-3.81851,-16.9755)"
id="g78">
<circle
cx="19.207"
cy="19.263"
r="4.404"
style="fill:#ffdf00;fill-opacity:1"
id="circle76" />
</g>
<g transform="matrix(1.36246,0,0,1.36246,-16.9151,-2.76732)">
<circle cx="19.207" cy="19.263" r="4.404" style="fill:rgb(225,142,57);"/>
<g
transform="matrix(1.36246,0,0,1.36246,-16.9151,-2.76732)"
id="g82"
style="fill:#ffdf00;fill-opacity:1">
<circle
cx="19.207"
cy="19.263"
r="4.404"
style="fill:#ffdf00;fill-opacity:1"
id="circle80" />
</g>
</g>
</g>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before After
Before After

View file

@ -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]