From 1bd258dbaed639b68f9173cfa192dbb75d985d96 Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Mon, 2 Oct 2023 00:10:24 -0700 Subject: [PATCH] fix animation inconsistent root nodes --- Assets/Animations/npc_hurt.res | Bin 0 -> 860 bytes Assets/Animations/npc_stun.res | Bin 0 -> 298 bytes Assets/Animations/stun.res | Bin 458 -> 452 bytes Characters/Character.cs | 13 +-- Characters/DocCenturion.tscn | 161 +++------------------------------ Characters/DocLegionary.tscn | 7 +- Characters/ExampleEnemy.tscn | 106 ++++++---------------- Characters/Player.tscn | 19 ++-- Extensions/AnimationPlayer.cs | 42 +++++++++ Utils/AnimationManager.cs | 4 +- 10 files changed, 108 insertions(+), 244 deletions(-) create mode 100644 Assets/Animations/npc_hurt.res create mode 100644 Assets/Animations/npc_stun.res diff --git a/Assets/Animations/npc_hurt.res b/Assets/Animations/npc_hurt.res new file mode 100644 index 0000000000000000000000000000000000000000..db668400e2bdf0d3db433f17d167a82d246a3f26 GIT binary patch literal 860 zcmV-i1Ec&>Q$s@n000005C8x>4FCW{0{{RhwJ-f(I}Fts0QTKxK_HDb9VCPRB-2`n z1OWh(fCPY6kz5>!ytnP{_O@T8ja-q-(@gM*9nKv15GkPBcb}XFFmnuxJm=kK+CK2D zwG>MLOaNE_B_0m<#&4TlwwxE2r9tN%BT3n}+@|1tOYPyM&> zixdGUCQhVm{I7gOmy*DboUpfplEZ(C{}lhH|CT=_D|zFl)9aw-?2WqmsH#X?+8%dh zZ_WVcIwU#%znr_3ELp4B>@2P}W5yc&W@Y*xqv`kIKY@oN?1mjzjv8#bAh=%k@V~%o zYg`g*G9YAxW@BnW7C#zbUYvo`_Jk*6uJ}xD$VbHi}$#4)Wf{3!J3fbN* z`(N?)Ak`{{VHk#C*L7Xjby=2WS(a5tELtk!z&*+>4V>%sHjV)uKqDY(3gH>?fGQO% zLUfyMSEd)J%D2ficbki4gQfE!l`K>zqv1m;0T4N%s1Au#q9%%O7zz_4M7VGuJa9mD zaBNJcG#W72WGui?aFGDP=6zGWh@8j?mu5O%xr3ddnZ6i+&Zu!^Gb54|B`FPKumX{p zp)n5<;Ikl1Vi3j%Ap$2r2$76PkR&BVO|=328J*xdaR_3#NAs<&eGK*0$%8ZMf|dpL3_(0F+|F`)J3oCie#~()PR6 z6Y~{FXTueqcYz8e*&uch_wvRVMw2Er;dj6LkaP-Uu8+sFU|-CV34a+Nf3Cv~+S@Rk z#}zH3MXnVnSmVRyg9+z_qXiHc$qGAGb_dK^W-)as^grTsp8V@MGo|p^N~1x|^|;@J z6nKjNN6B)MCirYjwieE!%xDk^8HLMLNbY0qQyF4EA=Y{WD1sB^ZIUa{?wJ^3IhaMn z`E=_mx=(O(?{^TqvpNcc0SXYciFLS9P%>4wC_DKCgR?UYMZ>hX@KW_lKfIG(UdS@! zO9&`n%raDkifeU-lcn265ErwJWdk~oSEo%#jvlU2Q7!gB49wgFA)V_4Agug1O<7-r mbTj2qQiBO~Gfx5^v;9Rb^+^8{NdAc=72=dlU8WvVQ$s_PQj2i_ literal 0 HcmV?d00001 diff --git a/Assets/Animations/npc_stun.res b/Assets/Animations/npc_stun.res new file mode 100644 index 0000000000000000000000000000000000000000..58c550fb86a2e66f63d0a080a2ad680f78b4ce08 GIT binary patch literal 298 zcmV+_0oDFeQ$s@n000005C8!50RR9J0RR9fwJ-f(^Z-Q&01}KUEpScJ82q{V|Ma8( z9Shi`J&4?d7JMYT_cHsTRHo>{p&d985#T$SpReW?NeUAYCicX5NHJG1I&8Xf*Th;*3)|bI;`u7^-3-EqqHW;n&7r3{ymxXyjeTB;sD7edA wBdo$DfsX`MfanXX%naOuJO?bwOtJ<_lAV04+LHXacLLBl#pDea3sO@OV literal 0 HcmV?d00001 diff --git a/Assets/Animations/stun.res b/Assets/Animations/stun.res index 238ca6a19e6136adce59b68fb00fa73acf6b2e8f..6d80a1c8a3eabb69f905b8eba2b042cdfcaeb50a 100644 GIT binary patch literal 452 zcmV;#0XzOuQ$s@n000005C8yq0{{T50RR9fwJ-f(c>)y;0G3ieGf-{Q0T8umMi4WN z$}>}Y`FRj&pS|0y3|pbub-^Diq1EnN)B1rR9>6IyhYvn6@I;aVE&wn9F#y)IRK+H5 z{SOg&Qr?c0ZZ7^C{8xCz2FPS$#4`T}T+Z0=iW2kx;Qzq?=)b@p)mj`-F2k$sI_VV~ zzSPq$!*Pd#wdpo*HLr=zX>qzkuJvE?y`ZFgrQzL*6)E*Whjkp3rx zoVQ{~tl6>SUS^DQ7K{H;(^x5H&vsz_a5$~oa^akYG#Z+XhO!MSianDuDU&kk8O2#5 zeI%^?G;Mn#mC6HwLhtjxjJCZ9Q0Ss*8}Aic;{OC83Q4G8IWi2<1Q|(TN(XQP5vo!T z5@1Cc%VGx1*~0q2Gt7^Vo7r^^NS-0& z=Ne&5sf`y551C-Kp>^Zma`*E+xpt*H(MLhYqJcxI8($J#R*Ei`wmj_WVp(k&t>un2 ue~heH9oGj9qLB(k-wj+$9!}wY`=}d^dh)%i;p>233if3GkCO>fQ$s_H-p_>q literal 458 zcmV;*0X6MmWoFpRk_VjGk)6fh7N1G!Ct*4J}A*K<8z z5LU-S;aXe=!!n1%Wa4Bp6%NHa7c6rcWGX5cmT6YgI`|`y2jdS(sA0J>RWo50q_C6& zZ~~F4QV$XUWg&|xhGy8p`oHB%Ih{NSfS@;q5iu*~dvPpaMR*NbolghIbq>hhA&@d7 z3H-hT0;*7Ytiv*2^EUH#?#sDuqMY*{V)Tka(hykiAAP<54=y3c6Vt(x=G A4*&oF diff --git a/Characters/Character.cs b/Characters/Character.cs index da78557..13f91e6 100644 --- a/Characters/Character.cs +++ b/Characters/Character.cs @@ -123,7 +123,7 @@ public partial class Character : CharacterBody2D, IFaction if (StunTime > 0 && !StunAnimation.IsPlaying()) { - StunAnimation.Play("stun"); + StunAnimation.TryPlayAny("stun", "npc_stun/stun"); } else if (StunTime < 0 && StunAnimation.IsPlaying()) { @@ -177,9 +177,9 @@ public partial class Character : CharacterBody2D, IFaction /// public virtual void Die() { - if (HurtAnimation.HasAnimation("death")) + if (HurtAnimation.TryPlayAny(out var name, "death", "npc_hurt/death")) { - HurtAnimation.Play("death"); + HurtAnimation.Play(name); HurtAnimation.AnimationFinished += (StringName name) => QueueFree(); } @@ -342,11 +342,8 @@ public partial class Character : CharacterBody2D, IFaction if (HurtAnimation is not null && Health > 0) { HurtAnimation.Stop(); - HurtAnimation.Play("hurt"); - if (HurtAnimation.HasAnimation("hurt_flash")) - { - HurtAnimation.Queue("hurt_flash"); - } + HurtAnimation.TryPlayAny("hurt", "npc_hurt/hurt"); + HurtAnimation.TryQueue("hurt_flash"); } if (this.GetNode("Effects/HurtSound") is AudioStreamPlayer2D sound) diff --git a/Characters/DocCenturion.tscn b/Characters/DocCenturion.tscn index f3d7959..4adbab9 100644 --- a/Characters/DocCenturion.tscn +++ b/Characters/DocCenturion.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=41 format=3 uid="uid://dhamcei7tfta8"] +[gd_scene load_steps=36 format=3 uid="uid://dhamcei7tfta8"] [ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="1_msit5"] [ext_resource type="Script" path="res://Characters/Enemy.cs" id="2_pkari"] @@ -9,7 +9,8 @@ [ext_resource type="Script" path="res://State/Thinker/CenturionAttackState.cs" id="7_n2slg"] [ext_resource type="Script" path="res://State/Thinker/IdleState.cs" id="8_5neew"] [ext_resource type="Script" path="res://Utils/AnimationManager.cs" id="9_fgnr2"] -[ext_resource type="Animation" uid="uid://8e8r3y1imvsx" path="res://Assets/Animations/stun.res" id="10_1erll"] +[ext_resource type="AnimationLibrary" uid="uid://xs6g84fkepjr" path="res://Assets/Animations/npc_hurt.res" id="10_bbwbd"] +[ext_resource type="AnimationLibrary" uid="uid://f1aqhnxndybx" path="res://Assets/Animations/npc_stun.res" id="11_a0f8a"] [ext_resource type="Material" uid="uid://bat28samf7ukd" path="res://Assets/Sprites/Particles/NPCDamageProcessMaterial.tres" id="11_p7yev"] [ext_resource type="Texture2D" uid="uid://bd8l8kafb42dt" path="res://Assets/Sprites/Particles/circle.png" id="12_t3nnt"] [ext_resource type="Material" uid="uid://2tsvsp45elru" path="res://Assets/Sprites/Particles/NPCDeathParticles.tres" id="13_nm3wd"] @@ -66,7 +67,7 @@ loop_mode = 1 tracks/0/type = "value" tracks/0/imported = false tracks/0/enabled = true -tracks/0/path = NodePath("../Sprites/Node2D/Character:frame") +tracks/0/path = NodePath("./Sprites/Node2D/Character:frame") tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/keys = { @@ -92,158 +93,20 @@ _data = { "RESET": SubResource("Animation_adxyh") } -[sub_resource type="Animation" id="Animation_k6l16"] -length = 0.001 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:material:shader_parameter/intensity") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [0.0] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath(".:material:shader_parameter/alpha_modulate") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [1.0] -} -tracks/2/type = "value" -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/path = NodePath("%Effects/DeathParticles:emitting") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [false] -} -tracks/3/type = "value" -tracks/3/imported = false -tracks/3/enabled = true -tracks/3/path = NodePath("%Effects/HurtParticles:emitting") -tracks/3/interp = 1 -tracks/3/loop_wrap = true -tracks/3/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [false] -} - -[sub_resource type="Animation" id="Animation_lhc4c"] -resource_name = "death" -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath("%Effects/DeathParticles:emitting") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [true] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath(".:material:shader_parameter/alpha_modulate") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0, 0.1), -"transitions": PackedFloat32Array(1, 1), -"update": 0, -"values": [1.0, 0.0] -} - -[sub_resource type="Animation" id="Animation_0vgmg"] -resource_local_to_scene = true -resource_name = "hurt" -length = 0.2 -step = 0.05 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:material:shader_parameter/intensity") -tracks/0/interp = 2 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0, 0.05, 0.1, 0.2), -"transitions": PackedFloat32Array(4, 4, 4, 4), -"update": 0, -"values": [1.0, 0.0, 1.0, 0.0] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath("%Effects/HurtParticles:emitting") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [true] -} -tracks/2/type = "method" -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/path = NodePath("%Effects/HurtParticles") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/keys = { -"times": PackedFloat32Array(0.1), -"transitions": PackedFloat32Array(1), -"values": [{ -"args": [], -"method": &"restart" -}] -} - -[sub_resource type="AnimationLibrary" id="AnimationLibrary_rc55s"] -_data = { -"RESET": SubResource("Animation_k6l16"), -"death": SubResource("Animation_lhc4c"), -"hurt": SubResource("Animation_0vgmg") -} - -[sub_resource type="Animation" id="Animation_7j54f"] -length = 0.001 - -[sub_resource type="AnimationLibrary" id="AnimationLibrary_kks2p"] -_data = { -"RESET": SubResource("Animation_7j54f"), -"stun": ExtResource("10_1erll") -} - [sub_resource type="CanvasTexture" id="CanvasTexture_pited"] diffuse_texture = ExtResource("14_o5rd3") [sub_resource type="Gradient" id="Gradient_b2o0f"] colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 0) -[sub_resource type="GradientTexture1D" id="GradientTexture1D_iyaih"] +[sub_resource type="GradientTexture1D" id="GradientTexture1D_tfqqu"] gradient = SubResource("Gradient_b2o0f") [sub_resource type="Curve" id="Curve_30p4b"] _data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(0.2, 1), 0.0, 0.0, 0, 0, Vector2(1, 0.5), 0.0, 0.0, 0, 0] point_count = 3 -[sub_resource type="CurveTexture" id="CurveTexture_5uulw"] +[sub_resource type="CurveTexture" id="CurveTexture_pcpms"] curve = SubResource("Curve_30p4b") [sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_qdhau"] @@ -262,9 +125,9 @@ tangential_accel_min = 8.0 tangential_accel_max = 8.0 scale_min = 0.13 scale_max = 0.25 -scale_curve = SubResource("CurveTexture_5uulw") +scale_curve = SubResource("CurveTexture_pcpms") color = Color(1, 0, 0, 1) -color_ramp = SubResource("GradientTexture1D_iyaih") +color_ramp = SubResource("GradientTexture1D_tfqqu") [sub_resource type="RectangleShape2D" id="RectangleShape2D_bfqew"] size = Vector2(12, 8) @@ -338,11 +201,13 @@ debug_enabled = true script = ExtResource("9_fgnr2") [node name="Movement" type="AnimationPlayer" parent="Animations"] +root_node = NodePath("../..") libraries = { "": SubResource("AnimationLibrary_uqsue") } [node name="Attack" type="AnimationPlayer" parent="Animations"] +root_node = NodePath("../..") libraries = { "": SubResource("AnimationLibrary_sxq14") } @@ -350,12 +215,13 @@ libraries = { [node name="Hurt" type="AnimationPlayer" parent="Animations"] root_node = NodePath("../..") libraries = { -"": SubResource("AnimationLibrary_rc55s") +"": ExtResource("10_bbwbd") } [node name="Stun" type="AnimationPlayer" parent="Animations"] +root_node = NodePath("../..") libraries = { -"": SubResource("AnimationLibrary_kks2p") +"": ExtResource("11_a0f8a") } [node name="Effects" type="Node2D" parent="."] @@ -403,6 +269,7 @@ use_parent_material = true texture = ExtResource("16_6uxxp") offset = Vector2(0, -12) hframes = 7 +frame = 1 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, -4) diff --git a/Characters/DocLegionary.tscn b/Characters/DocLegionary.tscn index a8d41ee..c4158d1 100644 --- a/Characters/DocLegionary.tscn +++ b/Characters/DocLegionary.tscn @@ -51,7 +51,7 @@ loop_mode = 1 tracks/0/type = "value" tracks/0/imported = false tracks/0/enabled = true -tracks/0/path = NodePath("../Sprites/Node2D/Character:frame") +tracks/0/path = NodePath("%Sprites/Node2D/Character:frame") tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/keys = { @@ -68,7 +68,7 @@ loop_mode = 1 tracks/0/type = "value" tracks/0/imported = false tracks/0/enabled = true -tracks/0/path = NodePath("../Sprites/Node2D/Character:frame") +tracks/0/path = NodePath("%Sprites/Node2D/Character:frame") tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/keys = { @@ -351,11 +351,13 @@ target_desired_distance = 16.0 script = ExtResource("9_ssmee") [node name="Movement" type="AnimationPlayer" parent="Animations"] +root_node = NodePath("../..") libraries = { "": SubResource("AnimationLibrary_uqsue") } [node name="Attack" type="AnimationPlayer" parent="Animations"] +root_node = NodePath("../..") libraries = { "": SubResource("AnimationLibrary_sxq14") } @@ -367,6 +369,7 @@ libraries = { } [node name="Stun" type="AnimationPlayer" parent="Animations"] +root_node = NodePath("../..") libraries = { "": SubResource("AnimationLibrary_kks2p") } diff --git a/Characters/ExampleEnemy.tscn b/Characters/ExampleEnemy.tscn index e22addb..027e2d2 100644 --- a/Characters/ExampleEnemy.tscn +++ b/Characters/ExampleEnemy.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=26 format=3 uid="uid://bf55wbq7m1gpp"] +[gd_scene load_steps=19 format=3 uid="uid://bf55wbq7m1gpp"] [ext_resource type="Script" path="res://Characters/Enemy.cs" id="1_2yopk"] [ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="1_fx1w5"] @@ -6,8 +6,10 @@ [ext_resource type="Script" path="res://State/Character/CharacterStateMachine.cs" id="4_424ux"] [ext_resource type="Script" path="res://State/Character/NPCIdleState.cs" id="5_tn4cf"] [ext_resource type="Script" path="res://State/Character/NPCMoveState.cs" id="6_73mr6"] +[ext_resource type="Script" path="res://State/Thinker/ThinkerStateMachine.cs" id="6_and4s"] [ext_resource type="PackedScene" uid="uid://cjgxyhgcyvsv7" path="res://BoundingBoxes/Hurtbox.tscn" id="6_jo0cg"] [ext_resource type="Script" path="res://Items/Inventory.cs" id="7_43gq8"] +[ext_resource type="Script" path="res://State/Thinker/AttackState.cs" id="7_bp1d0"] [ext_resource type="PackedScene" uid="uid://dvqap2uhcah63" path="res://Items/Weapons/Sword.tscn" id="8_s3c8r"] [ext_resource type="AudioStream" uid="uid://njun3e6v4854" path="res://Assets/Sounds/hurt.wav" id="10_n1e64"] @@ -55,91 +57,22 @@ _data = { "hurt": SubResource("Animation_dxevc") } -[sub_resource type="AtlasTexture" id="AtlasTexture_55yt4"] -atlas = ExtResource("3_ocaae") -region = Rect2(0, 0, 24, 24) - -[sub_resource type="AtlasTexture" id="AtlasTexture_xa1bi"] -atlas = ExtResource("3_ocaae") -region = Rect2(24, 0, 24, 24) - -[sub_resource type="AtlasTexture" id="AtlasTexture_hiodl"] -atlas = ExtResource("3_ocaae") -region = Rect2(48, 0, 24, 24) - -[sub_resource type="AtlasTexture" id="AtlasTexture_tok7d"] -atlas = ExtResource("3_ocaae") -region = Rect2(72, 0, 24, 24) - -[sub_resource type="AtlasTexture" id="AtlasTexture_dp8x6"] -atlas = ExtResource("3_ocaae") -region = Rect2(96, 0, 24, 24) - -[sub_resource type="AtlasTexture" id="AtlasTexture_sglor"] -atlas = ExtResource("3_ocaae") -region = Rect2(120, 0, 24, 24) - -[sub_resource type="AtlasTexture" id="AtlasTexture_gb41o"] -atlas = ExtResource("3_ocaae") -region = Rect2(144, 0, 24, 24) - -[sub_resource type="AtlasTexture" id="AtlasTexture_bx6qq"] -atlas = ExtResource("3_ocaae") -region = Rect2(168, 0, 24, 24) - -[sub_resource type="SpriteFrames" id="SpriteFrames_6pejo"] -resource_local_to_scene = true -animations = [{ -"frames": [{ -"duration": 1.0, -"texture": SubResource("AtlasTexture_55yt4") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_xa1bi") -}], -"loop": true, -"name": &"idle", -"speed": 5.0 -}, { -"frames": [{ -"duration": 1.0, -"texture": SubResource("AtlasTexture_hiodl") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_tok7d") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_dp8x6") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_sglor") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_gb41o") -}, { -"duration": 1.0, -"texture": SubResource("AtlasTexture_bx6qq") -}], -"loop": true, -"name": &"move", -"speed": 12.0 -}] - [sub_resource type="RectangleShape2D" id="RectangleShape2D_uict5"] size = Vector2(16, 8) [sub_resource type="RectangleShape2D" id="RectangleShape2D_8lxmf"] size = Vector2(16, 18) -[node name="ExampleEnemy" type="CharacterBody2D" node_paths=PackedStringArray("Sprite", "Inventory", "StateMachine", "Hurtbox")] +[node name="ExampleEnemy" type="CharacterBody2D" node_paths=PackedStringArray("ThinkerStateMachine", "Sprite", "Inventory", "StateMachine", "Hurtbox")] y_sort_enabled = true texture_filter = 3 material = SubResource("ShaderMaterial_ms3xg") collision_layer = 10 collision_mask = 17 script = ExtResource("1_2yopk") +ThinkerStateMachine = NodePath("ThinkerStateMachine") Health = 50.0 -Sprite = NodePath("Sprite") +Sprite = NodePath("Sprites/Node2D/Character") Inventory = NodePath("Inventory") StateMachine = NodePath("StateMachine") Hurtbox = NodePath("Hurtbox") @@ -160,6 +93,14 @@ script = ExtResource("6_73mr6") IdleState = NodePath("../Idle") Character = NodePath("../..") +[node name="ThinkerStateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState")] +script = ExtResource("6_and4s") +InitialState = NodePath("Attack") + +[node name="Attack" type="Node" parent="ThinkerStateMachine" node_paths=PackedStringArray("NPC")] +script = ExtResource("7_bp1d0") +NPC = NodePath("../..") + [node name="Animations" type="Node" parent="."] [node name="HurtAnimation" type="AnimationPlayer" parent="Animations"] @@ -168,11 +109,21 @@ libraries = { "": SubResource("AnimationLibrary_xe5eq") } -[node name="Sprite" type="AnimatedSprite2D" parent="."] +[node name="Sprites" type="Node2D" parent="."] +unique_name_in_owner = true +y_sort_enabled = true use_parent_material = true -position = Vector2(0, -4) -sprite_frames = SubResource("SpriteFrames_6pejo") -animation = &"move" +position = Vector2(-0.5, 0) + +[node name="Node2D" type="Node2D" parent="Sprites"] +use_parent_material = true + +[node name="Character" type="Sprite2D" parent="Sprites/Node2D"] +use_parent_material = true +position = Vector2(0, -8) +texture = ExtResource("3_ocaae") +offset = Vector2(0, -4) +hframes = 46 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, 4) @@ -188,6 +139,7 @@ shape = SubResource("RectangleShape2D_8lxmf") [node name="Inventory" type="Node2D" parent="."] y_sort_enabled = true +position = Vector2(0, -4) script = ExtResource("7_43gq8") [node name="Sword" parent="Inventory" instance=ExtResource("8_s3c8r")] diff --git a/Characters/Player.tscn b/Characters/Player.tscn index d696967..7f9ab70 100644 --- a/Characters/Player.tscn +++ b/Characters/Player.tscn @@ -140,7 +140,7 @@ loop_mode = 1 tracks/0/type = "value" tracks/0/imported = false tracks/0/enabled = true -tracks/0/path = NodePath("../Sprites/Node2D/Character:frame") +tracks/0/path = NodePath("%Sprites/Node2D/Character:frame") tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/keys = { @@ -152,7 +152,7 @@ tracks/0/keys = { tracks/1/type = "method" tracks/1/imported = false tracks/1/enabled = true -tracks/1/path = NodePath("..") +tracks/1/path = NodePath(".") tracks/1/interp = 1 tracks/1/loop_wrap = true tracks/1/keys = { @@ -174,7 +174,7 @@ step = 0.05 tracks/0/type = "value" tracks/0/imported = false tracks/0/enabled = true -tracks/0/path = NodePath("../Sprites/Node2D/Character:rotation") +tracks/0/path = NodePath("%Sprites/Node2D/Character:rotation") tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/keys = { @@ -190,7 +190,7 @@ length = 0.2 tracks/0/type = "value" tracks/0/imported = false tracks/0/enabled = true -tracks/0/path = NodePath("../Sprites/Node2D/Character:frame") +tracks/0/path = NodePath("%Sprites/Node2D/Character:frame") tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/keys = { @@ -252,7 +252,7 @@ tracks/2/keys = { tracks/3/type = "value" tracks/3/imported = false tracks/3/enabled = true -tracks/3/path = NodePath("../Sprites/CharacterEffects/Cast:visible") +tracks/3/path = NodePath("%Sprites/CharacterEffects/Cast:visible") tracks/3/interp = 1 tracks/3/loop_wrap = true tracks/3/keys = { @@ -264,7 +264,7 @@ tracks/3/keys = { tracks/4/type = "value" tracks/4/imported = false tracks/4/enabled = true -tracks/4/path = NodePath("../Sprites/CharacterEffects/Cast:frame") +tracks/4/path = NodePath("%Sprites/CharacterEffects/Cast:frame") tracks/4/interp = 1 tracks/4/loop_wrap = true tracks/4/keys = { @@ -309,7 +309,7 @@ tracks/1/keys = { tracks/2/type = "value" tracks/2/imported = false tracks/2/enabled = true -tracks/2/path = NodePath("../Sprites/CharacterEffects/Cast:visible") +tracks/2/path = NodePath("%Sprites/CharacterEffects/Cast:visible") tracks/2/interp = 1 tracks/2/loop_wrap = true tracks/2/keys = { @@ -321,7 +321,7 @@ tracks/2/keys = { tracks/3/type = "value" tracks/3/imported = false tracks/3/enabled = true -tracks/3/path = NodePath("../Sprites/CharacterEffects/Cast:frame") +tracks/3/path = NodePath("%Sprites/CharacterEffects/Cast:frame") tracks/3/interp = 1 tracks/3/loop_wrap = true tracks/3/keys = { @@ -670,11 +670,13 @@ unique_name_in_owner = true script = ExtResource("7_sdgvb") [node name="Movement" type="AnimationPlayer" parent="Animations"] +root_node = NodePath("../..") libraries = { "": SubResource("AnimationLibrary_0tohi") } [node name="Attack" type="AnimationPlayer" parent="Animations"] +root_node = NodePath("../..") libraries = { "": SubResource("AnimationLibrary_73mj7") } @@ -686,6 +688,7 @@ libraries = { } [node name="Stun" type="AnimationPlayer" parent="Animations"] +root_node = NodePath("../..") libraries = { "": SubResource("AnimationLibrary_kks2p") } diff --git a/Extensions/AnimationPlayer.cs b/Extensions/AnimationPlayer.cs index 0576b37..bc7e91a 100644 --- a/Extensions/AnimationPlayer.cs +++ b/Extensions/AnimationPlayer.cs @@ -14,6 +14,27 @@ public static class AnimationPlayerExtensions return hasAnimation; } + public static bool TryPlayAny(this AnimationPlayer player, + params string[] names) + { + return player.TryPlayAny(out var _, names); + } + + public static bool TryPlayAny(this AnimationPlayer player, + out string resultName, params string[] names) + { + foreach (string name in names) + { + if (player.TryPlay(name)) + { + resultName = name; + return true; + } + } + resultName = default; + return false; + } + public static bool TryQueue(this AnimationPlayer player, string name) { var hasAnimation = player.HasAnimation(name); @@ -23,4 +44,25 @@ public static class AnimationPlayerExtensions } return hasAnimation; } + + public static bool TryQueueAny(this AnimationPlayer player, + params string[] names) + { + return player.TryQueueAny(out var _, names); + } + + public static bool TryQueueAny(this AnimationPlayer player, + out string resultName, params string[] names) + { + foreach (string name in names) + { + if (player.TryQueue(name)) + { + resultName = name; + return true; + } + } + resultName = default; + return false; + } } diff --git a/Utils/AnimationManager.cs b/Utils/AnimationManager.cs index ef2ca99..08775f3 100644 --- a/Utils/AnimationManager.cs +++ b/Utils/AnimationManager.cs @@ -92,14 +92,14 @@ public partial class AnimationManager : Node NodePath anim1Path = anim1.TrackGetPath(p1Track); NodePath anim1Prop = anim1Path.GetConcatenatedSubNames(); NodePath anim1Name = anim1Path.GetConcatenatedNames(); - Node anim1Node = p1.GetParent().GetNode(anim1Name); + Node anim1Node = p1.GetNode(p1.RootNode)?.GetNode(anim1Name); for (int p2Track = 0; p2Track < anim2.GetTrackCount(); p2Track++) { NodePath anim2Path = anim2.TrackGetPath(p2Track); NodePath anim2Prop = anim2Path.GetConcatenatedSubNames(); NodePath anim2Name = anim2Path.GetConcatenatedNames(); - Node anim2Node = p2.GetParent().GetNode(anim2Name); + Node anim2Node = p2.GetNode(p2.RootNode)?.GetNode(anim2Name); // check if they point to the same node and property if (anim1Node == anim2Node && anim1Prop == anim2Prop)