diff --git a/assets/sounds/music/Bach_ Toccata and Fugue in D Minor, BWV 565.mp3 b/assets/sounds/music/Bach_ Toccata and Fugue in D Minor, BWV 565.mp3 new file mode 100644 index 0000000..43ea580 Binary files /dev/null and b/assets/sounds/music/Bach_ Toccata and Fugue in D Minor, BWV 565.mp3 differ diff --git a/assets/sounds/music/Bach_ Toccata and Fugue in D Minor, BWV 565.mp3.import b/assets/sounds/music/Bach_ Toccata and Fugue in D Minor, BWV 565.mp3.import new file mode 100644 index 0000000..b4789af --- /dev/null +++ b/assets/sounds/music/Bach_ Toccata and Fugue in D Minor, BWV 565.mp3.import @@ -0,0 +1,19 @@ +[remap] + +importer="mp3" +type="AudioStreamMP3" +uid="uid://b14wn4nntykxv" +path="res://.godot/imported/Bach_ Toccata and Fugue in D Minor, BWV 565.mp3-858103b4fd6b6728e77f9911964a975e.mp3str" + +[deps] + +source_file="res://assets/sounds/music/Bach_ Toccata and Fugue in D Minor, BWV 565.mp3" +dest_files=["res://.godot/imported/Bach_ Toccata and Fugue in D Minor, BWV 565.mp3-858103b4fd6b6728e77f9911964a975e.mp3str"] + +[params] + +loop=false +loop_offset=0 +bpm=0 +beat_count=0 +bar_beats=4 diff --git a/entities/backpack/backpack.gd b/entities/backpack/backpack.gd index 189c6d5..9103c7b 100644 --- a/entities/backpack/backpack.gd +++ b/entities/backpack/backpack.gd @@ -1,5 +1,5 @@ @icon("res://addons/at-icons/node3d/backpack.svg") -class_name Backpack extends EquippableItem +class_name Backpack extends PickupableItem @export var inventory_size: int = 10 @@ -17,6 +17,6 @@ func _ready() -> void: for i in range(inventory_size): inventory.append(null) - add_to_group("equippable") + add_to_group("pickupable") for i in get_children(): - i.add_to_group("equippable") + i.add_to_group("pickupable") diff --git a/classes/grabbable_item.gd b/entities/grabbable_base/grabbable_item.gd similarity index 100% rename from classes/grabbable_item.gd rename to entities/grabbable_base/grabbable_item.gd diff --git a/classes/grabbable_item.gd.uid b/entities/grabbable_base/grabbable_item.gd.uid similarity index 100% rename from classes/grabbable_item.gd.uid rename to entities/grabbable_base/grabbable_item.gd.uid diff --git a/classes/equippable_item.gd b/entities/pickupable/pickupable_item.gd similarity index 77% rename from classes/equippable_item.gd rename to entities/pickupable/pickupable_item.gd index be1d5a8..56317db 100644 --- a/classes/equippable_item.gd +++ b/entities/pickupable/pickupable_item.gd @@ -1,5 +1,5 @@ @icon("res://addons/at-icons/node3d/hand.svg") -class_name EquippableItem extends RigidBody3D +class_name PickupableItem extends RigidBody3D # The @export_file tag creates a folder icon in the Inspector # that only lets you select saved .tscn files! @@ -11,7 +11,7 @@ class_name EquippableItem extends RigidBody3D var weight: float = 10.0 func _ready() -> void: - self.add_to_group("equippable") + self.add_to_group("pickupable") for x in get_children(): - x.add_to_group("equippable") + x.add_to_group("pickupable") collision_layer = 17 diff --git a/classes/equippable_item.gd.uid b/entities/pickupable/pickupable_item.gd.uid similarity index 100% rename from classes/equippable_item.gd.uid rename to entities/pickupable/pickupable_item.gd.uid diff --git a/entities/equippable/test_object_equippable.tscn b/entities/pickupable/test_object_pickupable.tscn similarity index 93% rename from entities/equippable/test_object_equippable.tscn rename to entities/pickupable/test_object_pickupable.tscn index 766e374..d09e4a9 100644 --- a/entities/equippable/test_object_equippable.tscn +++ b/entities/pickupable/test_object_pickupable.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://don2g5auhwbl8"] -[ext_resource type="Script" uid="uid://yggv7ie8yere" path="res://classes/equippable_item.gd" id="1_xb40d"] +[ext_resource type="Script" uid="uid://yggv7ie8yere" path="res://entities/pickupable/pickupable_item.gd" id="1_xb40d"] [sub_resource type="BoxShape3D" id="BoxShape3D_yf5fn"] diff --git a/entities/equippable/test_object_equippable_2.tscn b/entities/pickupable/test_object_pickupable_2.tscn similarity index 93% rename from entities/equippable/test_object_equippable_2.tscn rename to entities/pickupable/test_object_pickupable_2.tscn index dccc39d..1b9c4ff 100644 --- a/entities/equippable/test_object_equippable_2.tscn +++ b/entities/pickupable/test_object_pickupable_2.tscn @@ -1,6 +1,6 @@ [gd_scene format=3 uid="uid://codt2h7ojcsae"] -[ext_resource type="Script" uid="uid://yggv7ie8yere" path="res://classes/equippable_item.gd" id="1_sb4pp"] +[ext_resource type="Script" uid="uid://yggv7ie8yere" path="res://entities/pickupable/pickupable_item.gd" id="1_sb4pp"] [sub_resource type="BoxShape3D" id="BoxShape3D_yf5fn"] diff --git a/entities/player/hotbar_component.gd b/entities/player/hotbar_component.gd index 640abac..8bfc6cf 100644 --- a/entities/player/hotbar_component.gd +++ b/entities/player/hotbar_component.gd @@ -4,17 +4,124 @@ var selected_item: int = 0 var prev_selected_item: int = 0 var inventory: Array[ItemData] = [null, null] -@export var equipped_item_mesh: MeshInstance3D +@export var equipped_item_position: Marker3D @export var hold_position: Marker3D @export var cursor_raycast: RayCast3D signal added_inventory_slot(successful: bool) signal removed_inventory_slot(successful: bool) -signal select_item(index: int) # For UI elements signal add_item(index: int, item: ItemData) signal remove_item(index: int) +signal select_item(index: int) + +var hand_cache: Dictionary = {} + + +func _select_item(index:int = selected_item) -> void: + # --- 1. HIDE ALL ITEMS IN CACHE TO BE SAFE --- + # Instead of relying on prev_selected_item (which can break during inventory swaps), + # we quickly hide everything in the cache. This guarantees no "ghost" items. + for key in hand_cache: + var cached_node = hand_cache[key] + if is_instance_valid(cached_node): + cached_node.hide() + cached_node.process_mode = Node.PROCESS_MODE_DISABLED + + # Update the index + selected_item = index + var current_data = inventory[index] + + # --- 2. SHOW OR INSTANTIATE THE NEW ITEM --- + if current_data != null and current_data.scene_path != "": + var item_path = current_data.scene_path + + # Did we already instantiate this item type, AND is it still valid (not freed)? + if hand_cache.has(item_path) and is_instance_valid(hand_cache[item_path]): + var cached_item = hand_cache[item_path] + cached_item.show() + cached_item.process_mode = Node.PROCESS_MODE_INHERIT + + else: + # Build it once. + var item_scene = load(item_path) as PackedScene + if item_scene: + var new_item = item_scene.instantiate() + equipped_item_position.add_child(new_item) + + if new_item is RigidBody3D: + new_item.freeze = true + + new_item.position = Vector3.ZERO + new_item.rotation = Vector3.ZERO + + # Save it to the dictionary + hand_cache[item_path] = new_item + + select_item.emit(index) + + +func update_slot(index: int, new_item: ItemData) -> void: + # 1. Clean up the physical 3D mesh of the old item being replaced/removed + var old_item = inventory[index] + if old_item != null and old_item.scene_path != "": + if hand_cache.has(old_item.scene_path): + var old_node = hand_cache[old_item.scene_path] + if is_instance_valid(old_node): + old_node.queue_free() # Free the 3D node from the equippable marker! + hand_cache.erase(old_item.scene_path) + + # 2. Update the array + inventory[index] = new_item + + # 3. Tell the in-game HUD that the slot changed + if new_item != null: + add_item.emit(index, new_item) + else: + remove_item.emit(index) + + # 4. Instantly refresh the hand visual (whether we added a new item or emptied it) + _select_item(selected_item) + + +func _remove_item(index: int): + # Clean up the physical 3D mesh before clearing the array + var old_item = inventory[index] + if old_item != null and old_item.scene_path != "": + if hand_cache.has(old_item.scene_path): + var old_node = hand_cache[old_item.scene_path] + if is_instance_valid(old_node): + old_node.queue_free() # Free the 3D node! + hand_cache.erase(old_item.scene_path) + + remove_item.emit(index) + inventory[index] = null + _select_item(selected_item) # Refresh the hand model + + +func use_active_item() -> void: + var current_data = inventory[selected_item] + + if current_data == null: + return + + if current_data.item_type == ItemData.ItemType.BACKPACK: + print("Equip Backpack via Hotbar!") + return + elif current_data.item_type == ItemData.ItemType.POCKET: + print("Equip Pocket via Hotbar!") + return + + var item_path = current_data.scene_path + + if item_path != "" and hand_cache.has(item_path): + var active_3d_item = hand_cache[item_path] + + if is_instance_valid(active_3d_item) and active_3d_item is UsableItem: + active_3d_item.use() + update_slot(selected_item, null) + func add_inventory_slot() -> bool: if len(inventory) < 5: @@ -24,6 +131,7 @@ func add_inventory_slot() -> bool: added_inventory_slot.emit(false) return false + func remove_inventory_slot() -> bool: if len(inventory) > 2: inventory.remove_at(len(inventory) - 1) @@ -32,6 +140,7 @@ func remove_inventory_slot() -> bool: removed_inventory_slot.emit(false) return false + func next_item(): prev_selected_item = selected_item if selected_item + 1 > len(inventory) - 1: @@ -40,6 +149,7 @@ func next_item(): selected_item += 1 _select_item() + func prev_item(): prev_selected_item = selected_item if selected_item - 1 < 0: @@ -48,22 +158,10 @@ func prev_item(): selected_item -= 1 _select_item() -func _select_item(index: int = selected_item): - selected_item = index - if index >= 0 and index < len(inventory): - select_item.emit(index) - - # Update the hand visual - if inventory[index] == null: - equipped_item_mesh.mesh = PlaceholderMesh.new() - else: - # Apply the mesh directly from the ItemData! - equipped_item_mesh.mesh = inventory[index].hand_mesh -func _add_item(item: EquippableItem): +func _add_item(item: PickupableItem): var target_index = -1 - # 1. Decide which slot to use (current slot first, then first empty) if inventory[selected_item] == null: target_index = selected_item else: @@ -72,12 +170,10 @@ func _add_item(item: EquippableItem): target_index = i break - # If inventory is full, do nothing if target_index == -1: print("Inventory Full!") return - # 2. Extract Data from the physical item var new_item_data: ItemData = ItemData.new() new_item_data.name = item.name new_item_data.weight = item.weight @@ -88,75 +184,49 @@ func _add_item(item: EquippableItem): new_item_data.provided_slots = item.inventory_size elif item is Pocket: new_item_data.item_type = ItemData.ItemType.POCKET + elif item is UsableItem: + new_item_data.item_type = ItemData.ItemType.USABLE else: new_item_data.item_type = ItemData.ItemType.NORMAL - - - # Save the mesh so we can display it in the player's hand later if item.mesh: new_item_data.hand_mesh = item.mesh.mesh - # Await your custom icon generator (if it requires awaiting) new_item_data.ui_icon = await GrabbableBase.create_icon_from_mesh(item.mesh.mesh) - # 3. Add to inventory array and UI inventory[target_index] = new_item_data add_item.emit(target_index, new_item_data) - # 4. CRITICAL: Delete the physical item from the world! item.queue_free() - - # Update the hand model if we added it to our currently selected slot _select_item(selected_item) -func update_slot(index: int, new_item: ItemData) -> void: - inventory[index] = new_item - - # Tell the in-game HUD that the slot changed - if new_item != null: - add_item.emit(index, new_item) - else: - remove_item.emit(index) - - # If this is the slot the player is currently holding, update the 3D hand mesh! - if index == selected_item: - _select_item(selected_item) func _drop_item(index: int = selected_item): var item_data = inventory[index] if item_data != null and item_data.scene_path != "": - # 1. Load the original scene file for the item var packed_scene = load(item_data.scene_path) as PackedScene if not packed_scene: push_error("Could not load scene path: " + item_data.scene_path) return - # 2. Instantiate a brand new physical object var new_object = packed_scene.instantiate() as RigidBody3D - - # 3. Add it to the world (Parent it to the main scene, not the player!) get_tree().current_scene.add_child(new_object) - # 4. Place it in front of the player new_object.global_position = hold_position.global_position new_object.global_rotation = Vector3.ZERO - # 5. Clear the inventory slot _remove_item(index) -func _remove_item(index: int): - remove_item.emit(index) - inventory[index] = null - _select_item(selected_item) # Refresh the hand model func get_selected_item() -> ItemData: return inventory[selected_item] + func _ready() -> void: get_tree().create_timer(0.1).timeout.connect(func(): _select_item(0)) + func _process(_delta: float) -> void: if Console.toggled or UiManager.in_game_menu.visible: return @@ -172,170 +242,14 @@ func _process(_delta: float) -> void: if Input.is_action_just_pressed("select_item_4"): _select_item(3) if Input.is_action_just_pressed("select_item_5"): _select_item(4) - if Input.is_action_just_pressed("equip"): + if Input.is_action_just_pressed("use"): if cursor_raycast.is_colliding(): var hit_object = cursor_raycast.get_collider() - if hit_object is EquippableItem: + if hit_object is PickupableItem: _add_item(hit_object) + else: + if inventory[selected_item] != null: + use_active_item() if Input.is_action_just_pressed("drop"): _drop_item() - -#class_name HotbarComponent extends Node -# -#var selected_item: int = 0 -#var prev_selected_item: int = 0 -#var selected_item_object: EquippableItem = null -#var inventory: Array[ItemData] = [null,null] -# -#@export var equipped_item_mesh: MeshInstance3D -#@export var hold_position: Marker3D -#@export var cursor_raycast: RayCast3D -# -#signal added_inventory_slot(successful:bool) -#signal removed_inventory_slot(successful:bool) -#signal select_item(index: int) -# -##for ui elements -#signal add_item(index: int, item: ItemData) -#signal remove_item(index: int) -# -#func add_inventory_slot() -> bool: - #if len(inventory) < 5: - #inventory.append(null) - #added_inventory_slot.emit(true) - #return true - #added_inventory_slot.emit(false) - #return false -# -#func remove_inventory_slot() -> bool: - #if len(inventory) > 2: - #inventory.remove_at(len(inventory) - 1) - #removed_inventory_slot.emit(true) - #return true - #added_inventory_slot.emit(false) - #return false -# -#func next_item(): - #prev_selected_item = selected_item - #if selected_item + 1 > len(inventory) - 1: - #selected_item = 0 - #else: - #selected_item += 1 - #_select_item() -# -#func prev_item(): - #prev_selected_item = selected_item - #if selected_item - 1 < 0: - #selected_item = len(inventory) - 1 - #else: - #selected_item -= 1 - #_select_item() -# -#func _select_item(index:int = selected_item): - #if index >= 0 and index < len(inventory): - #select_item.emit(index) - # - #if inventory[index] == null: - ##if current index is empty in the inventory, replace held object with placeholder (empty mesh) - #equipped_item_mesh.mesh = PlaceholderMesh.new() - #else: - #var mesh = null - #for i in inventory[index].get_children(): - #if i is MeshInstance3D: - #equipped_item_mesh.mesh = i.mesh -# -#func _add_item(item: EquippableItem): - ##add item to current equipped slot if empty - # - #var new_item_data = ItemData.new() - #new_item_data.name = item.name - #new_item_data.weight = item.weight - #new_item_data.scene_path = item.scene_file_path - #new_item_data.ui_icon = await GrabbableBase.create_icon_from_mesh(item.mesh.mesh) - #if inventory[selected_item] == null: - #inventory[selected_item] = new_item_data - # - #add_item.emit(selected_item, new_item_data) - # - ##ui.add_item(selected_item, item) - #item.reparent(get_parent().get_parent()) - #item.collision_layer = 0 - #item.visible = false - #_select_item(selected_item) - #return - # - ##add item to first empty slot if currently equipped slot is full - #for i in range(0, len(inventory)): - #if inventory[i] == null: - #inventory[i] = new_item_data - # - #add_item.emit(i, new_item_data) - ##ui.add_item(i, item) - #item.reparent(get_parent().get_parent()) - #item.collision_layer = 0 - #item.visible = false - #return - # - ##dont equip item if inventory full -# -#func _drop_item(index: int = selected_item): - #if inventory[index] != null: - #var object = inventory[index] - # - #object.scale = Vector3.ONE - # - #if object.is_inside_tree(): - #object.reparent(get_tree().current_scene, true) - # - #object.collision_layer = 17 - #object.global_position = hold_position.global_position - #object.visible = true - #object.global_rotation = Vector3.ZERO - # - #_remove_item(index) - # -#func _remove_item(index: int): - ##ui.remove_item(index) - #remove_item.emit(index) - #inventory[index] = null - #_select_item(index) -# -#func get_selected_item() -> ItemData: - #return inventory[selected_item] - # -#func _ready() -> void: - #get_tree().create_timer(0.1).timeout.connect(func (): _select_item(0)) -# -#func _process(_delta: float) -> void: - #if not Console.toggled and not UiManager.in_game_menu.visible: - #if Input.is_action_just_pressed("next_item"): - #next_item() - # - #if Input.is_action_just_pressed("prev_item"): - #prev_item() - # - #if Input.is_action_just_pressed("select_item_1"): - #_select_item(0) - # - #if Input.is_action_just_pressed("select_item_2"): - #_select_item(1) - # - #if Input.is_action_just_pressed("select_item_3"): - #_select_item(2) - # - #if Input.is_action_just_pressed("select_item_4"): - #_select_item(3) - # - #if Input.is_action_just_pressed("select_item_5"): - #_select_item(4) - # - #if Input.is_action_just_pressed("equip"): - #if cursor_raycast.is_colliding(): - #var hit_object = cursor_raycast.get_collider() - # - #if hit_object is EquippableItem: - #_add_item(hit_object) - # - #if Input.is_action_just_pressed("drop"): - #_drop_item() diff --git a/entities/player/input_controller_component.gd b/entities/player/input_controller_component.gd index 17361ac..5eef689 100644 --- a/entities/player/input_controller_component.gd +++ b/entities/player/input_controller_component.gd @@ -50,7 +50,7 @@ func _process(_delta: float) -> void: if cursor_raycast.is_colliding(): var hit_object = cursor_raycast.get_collider() - if hit_object is RigidBody3D and hit_object.is_in_group("grabbable") or hit_object.is_in_group("equippable"): + if hit_object is RigidBody3D and hit_object.is_in_group("grabbable") or hit_object.is_in_group("pickupable") or hit_object.is_in_group("equippable"): held_object = hit_object held_object.gravity_scale = 0.0 held_object.angular_damp = 5.0 diff --git a/entities/player/player.tscn b/entities/player/player.tscn index b998647..e87cdac 100644 --- a/entities/player/player.tscn +++ b/entities/player/player.tscn @@ -22,8 +22,6 @@ [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_g4v7s"] radius = 0.6166992 -[sub_resource type="PlaceholderMesh" id="PlaceholderMesh_b5l5s"] - [sub_resource type="CylinderShape3D" id="CylinderShape3D_g4v7s"] radius = 0.04638672 @@ -92,10 +90,10 @@ unique_name_in_owner = true script = ExtResource("65_kssj8") player = NodePath("../..") -[node name="HotbarComponent" type="Node" parent="Components" unique_id=1980833408 node_paths=PackedStringArray("equipped_item_mesh", "hold_position", "cursor_raycast")] +[node name="HotbarComponent" type="Node" parent="Components" unique_id=1980833408 node_paths=PackedStringArray("equipped_item_position", "hold_position", "cursor_raycast")] unique_name_in_owner = true script = ExtResource("10_ugbui") -equipped_item_mesh = NodePath("../../CameraPivot/PlayerCamera/EquippedItemMesh") +equipped_item_position = NodePath("../../CameraPivot/PlayerCamera/CurrentItemPosition") hold_position = NodePath("../../CameraPivot/PlayerCamera/HoldPosition") cursor_raycast = NodePath("../../CameraPivot/PlayerCamera/CursorRaycast") @@ -165,10 +163,9 @@ target_position = Vector3(0, -2, 0) unique_name_in_owner = true transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.5) -[node name="EquippedItemMesh" type="MeshInstance3D" parent="CameraPivot/PlayerCamera" unique_id=825894473] +[node name="CurrentItemPosition" type="Marker3D" parent="CameraPivot/PlayerCamera" unique_id=1900704334] unique_name_in_owner = true transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0.4, -0.30000004, -0.7) -mesh = SubResource("PlaceholderMesh_b5l5s") [node name="GrabbableFinder" type="Area3D" parent="CameraPivot/PlayerCamera" unique_id=988433915] diff --git a/entities/player/prompt_handler.gd b/entities/player/prompt_handler.gd index 1837cd5..7acc235 100644 --- a/entities/player/prompt_handler.gd +++ b/entities/player/prompt_handler.gd @@ -9,8 +9,8 @@ func _on_action_finder_body_entered(body: Node3D) -> void: if body != null: if body.is_in_group("grabbable"): prompt.change_text("[LMB] to grab") - elif body is EquippableItem: - prompt.change_text("[R] to equip") + elif body is PickupableItem: + prompt.change_text("[R] to pick up") else: return action_panel_body = body diff --git a/entities/pocket/pocket.gd b/entities/pocket/pocket.gd index 90a44a7..73cf3c5 100644 --- a/entities/pocket/pocket.gd +++ b/entities/pocket/pocket.gd @@ -1,3 +1,3 @@ -class_name Pocket extends EquippableItem +class_name Pocket extends PickupableItem #TODO: add pocket logic later diff --git a/entities/usable/stamina_recharge_item.gd b/entities/usable/stamina_recharge_item.gd new file mode 100644 index 0000000..4aefb8a --- /dev/null +++ b/entities/usable/stamina_recharge_item.gd @@ -0,0 +1,5 @@ +class_name StaminaRechargeItem extends UsableItem + +func use(): + Player.player.stamina_component.add_stamina(10) + queue_free() diff --git a/entities/usable/stamina_recharge_item.gd.uid b/entities/usable/stamina_recharge_item.gd.uid new file mode 100644 index 0000000..39b6eb2 --- /dev/null +++ b/entities/usable/stamina_recharge_item.gd.uid @@ -0,0 +1 @@ +uid://ltgcsertsux7 diff --git a/entities/usable/stamina_recharge_item.tscn b/entities/usable/stamina_recharge_item.tscn new file mode 100644 index 0000000..6885fa0 --- /dev/null +++ b/entities/usable/stamina_recharge_item.tscn @@ -0,0 +1,28 @@ +[gd_scene format=3 uid="uid://cr58irln78feo"] + +[ext_resource type="Script" uid="uid://ltgcsertsux7" path="res://entities/usable/stamina_recharge_item.gd" id="1_gy8nx"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_gy8nx"] +albedo_color = Color(0.41262913, 0.69107723, 7.70092e-07, 1) + +[sub_resource type="CapsuleMesh" id="CapsuleMesh_b5l5s"] +material = SubResource("StandardMaterial3D_gy8nx") +radius = 0.1 +height = 0.5 + +[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_b5l5s"] +radius = 0.1 +height = 0.5 + +[node name="UsableBase" type="RigidBody3D" unique_id=1625119467 node_paths=PackedStringArray("mesh", "collision")] +script = ExtResource("1_gy8nx") +scene_path = "uid://cr58irln78feo" +mesh = NodePath("MeshInstance3D") +collision = NodePath("CollisionShape3D") +metadata/_custom_type_script = "uid://ltgcsertsux7" + +[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=789013428] +mesh = SubResource("CapsuleMesh_b5l5s") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=227869647] +shape = SubResource("CapsuleShape3D_b5l5s") diff --git a/entities/usable/usable_item.gd b/entities/usable/usable_item.gd new file mode 100644 index 0000000..d5663a1 --- /dev/null +++ b/entities/usable/usable_item.gd @@ -0,0 +1,3 @@ +@abstract class_name UsableItem extends PickupableItem + +@abstract func use() diff --git a/entities/usable/usable_item.gd.uid b/entities/usable/usable_item.gd.uid new file mode 100644 index 0000000..f11b055 --- /dev/null +++ b/entities/usable/usable_item.gd.uid @@ -0,0 +1 @@ +uid://mmsevxf4u4j1 diff --git a/maps/dev/dev_map.tscn b/maps/dev/dev_map.tscn index 72dfdb4..42da028 100644 --- a/maps/dev/dev_map.tscn +++ b/maps/dev/dev_map.tscn @@ -1,13 +1,14 @@ [gd_scene format=3 uid="uid://chykk2a3opu0d"] [ext_resource type="PackedScene" uid="uid://dvw51mhd42wg7" path="res://entities/backpack/bakpakbruh.tscn" id="1_de016"] -[ext_resource type="Script" uid="uid://d5aotywdqlh5" path="res://classes/grabbable_item.gd" id="1_l7v2h"] +[ext_resource type="Script" uid="uid://d5aotywdqlh5" path="res://entities/grabbable_base/grabbable_item.gd" id="1_l7v2h"] [ext_resource type="PackedScene" uid="uid://kqq30y24c6kd" path="res://entities/player/player.tscn" id="1_s8b7j"] [ext_resource type="AudioStream" uid="uid://b6wlbiittcu48" path="res://assets/sounds/ambiance/harmonika-paulstretched.mp3" id="3_mtlx8"] -[ext_resource type="PackedScene" uid="uid://don2g5auhwbl8" path="res://entities/equippable/test_object_equippable.tscn" id="3_omlgy"] -[ext_resource type="PackedScene" uid="uid://codt2h7ojcsae" path="res://entities/equippable/test_object_equippable_2.tscn" id="4_8r7k8"] +[ext_resource type="PackedScene" uid="uid://don2g5auhwbl8" path="res://entities/pickupable/test_object_pickupable.tscn" id="3_omlgy"] +[ext_resource type="PackedScene" uid="uid://codt2h7ojcsae" path="res://entities/pickupable/test_object_pickupable_2.tscn" id="4_8r7k8"] [ext_resource type="Script" uid="uid://y8x4svl5kej2" path="res://addons/spatial_audio_3d/spatial_audio_3d.gd" id="4_yb1w3"] [ext_resource type="PackedScene" uid="uid://wvsly1kbdney" path="res://entities/pocket/pocket.tscn" id="5_8r7k8"] +[ext_resource type="PackedScene" uid="uid://cr58irln78feo" path="res://entities/usable/stamina_recharge_item.tscn" id="9_hupuo"] [sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_g4v7s"] @@ -142,3 +143,6 @@ shape = SubResource("BoxShape3D_57qmd") [node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=376113449] environment = SubResource("Environment_b5l5s") camera_attributes = SubResource("CameraAttributesPractical_60a4j") + +[node name="UsableBase" parent="." unique_id=1189819781 instance=ExtResource("9_hupuo")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.8267124, 0.65320015, -0.25214243) diff --git a/project.godot b/project.godot index f8bae83..3a4f1ed 100644 --- a/project.godot +++ b/project.godot @@ -71,8 +71,9 @@ import/blender/enabled=false [global_group] grabbable="this object can be grabbed" -equippable="the item is equippable" player="players" +pickupable="the item is equippable" +equippable="" [input] @@ -196,7 +197,7 @@ open_menu={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null) ] } -equip={ +use={ "deadzone": 0.2, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null) diff --git a/scenes/ui/inventory/item_datat.gd b/scenes/ui/inventory/item_datat.gd index 297938f..4745984 100644 --- a/scenes/ui/inventory/item_datat.gd +++ b/scenes/ui/inventory/item_datat.gd @@ -1,6 +1,6 @@ class_name ItemData extends Resource -enum ItemType { NORMAL, BACKPACK, POCKET } +enum ItemType { NORMAL, BACKPACK, POCKET, USABLE } @export var item_type: ItemType = ItemType.NORMAL @export var provided_slots: int diff --git a/scripts/autoload/global_signals.gd b/scripts/autoload/global_signals.gd index a5e1a02..bbf2e53 100644 --- a/scripts/autoload/global_signals.gd +++ b/scripts/autoload/global_signals.gd @@ -11,7 +11,7 @@ signal drop_item(index:int) @warning_ignore("unused_signal") signal remove_item(index:int) @warning_ignore("unused_signal") -signal add_item(item: EquippableItem) +signal add_item(item: PickupableItem) @warning_ignore("unused_signal") signal stamina_recharge_off