diff --git a/godot/assets/blocks/blocks-coin.png b/godot/assets/blocks/blocks-coin.png
new file mode 100644
index 0000000..89490ac
--- /dev/null
+++ b/godot/assets/blocks/blocks-coin.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:c3f5e717172d807af12dd086c3eccf6c747c0dc65de494c7464a7eefad665f99
+size 850
diff --git a/godot/assets/blocks/blocks-coin.png.import b/godot/assets/blocks/blocks-coin.png.import
new file mode 100644
index 0000000..bd3a6c6
--- /dev/null
+++ b/godot/assets/blocks/blocks-coin.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/blocks-coin.png-e02d021b2492bebc2d42f6607de594d0.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/blocks/blocks-coin.png"
+dest_files=[ "res://.import/blocks-coin.png-e02d021b2492bebc2d42f6607de594d0.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=false
+svg/scale=1.0
diff --git a/godot/assets/blocks/blocks-exclamation.png b/godot/assets/blocks/blocks-exclamation.png
new file mode 100644
index 0000000..96b9028
--- /dev/null
+++ b/godot/assets/blocks/blocks-exclamation.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:d03bd5d598e78759aff6e22dd75d1e4674bdb8235e03897679ed16fd9d70d06c
+size 839
diff --git a/godot/assets/blocks/blocks-exclamation.png.import b/godot/assets/blocks/blocks-exclamation.png.import
new file mode 100644
index 0000000..bb9f2a2
--- /dev/null
+++ b/godot/assets/blocks/blocks-exclamation.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/blocks-exclamation.png-3d4ad82f7288be44d67e956f3c0bebbc.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/blocks/blocks-exclamation.png"
+dest_files=[ "res://.import/blocks-exclamation.png-3d4ad82f7288be44d67e956f3c0bebbc.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=false
+svg/scale=1.0
diff --git a/godot/assets/blocks/blocks-lock.png b/godot/assets/blocks/blocks-lock.png
new file mode 100644
index 0000000..4059e1b
--- /dev/null
+++ b/godot/assets/blocks/blocks-lock.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:9b7d1c159057b02a4ef86c3eb3526e208d7dbacf7022b104dcae0fbd3cbd08fa
+size 10037
diff --git a/godot/assets/blocks/blocks-lock.png.import b/godot/assets/blocks/blocks-lock.png.import
new file mode 100644
index 0000000..8043038
--- /dev/null
+++ b/godot/assets/blocks/blocks-lock.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/blocks-lock.png-e62b69c90efbafbcd301ed5c5a597fa0.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/blocks/blocks-lock.png"
+dest_files=[ "res://.import/blocks-lock.png-e62b69c90efbafbcd301ed5c5a597fa0.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=false
+svg/scale=1.0
diff --git a/godot/assets/blocks/blocks-normal.png b/godot/assets/blocks/blocks-normal.png
new file mode 100644
index 0000000..7bb808f
--- /dev/null
+++ b/godot/assets/blocks/blocks-normal.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6161973675876daf47bf373fabff792851ee40751f3982d797237f778785a1ae
+size 721
diff --git a/godot/assets/blocks/blocks-normal.png.import b/godot/assets/blocks/blocks-normal.png.import
new file mode 100644
index 0000000..1ceda52
--- /dev/null
+++ b/godot/assets/blocks/blocks-normal.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/blocks-normal.png-4af7780b7fe056a41734dfa530cd81c4.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/blocks/blocks-normal.png"
+dest_files=[ "res://.import/blocks-normal.png-4af7780b7fe056a41734dfa530cd81c4.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=false
+svg/scale=1.0
diff --git a/godot/assets/button.png b/godot/assets/button.png
new file mode 100644
index 0000000..4feceba
--- /dev/null
+++ b/godot/assets/button.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:5342b91195a92698fa6c4ce612410a90cfa6be378bdad6eba4d937fb75f20ce3
+size 697
diff --git a/godot/assets/button.png.import b/godot/assets/button.png.import
new file mode 100644
index 0000000..0098d5f
--- /dev/null
+++ b/godot/assets/button.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/button.png-c79155b6e84601a7c5a042250ad77b07.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/button.png"
+dest_files=[ "res://.import/button.png-c79155b6e84601a7c5a042250ad77b07.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=false
+svg/scale=1.0
diff --git a/godot/assets/coin.png b/godot/assets/coin.png
new file mode 100644
index 0000000..83175d5
--- /dev/null
+++ b/godot/assets/coin.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:1a882327de89f19ce8d7c1d7b499caf19ac0a323f72326c1adc522c7762c4be5
+size 709
diff --git a/godot/assets/coin.png.import b/godot/assets/coin.png.import
new file mode 100644
index 0000000..b18e5a3
--- /dev/null
+++ b/godot/assets/coin.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/coin.png-f04b9cd408b88aba3ab0966b4da32df0.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/coin.png"
+dest_files=[ "res://.import/coin.png-f04b9cd408b88aba3ab0966b4da32df0.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=false
+svg/scale=1.0
diff --git a/godot/assets/flag.png b/godot/assets/flag.png
new file mode 100644
index 0000000..81911f2
--- /dev/null
+++ b/godot/assets/flag.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:39f152c42bc749e0e6acf2a253598b2ce27797499332a4092bc150df162012a9
+size 903
diff --git a/godot/assets/flag.png.import b/godot/assets/flag.png.import
new file mode 100644
index 0000000..5ad2205
--- /dev/null
+++ b/godot/assets/flag.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/flag.png-29c6a06ab0a1d25cfcfa38ea2a7baffa.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/flag.png"
+dest_files=[ "res://.import/flag.png-29c6a06ab0a1d25cfcfa38ea2a7baffa.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=false
+svg/scale=1.0
diff --git a/godot/assets/gems/gem1.png b/godot/assets/gems/gem1.png
new file mode 100644
index 0000000..8f2565b
--- /dev/null
+++ b/godot/assets/gems/gem1.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:bc6ff8a090d5999ae1593bcd2f6d9ae90f014f3495f6d0398f727dad75123841
+size 695
diff --git a/godot/assets/gems/gem1.png.import b/godot/assets/gems/gem1.png.import
new file mode 100644
index 0000000..f8e7e0b
--- /dev/null
+++ b/godot/assets/gems/gem1.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/gem1.png-11065ad0e2eb5b112fc6a0edf260e97b.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/gems/gem1.png"
+dest_files=[ "res://.import/gem1.png-11065ad0e2eb5b112fc6a0edf260e97b.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=false
+svg/scale=1.0
diff --git a/godot/assets/gems/gem2.png b/godot/assets/gems/gem2.png
new file mode 100644
index 0000000..82b6fd5
--- /dev/null
+++ b/godot/assets/gems/gem2.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:181efc41fbb66a8ce641bc515737a109612237c6d1cc09bed8497d5a46a59c0e
+size 707
diff --git a/godot/assets/gems/gem2.png.import b/godot/assets/gems/gem2.png.import
new file mode 100644
index 0000000..59ac929
--- /dev/null
+++ b/godot/assets/gems/gem2.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/gem2.png-72573c34c050e40128e078d94f847e09.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/gems/gem2.png"
+dest_files=[ "res://.import/gem2.png-72573c34c050e40128e078d94f847e09.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=false
+svg/scale=1.0
diff --git a/godot/assets/gems/gem3.png b/godot/assets/gems/gem3.png
new file mode 100644
index 0000000..19dd614
--- /dev/null
+++ b/godot/assets/gems/gem3.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:e53b83b4b284d28250a7742f4192183f0e0c194f889422a58552ba6114b38a39
+size 671
diff --git a/godot/assets/gems/gem3.png.import b/godot/assets/gems/gem3.png.import
new file mode 100644
index 0000000..1604e59
--- /dev/null
+++ b/godot/assets/gems/gem3.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/gem3.png-471deee972b4e29e8d552e3b1ebf7645.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/gems/gem3.png"
+dest_files=[ "res://.import/gem3.png-471deee972b4e29e8d552e3b1ebf7645.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=false
+svg/scale=1.0
diff --git a/godot/assets/health.png b/godot/assets/health.png
new file mode 100644
index 0000000..9dc09ae
--- /dev/null
+++ b/godot/assets/health.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3477fd291a49199237fe96cdc337055eeab9c95a51e0ba00bba55d0ece827f17
+size 830
diff --git a/godot/assets/health.png.import b/godot/assets/health.png.import
new file mode 100644
index 0000000..24fd710
--- /dev/null
+++ b/godot/assets/health.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/health.png-00457dc45e4c240f12819344f6504f87.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/health.png"
+dest_files=[ "res://.import/health.png-00457dc45e4c240f12819344f6504f87.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=false
+svg/scale=1.0
diff --git a/godot/assets/key.png b/godot/assets/key.png
new file mode 100644
index 0000000..019bd92
--- /dev/null
+++ b/godot/assets/key.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:4d0a8a72855134da1af9a1dd6f8645dbc4071f65cf077c11089e630f3af6a733
+size 702
diff --git a/godot/assets/key.png.import b/godot/assets/key.png.import
new file mode 100644
index 0000000..6a0e560
--- /dev/null
+++ b/godot/assets/key.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/key.png-a97df9ba773df86f934812b8b28ef996.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/key.png"
+dest_files=[ "res://.import/key.png-a97df9ba773df86f934812b8b28ef996.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=false
+svg/scale=1.0
diff --git a/godot/assets/spring.png b/godot/assets/spring.png
new file mode 100644
index 0000000..e9c449c
--- /dev/null
+++ b/godot/assets/spring.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:cd115cd0b411a7c663b6e60a840e12763496e2bca00e2556fa50fd0f34f1f0d3
+size 770
diff --git a/godot/assets/spring.png.import b/godot/assets/spring.png.import
new file mode 100644
index 0000000..555135a
--- /dev/null
+++ b/godot/assets/spring.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/spring.png-3b3902b04c9197ab9097abc899b361d1.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/spring.png"
+dest_files=[ "res://.import/spring.png-3b3902b04c9197ab9097abc899b361d1.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=false
+svg/scale=1.0
diff --git a/godot/assets/switch.png b/godot/assets/switch.png
new file mode 100644
index 0000000..869c02f
--- /dev/null
+++ b/godot/assets/switch.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:57e5096a649e708ef9c5a55726fd4743bb09a544d2ece84578b85ac0d9ad2bb4
+size 916
diff --git a/godot/assets/switch.png.import b/godot/assets/switch.png.import
new file mode 100644
index 0000000..0bab12e
--- /dev/null
+++ b/godot/assets/switch.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/switch.png-7f9d21c701660c7107ee136e6649068b.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/switch.png"
+dest_files=[ "res://.import/switch.png-7f9d21c701660c7107ee136e6649068b.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=false
+svg/scale=1.0
diff --git a/godot/tilesets/tiles.tsx b/godot/tilesets/tiles.tsx
index 8e80eba..547a5ff 100644
--- a/godot/tilesets/tiles.tsx
+++ b/godot/tilesets/tiles.tsx
@@ -239,7 +239,7 @@
-
+
diff --git a/src/state_machine/State.cpp b/src/state_machine/State.cpp
index 29efa48..2763449 100644
--- a/src/state_machine/State.cpp
+++ b/src/state_machine/State.cpp
@@ -25,12 +25,12 @@ void State::_init()
void State::_state_enter(const String state, const Array args)
{
- WARN_PRINT("State " + state + " is missing its _state_enter method!");
+ WARN_PRINT("State " + get_state_machine()->get_current_state() + " is missing its _state_enter method!");
}
void State::_state_exit(const String state, const Array args)
{
- WARN_PRINT("State " + state + " is missing its _state_exit method!");
+ WARN_PRINT("State " + get_state_machine()->get_current_state() + " is missing its _state_exit method!");
}
void State::set_parent(Node *parent)
diff --git a/src/state_machine/StateMachine.cpp b/src/state_machine/StateMachine.cpp
index 4370842..73b1f9d 100644
--- a/src/state_machine/StateMachine.cpp
+++ b/src/state_machine/StateMachine.cpp
@@ -34,7 +34,15 @@ void StateMachine::_ready()
connect("tree_entered", this, "_on_StateMachine_tree_entered");
connect("tree_exiting", this, "_on_StateMachine_tree_exiting");
parent = get_parent();
- set_current_state(get_default_state());
+ add_states();
+ if (has(get_default_state()))
+ {
+ set_current_state(get_default_state());
+ }
+ else
+ {
+ WARN_PRINT("The selected default state " + get_default_state() + " doesn't exist!");
+ }
setup();
}
@@ -46,13 +54,13 @@ void StateMachine::setup()
{
if (children.size() > 0)
{
- WARN_PRINT("State machine doesn't have a default state set, using first child!");
+ WARN_PRINT("The state machine doesn't have a default state set, using first child!");
auto child = Object::cast_to(children[0].operator Object*());
set_current_state(child->get_name());
}
else
{
- ERR_PRINT("State machine doesn't have a default state set and has no child states!");
+ ERR_PRINT("The state machine doesn't have a default state set and has no child states!");
return;
}
}
@@ -60,7 +68,6 @@ void StateMachine::setup()
for (uint8_t i = 0; i < children.size(); i++)
{
auto child = Object::cast_to(children[i].operator Object*());
- add_state(child->get_name(), child);
child->call("set_state_machine", this);
@@ -72,7 +79,24 @@ void StateMachine::setup()
}
}
- this->call("_state_enter", get_current_state());
+ Node *state_node = Object::cast_to(this->states[get_current_state()]);
+ if (state_node->has_method("_state_enter"))
+ {
+ this->call("_state_enter", get_current_state());
+ }
+ else {
+ WARN_PRINT("The state " + get_current_state() + " doesn't have a _state_enter method!");
+ }
+}
+
+void StateMachine::add_states()
+{
+ auto children = get_children();
+ for (uint8_t i = 0; i < children.size(); i++)
+ {
+ auto child = Object::cast_to(children[i].operator Object*());
+ add_state(child->get_name(), child);
+ }
}
void StateMachine::add_state(const String state, Node *child)
@@ -111,8 +135,31 @@ void StateMachine::change(const String state, const Array &args)
return this->restart(state, args);
}
+ if (!has(state))
+ {
+ WARN_PRINT("The state " + state + " does not exist, called from state " + get_current_state() + "!");
+ return;
+ }
+
auto previous_state = get_current_state();
- auto exiting = this->call("_state_exit", state, args);
+
+ Variant exiting;
+ Node *state_node = Object::cast_to(this->states[previous_state]);
+ if (state_node)
+ {
+ if (state_node->has_method("_state_exit"))
+ {
+ exiting = this->call("_state_exit", state, args);
+ }
+ else
+ {
+ WARN_PRINT("The state " + get_current_state() + " doesn't have a _state_exit method!");
+ }
+ }
+ else
+ {
+ ERR_PRINT("Could not get current state node for " + get_current_state() + "!");
+ }
if (get_current_state() != "")
{
@@ -132,7 +179,23 @@ void StateMachine::change(const String state, const Array &args)
auto child = Object::cast_to(states[get_current_state()].operator Object*());
this->add_child(child);
- this->call("_state_enter", previous_state, args);
+ state_node = Object::cast_to(this->states[get_current_state()]);
+ if (state_node)
+ {
+ if (state_node->has_method("_state_enter"))
+ {
+ this->call("_state_enter", previous_state, args);
+ }
+ else
+ {
+ WARN_PRINT("The state " + get_current_state() + " doesn't have a _state_enter method!");
+ }
+ }
+ else
+ {
+ ERR_PRINT("Could not get current state node for " + get_current_state() + "!");
+ }
+
this->emit_signal("state_entered", get_current_state());
if (debug)
{
@@ -143,11 +206,23 @@ void StateMachine::change(const String state, const Array &args)
Variant StateMachine::call(const String method, const Array &args)
{
auto node = Object::cast_to(states[get_current_state()].operator Object*());
- if (node != nullptr)
+ if (node)
{
- return node->call(method, args);
+ if (node->has_method(method))
+ {
+ return node->call(method, args);
+ }
+ else
+ {
+ WARN_PRINT("The state " + get_current_state() + " doesn't contain the method " + method + "!");
+ return Variant();
+ }
+ }
+ else
+ {
+ ERR_PRINT("Could not get current state node for " + get_current_state() + "!");
+ return Variant();
}
- return Variant();
}
Variant StateMachine::_call(const String method, const Array &args)
@@ -196,7 +271,7 @@ void StateMachine::_on_StateMachine_tree_exiting()
for (uint8_t i = 0; i < keys.size(); i++)
{
auto child = Object::cast_to(states[keys[i]].operator Object*());
- if (child != nullptr)
+ if (child)
{
auto children = get_children();
if (!children.has(child))
@@ -204,5 +279,10 @@ void StateMachine::_on_StateMachine_tree_exiting()
this->add_child(child);
}
}
+ else
+ {
+ ERR_PRINT("Could not get child node!");
+ return;
+ }
}
}
diff --git a/src/state_machine/StateMachine.h b/src/state_machine/StateMachine.h
index 02789ba..0fdb8d7 100644
--- a/src/state_machine/StateMachine.h
+++ b/src/state_machine/StateMachine.h
@@ -43,6 +43,12 @@ namespace godot
*/
Dictionary states;
+ /**
+ * @brief This adds all nodes of the states machine as states in the machine.
+ *
+ */
+ void add_states();
+
/**
* @brief This adds a state to the list of states in the state machine.
*
@@ -51,6 +57,13 @@ namespace godot
*/
void add_state(const String state, Node *child);
+ /**
+ * @brief Set the current state object.
+ *
+ * @param[in] current_state The current state that is running.
+ */
+ void set_current_state(const String current_state);
+
public:
/**
* @brief This method registers classes with Godot.
@@ -157,6 +170,13 @@ namespace godot
*/
String get_default_state();
+ /**
+ * @brief Get the current state object.
+ *
+ * @return String The current running state.
+ */
+ String get_current_state();
+
/**
* @brief Set the debug object.
*
@@ -172,20 +192,6 @@ namespace godot
*/
bool get_debug();
- /**
- * @brief Set the current state object.
- *
- * @param[in] current_state The current state that is running.
- */
- void set_current_state(const String current_state);
-
- /**
- * @brief Get the current state object.
- *
- * @return String The current running state.
- */
- String get_current_state();
-
/**
* @brief This method is called when the signal tree_entered is emitted.
*