From e87f8a04a1054cd63f9ddf250553ca462cff2b9f Mon Sep 17 00:00:00 2001 From: Brian Holsters Date: Sat, 6 Apr 2024 14:03:05 +0200 Subject: [PATCH 1/4] decouple wieldable scenes from player --- .../Components/PlayerInteractionComponent.gd | 20 ++++++++++------- .../InventoryPD/CustomResources/AmmoItemPD.gd | 2 -- .../CustomResources/WieldableItemPD.gd | 7 ++++++ COGITO/InventoryPD/Items/Cogito_Battery.tres | 4 +--- COGITO/InventoryPD/Items/Cogito_Dart.tres | 6 +++-- .../InventoryPD/Items/Cogito_Flashlight.tres | 4 +++- .../InventoryPD/Items/Cogito_FoamBullets.tres | 4 +--- .../InventoryPD/Items/Cogito_LaserAmmo.tres | 4 +--- .../InventoryPD/Items/Cogito_LaserRifle.tres | 4 +++- COGITO/InventoryPD/Items/Cogito_Pickaxe.tres | 4 +++- COGITO/InventoryPD/Items/Cogito_Pistol.tres | 16 ++++++++------ COGITO/PrefabScenes/Pickups/pickup_dart.tscn | 4 ++-- COGITO/PrefabScenes/player.tscn | 22 ++++--------------- COGITO/Scripts/Cogito_Wieldable.gd | 2 +- COGITO/Scripts/player.gd | 2 ++ COGITO/Wieldables/Wieldable_Dart.gd | 4 +--- COGITO/Wieldables/flashlight.tscn | 5 +---- COGITO/Wieldables/laser_rifle.tscn | 1 - COGITO/Wieldables/pickaxe.tscn | 4 +--- COGITO/Wieldables/throw_dart.tscn | 6 +---- COGITO/Wieldables/toy_pistol.tscn | 4 +--- 21 files changed, 58 insertions(+), 71 deletions(-) diff --git a/COGITO/Components/PlayerInteractionComponent.gd b/COGITO/Components/PlayerInteractionComponent.gd index ad805eda..c5ebe795 100644 --- a/COGITO/Components/PlayerInteractionComponent.gd +++ b/COGITO/Components/PlayerInteractionComponent.gd @@ -31,6 +31,7 @@ var is_changing_wieldables : bool = false #Used to avoid any input acitons while ## List of Wieldable nodes @export var wieldable_nodes : Array[Node] +@export var wieldable_container : Node3D # Various variables used for wieldable handling var equipped_wieldable_item = null var equipped_wieldable_node = null @@ -168,14 +169,15 @@ func equip_wieldable(wieldable_item:WieldableItemPD): if wieldable_item != null: equipped_wieldable_item = wieldable_item #Set Inventory Item reference # Set Wieldable node reference - for wieldable_node in wieldable_nodes: - if wieldable_node.item_reference == equipped_wieldable_item: - equipped_wieldable_node = wieldable_node - print("PIC: Found ", equipped_wieldable_item.name, " in wieldable node array: ", wieldable_node.name) - equipped_wieldable_node.equip(self) - is_wielding = true - await get_tree().create_timer(equipped_wieldable_node.animation_player.current_animation_length).timeout - is_changing_wieldables = false + var wieldable_node = wieldable_item.build_wieldable_scene() + wieldable_container.add_child(wieldable_node) + equipped_wieldable_node = wieldable_node + equipped_wieldable_node.item_reference = wieldable_item + print("PIC: Found ", equipped_wieldable_item.name, " in wieldable node array: ", wieldable_node.name) + equipped_wieldable_node.equip(self) + is_wielding = true + await get_tree().create_timer(equipped_wieldable_node.animation_player.current_animation_length).timeout + is_changing_wieldables = false else: is_changing_wieldables = false @@ -190,6 +192,8 @@ func change_wieldable_to(next_wieldable: InventoryItemPD): if equipped_wieldable_node.animation_player.is_playing(): #Wait until unequip animation finishes. await get_tree().create_timer(equipped_wieldable_node.animation_player.current_animation_length).timeout equipped_wieldable_item = null + if equipped_wieldable_node != null: + equipped_wieldable_node.queue_free() equipped_wieldable_node = null is_wielding = false equip_wieldable(next_wieldable) diff --git a/COGITO/InventoryPD/CustomResources/AmmoItemPD.gd b/COGITO/InventoryPD/CustomResources/AmmoItemPD.gd index 65505ec2..c19c9249 100644 --- a/COGITO/InventoryPD/CustomResources/AmmoItemPD.gd +++ b/COGITO/InventoryPD/CustomResources/AmmoItemPD.gd @@ -2,8 +2,6 @@ extends InventoryItemPD class_name AmmoItemPD @export_group("Ammo settings") -## The item that this item is ammunition for. -@export var target_item_ammo : WieldableItemPD = null ## The amount one item addes to the target item charge. For bullets this should be 1. @export var reload_amount : int = 1 diff --git a/COGITO/InventoryPD/CustomResources/WieldableItemPD.gd b/COGITO/InventoryPD/CustomResources/WieldableItemPD.gd index 08770fb0..987fcd96 100644 --- a/COGITO/InventoryPD/CustomResources/WieldableItemPD.gd +++ b/COGITO/InventoryPD/CustomResources/WieldableItemPD.gd @@ -5,6 +5,7 @@ class_name WieldableItemPD signal charge_changed() @export_group("Wieldable settings") +@export var wieldable_scene : PackedScene ## Icon that is displayed on the HUD when item is wielded. If NULL, the item icon will be used instead. @export var wieldable_data_icon : Texture2D ## Check this if your wieldable doesn't use reload (for example melee weapons) @@ -127,3 +128,9 @@ func save(): "charge_current" : charge_current } return saved_item_data + + +func build_wieldable_scene(): + var scene = wieldable_scene.instantiate() + scene.item_reference = self + return scene diff --git a/COGITO/InventoryPD/Items/Cogito_Battery.tres b/COGITO/InventoryPD/Items/Cogito_Battery.tres index ddbae799..5fcfcac9 100644 --- a/COGITO/InventoryPD/Items/Cogito_Battery.tres +++ b/COGITO/InventoryPD/Items/Cogito_Battery.tres @@ -1,15 +1,13 @@ -[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=7 format=3 uid="uid://cupby6uqaftvv"] +[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=6 format=3 uid="uid://cupby6uqaftvv"] [ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/AmmoItemPD.gd" id="1_3ov2u"] [ext_resource type="Texture2D" uid="uid://cg5knuav7df4o" path="res://COGITO/Assets/Graphics/HintIcons/Hint_X.png" id="1_54cn8"] [ext_resource type="Texture2D" uid="uid://c0h1s1g4g1q56" path="res://COGITO/Assets/Graphics/ItemIcons/CogitoBattery.png" id="1_fjosn"] [ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_lxwux"] -[ext_resource type="Resource" uid="uid://ckvdkigvwowm5" path="res://COGITO/InventoryPD/Items/Cogito_Flashlight.tres" id="3_myi62"] [ext_resource type="AudioStream" uid="uid://bnqnuewmntcyp" path="res://COGITO/Assets/Audio/Kenney/UiAudio/error_008.ogg" id="5_tfubv"] [resource] script = ExtResource("1_3ov2u") -target_item_ammo = ExtResource("3_myi62") reload_amount = 10 name = "Battery" description = "Can be combined with the Flashlight. Non-rechargeable." diff --git a/COGITO/InventoryPD/Items/Cogito_Dart.tres b/COGITO/InventoryPD/Items/Cogito_Dart.tres index 83480d04..a1d8bfc9 100644 --- a/COGITO/InventoryPD/Items/Cogito_Dart.tres +++ b/COGITO/InventoryPD/Items/Cogito_Dart.tres @@ -1,11 +1,13 @@ -[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=4 format=3 uid="uid://c6rpnmo1y1cw5"] +[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=5 format=3 uid="uid://c6rpnmo1y1cw5"] [ext_resource type="Texture2D" uid="uid://bubcgr2q03ert" path="res://COGITO/Assets/Graphics/ItemIcons/Dart.png" id="1_m1vko"] [ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="1_ub1do"] [ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_sof2n"] +[ext_resource type="PackedScene" uid="uid://1vnxo4ya6yjr" path="res://COGITO/Wieldables/throw_dart.tscn" id="4_dlpol"] [resource] script = ExtResource("1_ub1do") +wieldable_scene = ExtResource("4_dlpol") no_reload = true charge_max = 1.0 ammo_item_name = "Dart" @@ -13,7 +15,7 @@ charge_current = 1.0 wieldable_range = 10.0 wieldable_damage = 1.0 name = "Dart" -descpription = "Throw it and see what happens." +description = "" icon = ExtResource("1_m1vko") is_stackable = true stack_size = 5 diff --git a/COGITO/InventoryPD/Items/Cogito_Flashlight.tres b/COGITO/InventoryPD/Items/Cogito_Flashlight.tres index 25c06d4c..990db79f 100644 --- a/COGITO/InventoryPD/Items/Cogito_Flashlight.tres +++ b/COGITO/InventoryPD/Items/Cogito_Flashlight.tres @@ -1,12 +1,14 @@ -[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=5 format=3 uid="uid://ckvdkigvwowm5"] +[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=6 format=3 uid="uid://ckvdkigvwowm5"] [ext_resource type="Texture2D" uid="uid://heih3rs4r4gt" path="res://COGITO/Assets/Graphics/ItemIcons/CogitoFlashlight.png" id="1_f43pq"] [ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="2_h6bnx"] [ext_resource type="Texture2D" uid="uid://4xstvhrf4r2h" path="res://COGITO/Assets/Graphics/BatteryIcon.png" id="3_ea2qf"] [ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_f88a5"] +[ext_resource type="PackedScene" uid="uid://5r8icl42jumy" path="res://COGITO/Wieldables/flashlight.tscn" id="5_ty4ey"] [resource] script = ExtResource("2_h6bnx") +wieldable_scene = ExtResource("5_ty4ey") wieldable_data_icon = ExtResource("3_ea2qf") no_reload = false charge_max = 100.0 diff --git a/COGITO/InventoryPD/Items/Cogito_FoamBullets.tres b/COGITO/InventoryPD/Items/Cogito_FoamBullets.tres index 59c76923..bdbca559 100644 --- a/COGITO/InventoryPD/Items/Cogito_FoamBullets.tres +++ b/COGITO/InventoryPD/Items/Cogito_FoamBullets.tres @@ -1,14 +1,12 @@ -[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=6 format=3 uid="uid://bqhbrpnp2tt08"] +[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=5 format=3 uid="uid://bqhbrpnp2tt08"] [ext_resource type="Texture2D" uid="uid://cxvxq8hy53ih5" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_FoamBullets.png" id="1_efcmi"] [ext_resource type="Texture2D" uid="uid://cg5knuav7df4o" path="res://COGITO/Assets/Graphics/HintIcons/Hint_X.png" id="1_p472b"] [ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/AmmoItemPD.gd" id="3_fjkqh"] [ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="4_2hhqx"] -[ext_resource type="Resource" uid="uid://lc5uq2e6ldah" path="res://COGITO/InventoryPD/Items/Cogito_Pistol.tres" id="5_cl3nd"] [resource] script = ExtResource("3_fjkqh") -target_item_ammo = ExtResource("5_cl3nd") reload_amount = 1 name = "Foam Bullets" description = "Very visible but not very dangerous. Have a tendency to vanish." diff --git a/COGITO/InventoryPD/Items/Cogito_LaserAmmo.tres b/COGITO/InventoryPD/Items/Cogito_LaserAmmo.tres index 1955d700..4e705040 100644 --- a/COGITO/InventoryPD/Items/Cogito_LaserAmmo.tres +++ b/COGITO/InventoryPD/Items/Cogito_LaserAmmo.tres @@ -1,13 +1,11 @@ -[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=5 format=3 uid="uid://cvupo3p844nh2"] +[gd_resource type="Resource" script_class="AmmoItemPD" load_steps=4 format=3 uid="uid://cvupo3p844nh2"] [ext_resource type="Texture2D" uid="uid://uj2uowrvb2ni" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_LaserAmmo.png" id="1_6hnrl"] [ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/AmmoItemPD.gd" id="1_opcg5"] [ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_qv1dk"] -[ext_resource type="Resource" uid="uid://txiu5yxexevm" path="res://COGITO/InventoryPD/Items/Cogito_LaserRifle.tres" id="4_37gcd"] [resource] script = ExtResource("1_opcg5") -target_item_ammo = ExtResource("4_37gcd") reload_amount = 50 name = "Laser Ammo" description = "Tends to get hot. One clip has a charge of 50." diff --git a/COGITO/InventoryPD/Items/Cogito_LaserRifle.tres b/COGITO/InventoryPD/Items/Cogito_LaserRifle.tres index f57642e1..4de1a304 100644 --- a/COGITO/InventoryPD/Items/Cogito_LaserRifle.tres +++ b/COGITO/InventoryPD/Items/Cogito_LaserRifle.tres @@ -1,11 +1,13 @@ -[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=4 format=3 uid="uid://txiu5yxexevm"] +[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=5 format=3 uid="uid://txiu5yxexevm"] [ext_resource type="Texture2D" uid="uid://bnqyy1c46mlfw" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_LaserRifle.png" id="1_62c38"] [ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="2_o1rdd"] [ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_yhudh"] +[ext_resource type="PackedScene" uid="uid://bb8pm2nk8hwon" path="res://COGITO/Wieldables/laser_rifle.tscn" id="4_wbhgr"] [resource] script = ExtResource("2_o1rdd") +wieldable_scene = ExtResource("4_wbhgr") no_reload = false charge_max = 100.0 ammo_item_name = "Laser Ammo" diff --git a/COGITO/InventoryPD/Items/Cogito_Pickaxe.tres b/COGITO/InventoryPD/Items/Cogito_Pickaxe.tres index 9946a774..c60696f6 100644 --- a/COGITO/InventoryPD/Items/Cogito_Pickaxe.tres +++ b/COGITO/InventoryPD/Items/Cogito_Pickaxe.tres @@ -1,11 +1,13 @@ -[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=4 format=3 uid="uid://bp6xhd3rkh7tl"] +[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=5 format=3 uid="uid://s2y3u88qdau3"] [ext_resource type="Texture2D" uid="uid://h6c4g2wtkb48" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_Pickaxe.png" id="1_a7clm"] [ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="1_fay77"] [ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_5g3cg"] +[ext_resource type="PackedScene" uid="uid://dxxemvynrimqw" path="res://COGITO/Wieldables/pickaxe.tscn" id="4_cgf4o"] [resource] script = ExtResource("1_fay77") +wieldable_scene = ExtResource("4_cgf4o") no_reload = true charge_max = 1.0 ammo_item_name = "" diff --git a/COGITO/InventoryPD/Items/Cogito_Pistol.tres b/COGITO/InventoryPD/Items/Cogito_Pistol.tres index 2ab279df..cd3cc308 100644 --- a/COGITO/InventoryPD/Items/Cogito_Pistol.tres +++ b/COGITO/InventoryPD/Items/Cogito_Pistol.tres @@ -1,11 +1,13 @@ -[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=4 format=3 uid="uid://lc5uq2e6ldah"] +[gd_resource type="Resource" script_class="WieldableItemPD" load_steps=5 format=3 uid="uid://lc5uq2e6ldah"] -[ext_resource type="Texture2D" uid="uid://78js4558o61m" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_Pistol.png" id="1_t40ae"] -[ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="2_otaa7"] -[ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_5o4ls"] +[ext_resource type="Texture2D" uid="uid://78js4558o61m" path="res://COGITO/Assets/Graphics/ItemIcons/Cogito_Pistol.png" id="1_dj2ew"] +[ext_resource type="Script" path="res://COGITO/InventoryPD/CustomResources/WieldableItemPD.gd" id="2_dk2he"] +[ext_resource type="AudioStream" uid="uid://npav2p2tk10i" path="res://COGITO/Assets/Audio/Kenney/handleSmallLeather.ogg" id="3_weko3"] +[ext_resource type="PackedScene" uid="uid://dgtjml2t3hdvx" path="res://COGITO/Wieldables/toy_pistol.tscn" id="4_f2ej1"] [resource] -script = ExtResource("2_otaa7") +script = ExtResource("2_dk2he") +wieldable_scene = ExtResource("4_f2ej1") no_reload = false charge_max = 10.0 ammo_item_name = "Foam Bullets" @@ -14,9 +16,9 @@ wieldable_range = 10.0 wieldable_damage = 1.0 name = "Foam Pistol" description = "There's a reason it looks like a toy. Shoots foam bullets." -icon = ExtResource("1_t40ae") +icon = ExtResource("1_dj2ew") is_stackable = false stack_size = 0 drop_scene = "res://COGITO/PrefabScenes/Pickups/pickup_pistol.tscn" hint_text_on_use = "" -sound_pickup = ExtResource("3_5o4ls") +sound_pickup = ExtResource("3_weko3") diff --git a/COGITO/PrefabScenes/Pickups/pickup_dart.tscn b/COGITO/PrefabScenes/Pickups/pickup_dart.tscn index 5646f1ba..b24db508 100644 --- a/COGITO/PrefabScenes/Pickups/pickup_dart.tscn +++ b/COGITO/PrefabScenes/Pickups/pickup_dart.tscn @@ -78,7 +78,7 @@ metallic = 1.0 height = 0.28 radius = 0.05 -[sub_resource type="Resource" id="Resource_5gvqf"] +[sub_resource type="Resource" id="Resource_wj66l"] resource_local_to_scene = true script = ExtResource("4_qk8k6") inventory_item = ExtResource("3_ohc35") @@ -114,7 +114,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.14, 0) shape = SubResource("CylinderShape3D_xbicr") [node name="PickupComponent" parent="." instance=ExtResource("2_u01ym")] -slot_data = SubResource("Resource_5gvqf") +slot_data = SubResource("Resource_wj66l") [node name="Lifespan" type="Timer" parent="."] diff --git a/COGITO/PrefabScenes/player.tscn b/COGITO/PrefabScenes/player.tscn index 1b199ae0..74936400 100644 --- a/COGITO/PrefabScenes/player.tscn +++ b/COGITO/PrefabScenes/player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=27 format=3 uid="uid://kicjwmh02uwf"] +[gd_scene load_steps=22 format=3 uid="uid://kicjwmh02uwf"] [ext_resource type="Script" path="res://COGITO/Scripts/player.gd" id="1_wkneb"] [ext_resource type="Resource" uid="uid://ev2xuamhfojm" path="res://COGITO/InventoryPD/Inventories/PlayerInventory.tres" id="2_qleua"] @@ -8,18 +8,13 @@ [ext_resource type="AnimationLibrary" uid="uid://cdchpsv104er2" path="res://COGITO/Assets/Animations/player_eyes.tres" id="4_juktk"] [ext_resource type="AudioStream" uid="uid://crj07wq4oocwi" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep01.ogg" id="5_6htai"] [ext_resource type="PackedScene" uid="uid://ce7bjv28uakxl" path="res://COGITO/Components/Attributes/StaminaAttribute.tscn" id="5_dmlhq"] -[ext_resource type="PackedScene" uid="uid://5r8icl42jumy" path="res://COGITO/Wieldables/flashlight.tscn" id="5_ukw1v"] [ext_resource type="PackedScene" uid="uid://wtf1fqndii2p" path="res://COGITO/Components/Attributes/VisibilityAttribute.tscn" id="6_kao4w"] -[ext_resource type="PackedScene" uid="uid://dgtjml2t3hdvx" path="res://COGITO/Wieldables/toy_pistol.tscn" id="6_lwwgx"] [ext_resource type="AudioStream" uid="uid://dewyukd562k37" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep02.ogg" id="6_nrttm"] -[ext_resource type="PackedScene" uid="uid://bb8pm2nk8hwon" path="res://COGITO/Wieldables/laser_rifle.tscn" id="7_cn6iu"] [ext_resource type="AudioStream" uid="uid://c5kfw4o57foju" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep03.ogg" id="7_swbyy"] [ext_resource type="PackedScene" uid="uid://cetc123v5gnff" path="res://COGITO/Components/Attributes/SanityAttribute.tscn" id="7_toa7v"] [ext_resource type="AudioStream" uid="uid://b4mt1tuxo2144" path="res://COGITO/Assets/Audio/Kenney/Footsteps/footstep04.ogg" id="8_2tp8b"] -[ext_resource type="PackedScene" uid="uid://dxxemvynrimqw" path="res://COGITO/Wieldables/pickaxe.tscn" id="12_03s1j"] [ext_resource type="AudioStream" uid="uid://b7wmxwvtbpfu1" path="res://COGITO/Assets/Audio/537275__laughingfish78__dirt-sliding.ogg" id="13_jr246"] [ext_resource type="PackedScene" uid="uid://dy3tudla5p2nc" path="res://COGITO/Components/PlayerInteractionComponent.tscn" id="13_rawn6"] -[ext_resource type="PackedScene" uid="uid://1vnxo4ya6yjr" path="res://COGITO/Wieldables/throw_dart.tscn" id="14_xn6yt"] [ext_resource type="Script" path="res://COGITO/DynamicFootstepSystem/Scripts/footstep_surface_detector.gd" id="16_a6uam"] [ext_resource type="AudioStream" uid="uid://dc03jiw2a6y3j" path="res://COGITO/DynamicFootstepSystem/FootstepProfiles/generic_footstep_profile.tres" id="17_rmtvn"] [ext_resource type="Resource" uid="uid://ca0q2t6w08ubh" path="res://COGITO/DynamicFootstepSystem/FootstepMaterialLibrary/sample_footstep_material_library.tres" id="18_q6u2l"] @@ -104,16 +99,7 @@ target_position = Vector3(0, 0, -2.5) collision_mask = 3 [node name="Wieldables" type="Node3D" parent="Neck/Head"] - -[node name="Flashlight" parent="Neck/Head/Wieldables" instance=ExtResource("5_ukw1v")] - -[node name="Toy Pistol" parent="Neck/Head/Wieldables" instance=ExtResource("6_lwwgx")] - -[node name="Laser Rifle" parent="Neck/Head/Wieldables" instance=ExtResource("7_cn6iu")] - -[node name="Pickaxe" parent="Neck/Head/Wieldables" instance=ExtResource("12_03s1j")] - -[node name="Dart" parent="Neck/Head/Wieldables" instance=ExtResource("14_xn6yt")] +unique_name_in_owner = true [node name="SlidingTimer" type="Timer" parent="."] wait_time = 1.5 @@ -135,10 +121,10 @@ one_shot = true wait_time = 0.5 one_shot = true -[node name="PlayerInteractionComponent" parent="." node_paths=PackedStringArray("interaction_raycast", "carryable_position", "wieldable_nodes") instance=ExtResource("13_rawn6")] +[node name="PlayerInteractionComponent" parent="." node_paths=PackedStringArray("interaction_raycast", "carryable_position", "wieldable_container") instance=ExtResource("13_rawn6")] interaction_raycast = NodePath("../Neck/Head/Eyes/Camera/InteractionRaycast") carryable_position = NodePath("../CarryablePosition") -wieldable_nodes = [NodePath("../Neck/Head/Wieldables/Flashlight"), NodePath("../Neck/Head/Wieldables/Toy Pistol"), NodePath("../Neck/Head/Wieldables/Laser Rifle"), NodePath("../Neck/Head/Wieldables/Pickaxe"), NodePath("../Neck/Head/Wieldables/Dart")] +wieldable_container = NodePath("../Neck/Head/Wieldables") [connection signal="animation_finished" from="Neck/Head/Eyes/AnimationPlayer" to="." method="_on_animation_player_animation_finished"] [connection signal="timeout" from="SlidingTimer" to="." method="_on_sliding_timer_timeout"] diff --git a/COGITO/Scripts/Cogito_Wieldable.gd b/COGITO/Scripts/Cogito_Wieldable.gd index dd4ec26e..e40d9739 100644 --- a/COGITO/Scripts/Cogito_Wieldable.gd +++ b/COGITO/Scripts/Cogito_Wieldable.gd @@ -3,7 +3,7 @@ class_name CogitoWieldable @export_group("General Wieldable Settings") ## Item resource that this wieldable refers to. -@export var item_reference : WieldableItemPD +var item_reference : WieldableItemPD ## Visible parts of the wieldable. Used to hide/show on equip/unequip. @export var wieldable_mesh : Node3D diff --git a/COGITO/Scripts/player.gd b/COGITO/Scripts/player.gd index 142c1bbe..56ec8eb5 100644 --- a/COGITO/Scripts/player.gd +++ b/COGITO/Scripts/player.gd @@ -159,6 +159,8 @@ var slide_audio_player : AudioStreamPlayer3D @onready var self_rid: RID = self.get_rid() @onready var test_motion_result: PhysicsTestMotionResult3D = PhysicsTestMotionResult3D.new() + +@onready var wieldables = %Wieldables #endregion diff --git a/COGITO/Wieldables/Wieldable_Dart.gd b/COGITO/Wieldables/Wieldable_Dart.gd index 802d359d..57b1bdc1 100644 --- a/COGITO/Wieldables/Wieldable_Dart.gd +++ b/COGITO/Wieldables/Wieldable_Dart.gd @@ -1,8 +1,6 @@ extends CogitoWieldable @export_group("Dart Settings") -## Path to the projectile prefab scene -@export var projectile_prefab : PackedScene ## Speed the projectile spawns with @export var projectile_velocity : float ## Node the projectile spawns at @@ -67,7 +65,7 @@ func action_primary(_passed_item_reference : InventoryItemPD, _is_released: bool var Direction = (_camera_collision - bullet_point.get_global_transform().origin).normalized() # Spawning projectile - var Projectile = projectile_prefab.instantiate() + var Projectile = load(item_reference.drop_scene).instantiate() bullet_point.add_child(Projectile) Projectile.damage_amount = _passed_item_reference.wieldable_damage Projectile.set_linear_velocity(Direction * projectile_velocity) diff --git a/COGITO/Wieldables/flashlight.tscn b/COGITO/Wieldables/flashlight.tscn index 0b933227..c1574872 100644 --- a/COGITO/Wieldables/flashlight.tscn +++ b/COGITO/Wieldables/flashlight.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=8 format=3 uid="uid://5r8icl42jumy"] +[gd_scene load_steps=7 format=3 uid="uid://5r8icl42jumy"] [ext_resource type="Script" path="res://COGITO/Wieldables/Wieldable_Flashlight.gd" id="1_pak3j"] [ext_resource type="AudioStream" uid="uid://dsp8iwkwq2rlu" path="res://COGITO/Assets/Audio/Kenney/UiAudio/switch1.ogg" id="2_dm0bj"] -[ext_resource type="Resource" uid="uid://ckvdkigvwowm5" path="res://COGITO/InventoryPD/Items/Cogito_Flashlight.tres" id="3_2q6j0"] [ext_resource type="AnimationLibrary" uid="uid://dtnyvbl2d4lxg" path="res://COGITO/Animations/Wieldables/Wieldable_Flashlight.res" id="4_sk1pk"] [ext_resource type="Script" path="res://COGITO/Assets/Shader/ViewmodelSpace.gd" id="5_kuso5"] @@ -22,7 +21,6 @@ transform = Transform3D(-3.61999e-06, 0, 1, 0, 1, 0, -1, 0, -3.61999e-06, 0.3258 script = ExtResource("1_pak3j") drain_rate = 4.0 switch_sound = ExtResource("2_dm0bj") -item_reference = ExtResource("3_2q6j0") wieldable_mesh = NodePath("Flashlight_Mesh") anim_equip = "Wieldable_Flashlight/equip" anim_unequip = "Wieldable_Flashlight/unequip" @@ -45,7 +43,6 @@ spot_range = 8.0 spot_angle = 30.0 [node name="Flashlight_Mesh" type="Node3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0) script = ExtResource("5_kuso5") [node name="CSGCylinder3D" type="CSGCylinder3D" parent="Flashlight_Mesh"] diff --git a/COGITO/Wieldables/laser_rifle.tscn b/COGITO/Wieldables/laser_rifle.tscn index 6271846d..f630a78d 100644 --- a/COGITO/Wieldables/laser_rifle.tscn +++ b/COGITO/Wieldables/laser_rifle.tscn @@ -270,7 +270,6 @@ laser_ray_prefab = ExtResource("2_ic084") ray_lifespan = 3.0 default_position = Vector3(0.329, -0.264, -0.535) sound_primary_use = ExtResource("2_f7ale") -item_reference = ExtResource("2_i0fx0") wieldable_mesh = NodePath("LaserRifleMesh") anim_equip = "LaserRifle/equip" anim_unequip = "LaserRifle/unequip" diff --git a/COGITO/Wieldables/pickaxe.tscn b/COGITO/Wieldables/pickaxe.tscn index fd2b9d92..a2a4cf3f 100644 --- a/COGITO/Wieldables/pickaxe.tscn +++ b/COGITO/Wieldables/pickaxe.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=11 format=3 uid="uid://dxxemvynrimqw"] +[gd_scene load_steps=10 format=3 uid="uid://dxxemvynrimqw"] [ext_resource type="Script" path="res://COGITO/Wieldables/Wieldable_Pickaxe.gd" id="1_hb7ed"] -[ext_resource type="Resource" uid="uid://bp6xhd3rkh7tl" path="res://COGITO/InventoryPD/Items/Cogito_Pickaxe.tres" id="2_1ju5q"] [ext_resource type="AudioStream" uid="uid://ocm2blyfthyq" path="res://COGITO/Assets/Audio/Kenney/woosh1.ogg" id="2_hp6wh"] [ext_resource type="AnimationLibrary" uid="uid://da3y5068fwwbq" path="res://COGITO/Animations/Wieldables/Wieldable_Pickaxe.res" id="3_cqo2g"] [ext_resource type="Script" path="res://COGITO/Assets/Shader/ViewmodelSpace.gd" id="4_0jrxw"] @@ -78,7 +77,6 @@ transform = Transform3D(-3.61999e-06, 0, 1, 0, 1, 0, -1, 0, -3.61999e-06, 0.3258 script = ExtResource("1_hb7ed") damage_area = NodePath("PickaxeMesh/DamageArea") swing_sound = ExtResource("2_hp6wh") -item_reference = ExtResource("2_1ju5q") wieldable_mesh = NodePath("PickaxeMesh") anim_action_primary = "swing" diff --git a/COGITO/Wieldables/throw_dart.tscn b/COGITO/Wieldables/throw_dart.tscn index 102a3098..f5c0cac9 100644 --- a/COGITO/Wieldables/throw_dart.tscn +++ b/COGITO/Wieldables/throw_dart.tscn @@ -1,8 +1,6 @@ -[gd_scene load_steps=10 format=3 uid="uid://1vnxo4ya6yjr"] +[gd_scene load_steps=8 format=3 uid="uid://1vnxo4ya6yjr"] [ext_resource type="Script" path="res://COGITO/Wieldables/Wieldable_Dart.gd" id="1_pgk5e"] -[ext_resource type="Resource" uid="uid://c6rpnmo1y1cw5" path="res://COGITO/InventoryPD/Items/Cogito_Dart.tres" id="2_3c0of"] -[ext_resource type="PackedScene" uid="uid://bekq2c16juwa1" path="res://COGITO/PrefabScenes/Pickups/pickup_dart.tscn" id="2_e6p2w"] [ext_resource type="AnimationLibrary" uid="uid://ddo1rrwrgerw0" path="res://COGITO/Animations/Wieldables/Wieldable_Dart.res" id="2_nvn25"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_halr6"] @@ -76,9 +74,7 @@ metallic = 1.0 [node name="Dart" type="Node3D" node_paths=PackedStringArray("wieldable_mesh")] script = ExtResource("1_pgk5e") -projectile_prefab = ExtResource("2_e6p2w") projectile_velocity = 40.0 -item_reference = ExtResource("2_3c0of") wieldable_mesh = NodePath("DartMesh") anim_equip = "Dart_equip" anim_unequip = "Dart_unequip" diff --git a/COGITO/Wieldables/toy_pistol.tscn b/COGITO/Wieldables/toy_pistol.tscn index c735cac0..3283fa2e 100644 --- a/COGITO/Wieldables/toy_pistol.tscn +++ b/COGITO/Wieldables/toy_pistol.tscn @@ -1,9 +1,8 @@ -[gd_scene load_steps=11 format=3 uid="uid://dgtjml2t3hdvx"] +[gd_scene load_steps=10 format=3 uid="uid://dgtjml2t3hdvx"] [ext_resource type="Script" path="res://COGITO/Wieldables/Wieldable_Pistol.gd" id="1_b1v5k"] [ext_resource type="PackedScene" uid="uid://c1umit2vtv22v" path="res://COGITO/PrefabScenes/projectile_pistol.tscn" id="2_l6tt4"] [ext_resource type="AudioStream" uid="uid://clsajk36s7luk" path="res://COGITO/Assets/Audio/Kenney/error_004.ogg" id="3_vdfq8"] -[ext_resource type="Resource" uid="uid://lc5uq2e6ldah" path="res://COGITO/InventoryPD/Items/Cogito_Pistol.tres" id="4_xoq73"] [ext_resource type="Script" path="res://COGITO/Assets/Shader/ViewmodelSpace.gd" id="5_1h55s"] [ext_resource type="AnimationLibrary" uid="uid://bbnpn3wqqoj7l" path="res://COGITO/Animations/Wieldables/Wieldable_ToyPistol.res" id="5_fkf6b"] @@ -57,7 +56,6 @@ projectile_prefab = ExtResource("2_l6tt4") projectile_velocity = 50.0 default_position = Vector3(0.329, -0.264, -0.535) sound_primary_use = ExtResource("3_vdfq8") -item_reference = ExtResource("4_xoq73") wieldable_mesh = NodePath("ToyPistol_mesh") anim_equip = "ToyPistol/equip" anim_unequip = "ToyPistol/unequip" From 6a5cb53cc905a159ebb0b7f239b1bae347b84811 Mon Sep 17 00:00:00 2001 From: Brian Holsters Date: Sat, 6 Apr 2024 14:10:49 +0200 Subject: [PATCH 2/4] dart fixes after merge with main --- COGITO/PrefabScenes/Pickups/pickup_dart.tscn | 4 ++-- COGITO/Wieldables/throw_dart.tscn | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/COGITO/PrefabScenes/Pickups/pickup_dart.tscn b/COGITO/PrefabScenes/Pickups/pickup_dart.tscn index b24db508..6436fc33 100644 --- a/COGITO/PrefabScenes/Pickups/pickup_dart.tscn +++ b/COGITO/PrefabScenes/Pickups/pickup_dart.tscn @@ -78,7 +78,7 @@ metallic = 1.0 height = 0.28 radius = 0.05 -[sub_resource type="Resource" id="Resource_wj66l"] +[sub_resource type="Resource" id="Resource_8p8de"] resource_local_to_scene = true script = ExtResource("4_qk8k6") inventory_item = ExtResource("3_ohc35") @@ -114,7 +114,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.14, 0) shape = SubResource("CylinderShape3D_xbicr") [node name="PickupComponent" parent="." instance=ExtResource("2_u01ym")] -slot_data = SubResource("Resource_wj66l") +slot_data = SubResource("Resource_8p8de") [node name="Lifespan" type="Timer" parent="."] diff --git a/COGITO/Wieldables/throw_dart.tscn b/COGITO/Wieldables/throw_dart.tscn index 45e95e32..eedae9da 100644 --- a/COGITO/Wieldables/throw_dart.tscn +++ b/COGITO/Wieldables/throw_dart.tscn @@ -1,6 +1,5 @@ [gd_scene load_steps=8 format=3 uid="uid://1vnxo4ya6yjr"] - [ext_resource type="Script" path="res://COGITO/Wieldables/Wieldable_Throwable.gd" id="1_pgk5e"] [ext_resource type="AnimationLibrary" uid="uid://ddo1rrwrgerw0" path="res://COGITO/Animations/Wieldables/Wieldable_Dart.res" id="2_nvn25"] From 90cfcceb4f5734305b330fe8291724735a4d5a73 Mon Sep 17 00:00:00 2001 From: Brian Holsters Date: Mon, 8 Apr 2024 08:28:58 +0200 Subject: [PATCH 3/4] added projectile_override to throwable Tested with foam bullet, works as intended. --- COGITO/Wieldables/Wieldable_Throwable.gd | 18 +++++++++++++----- COGITO/Wieldables/throw_dart.tscn | 4 +++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/COGITO/Wieldables/Wieldable_Throwable.gd b/COGITO/Wieldables/Wieldable_Throwable.gd index 68c5ed81..140d0391 100644 --- a/COGITO/Wieldables/Wieldable_Throwable.gd +++ b/COGITO/Wieldables/Wieldable_Throwable.gd @@ -2,6 +2,8 @@ extends CogitoWieldable @export_group("Throwable Settings") +## Leave empty if projectile and pickup are the same scene +@export var projectile_override: PackedScene ## Speed the projectile spawns with @export var projectile_velocity : float ## Node the projectile spawns at @@ -66,8 +68,14 @@ func action_primary(_passed_item_reference : InventoryItemPD, _is_released: bool var Direction = (_camera_collision - bullet_point.get_global_transform().origin).normalized() # Spawning projectile - var Projectile = load(item_reference.drop_scene).instantiate() - bullet_point.add_child(Projectile) - Projectile.damage_amount = _passed_item_reference.wieldable_damage - Projectile.set_linear_velocity(Direction * projectile_velocity) - Projectile.reparent(get_tree().get_current_scene()) + var projectile = instantiate_projectile() + bullet_point.add_child(projectile) + projectile.damage_amount = _passed_item_reference.wieldable_damage + projectile.set_linear_velocity(Direction * projectile_velocity) + projectile.reparent(get_tree().get_current_scene()) + + +func instantiate_projectile() -> Node3D: + if projectile_override != null: + return projectile_override.instantiate() + return load(item_reference.drop_scene).instantiate() diff --git a/COGITO/Wieldables/throw_dart.tscn b/COGITO/Wieldables/throw_dart.tscn index eedae9da..54fbff51 100644 --- a/COGITO/Wieldables/throw_dart.tscn +++ b/COGITO/Wieldables/throw_dart.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=8 format=3 uid="uid://1vnxo4ya6yjr"] +[gd_scene load_steps=9 format=3 uid="uid://1vnxo4ya6yjr"] [ext_resource type="Script" path="res://COGITO/Wieldables/Wieldable_Throwable.gd" id="1_pgk5e"] [ext_resource type="AnimationLibrary" uid="uid://ddo1rrwrgerw0" path="res://COGITO/Animations/Wieldables/Wieldable_Dart.res" id="2_nvn25"] +[ext_resource type="PackedScene" uid="uid://c1umit2vtv22v" path="res://COGITO/PrefabScenes/projectile_pistol.tscn" id="2_yv8tl"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_halr6"] resource_name = "yellow" @@ -74,6 +75,7 @@ metallic = 1.0 [node name="Dart" type="Node3D" node_paths=PackedStringArray("wieldable_mesh")] script = ExtResource("1_pgk5e") +projectile_override = ExtResource("2_yv8tl") projectile_velocity = 40.0 wieldable_mesh = NodePath("DartMesh") anim_equip = "Dart_equip" From c426d1d524c9b28ccf328c225627955a3a905af6 Mon Sep 17 00:00:00 2001 From: Brian Holsters Date: Mon, 8 Apr 2024 08:50:58 +0200 Subject: [PATCH 4/4] removed pistol projectile left by error in dart scene --- COGITO/Wieldables/throw_dart.tscn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/COGITO/Wieldables/throw_dart.tscn b/COGITO/Wieldables/throw_dart.tscn index 54fbff51..eedae9da 100644 --- a/COGITO/Wieldables/throw_dart.tscn +++ b/COGITO/Wieldables/throw_dart.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=9 format=3 uid="uid://1vnxo4ya6yjr"] +[gd_scene load_steps=8 format=3 uid="uid://1vnxo4ya6yjr"] [ext_resource type="Script" path="res://COGITO/Wieldables/Wieldable_Throwable.gd" id="1_pgk5e"] [ext_resource type="AnimationLibrary" uid="uid://ddo1rrwrgerw0" path="res://COGITO/Animations/Wieldables/Wieldable_Dart.res" id="2_nvn25"] -[ext_resource type="PackedScene" uid="uid://c1umit2vtv22v" path="res://COGITO/PrefabScenes/projectile_pistol.tscn" id="2_yv8tl"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_halr6"] resource_name = "yellow" @@ -75,7 +74,6 @@ metallic = 1.0 [node name="Dart" type="Node3D" node_paths=PackedStringArray("wieldable_mesh")] script = ExtResource("1_pgk5e") -projectile_override = ExtResource("2_yv8tl") projectile_velocity = 40.0 wieldable_mesh = NodePath("DartMesh") anim_equip = "Dart_equip"