diff --git a/autoloads/inventory_manager.gd b/autoloads/inventory_manager.gd index 9cd397e..9548fab 100644 --- a/autoloads/inventory_manager.gd +++ b/autoloads/inventory_manager.gd @@ -4,7 +4,8 @@ signal next_quick_slot signal previous_quick_slot signal select_quick_slot(slot_index: int) signal quick_slot_item_changed(item_id: String) -signal item_picked_up(item_id: String, amount: int) +signal item_picked_up(item: ItemResource) +signal item_dropped(item: ItemResource) signal inventory_opened signal inventory_closed diff --git a/resources/blocks/001_dirt.tres b/resources/blocks/001_dirt.tres index 1130feb..efd0ad1 100644 --- a/resources/blocks/001_dirt.tres +++ b/resources/blocks/001_dirt.tres @@ -8,7 +8,7 @@ script = ExtResource("1_ljghb") material_east = ExtResource("1_n1cq6") id = "001" name = "Dirt" -amount = 998 +amount = 0 description = "Block of dirt" item_texture = "uid://li36txj7oweq" metadata/_custom_type_script = "uid://dwrmy4mx0mw18" diff --git a/resources/blocks/002_stone.tres b/resources/blocks/002_stone.tres index a80ea9f..8e5d3d1 100644 --- a/resources/blocks/002_stone.tres +++ b/resources/blocks/002_stone.tres @@ -8,7 +8,7 @@ script = ExtResource("1_63t5s") material_east = ExtResource("1_6chm7") id = "002" name = "Stone" -amount = 998 +amount = 0 description = "Block of stone" item_texture = "uid://ct1iawpfkdf5l" metadata/_custom_type_script = "uid://dwrmy4mx0mw18" diff --git a/resources/blocks/003_wood.tres b/resources/blocks/003_wood.tres index 322e57b..ae533ae 100644 --- a/resources/blocks/003_wood.tres +++ b/resources/blocks/003_wood.tres @@ -14,7 +14,7 @@ material_top = ExtResource("1_1n8h6") material_bottom = ExtResource("1_1n8h6") id = "003" name = "Wood" -amount = 998 +amount = 0 description = "Wood log" item_texture = "uid://0mw651622h01" metadata/_custom_type_script = "uid://dwrmy4mx0mw18" diff --git a/resources/blocks/004_leaves.tres b/resources/blocks/004_leaves.tres index 48d0a55..7a32786 100644 --- a/resources/blocks/004_leaves.tres +++ b/resources/blocks/004_leaves.tres @@ -8,7 +8,7 @@ script = ExtResource("3_kuops") material_east = ExtResource("1_dbmit") id = "004" name = "Leaves" -amount = 998 +amount = 0 description = "Tree leaves" item_texture = "uid://goygbpyqhych" metadata/_custom_type_script = "uid://dwrmy4mx0mw18" diff --git a/resources/inventory/player_inventory_testing.tres b/resources/inventory/player_inventory_testing.tres index d452ad8..87921a6 100644 --- a/resources/inventory/player_inventory_testing.tres +++ b/resources/inventory/player_inventory_testing.tres @@ -1,14 +1,61 @@ -[gd_resource type="Resource" script_class="InventoryResource" load_steps=7 format=3 uid="uid://blfp6tiir282o"] +[gd_resource type="Resource" script_class="InventoryResource" load_steps=13 format=3 uid="uid://blfp6tiir282o"] [ext_resource type="Script" uid="uid://becun6dj78v8d" path="res://resources/inventory_resource.gd" id="1_4v6mg"] [ext_resource type="Script" uid="uid://bdx4q355l5ugl" path="res://resources/item_resource.gd" id="1_gg8jx"] -[ext_resource type="Resource" uid="uid://bu0yoee1rs1se" path="res://resources/blocks/001_dirt.tres" id="2_rssib"] -[ext_resource type="Resource" uid="uid://cpddnknmxpohc" path="res://resources/blocks/002_stone.tres" id="3_rlc1a"] -[ext_resource type="Resource" uid="uid://bvudydis6w27b" path="res://resources/blocks/003_wood.tres" id="4_rlc1a"] -[ext_resource type="Resource" uid="uid://4knt6o2ohku3" path="res://resources/blocks/004_leaves.tres" id="5_p27bu"] +[ext_resource type="Material" uid="uid://uex0dq00xomt" path="res://assets/materials/dirt.tres" id="2_8w148"] +[ext_resource type="Script" uid="uid://dwrmy4mx0mw18" path="res://resources/block_resource.gd" id="3_vgvac"] +[ext_resource type="Material" uid="uid://cx7m27qa4ds4s" path="res://assets/materials/stone.tres" id="4_7yuhn"] +[ext_resource type="Material" uid="uid://bnqiumcb3ixan" path="res://assets/materials/wood_ends.tres" id="5_viap3"] +[ext_resource type="Material" uid="uid://h0naiw6swfkl" path="res://assets/materials/wood_side.tres" id="6_wqat2"] +[ext_resource type="Material" uid="uid://d15n1p3spu3jg" path="res://assets/materials/leaves.tres" id="7_xd1nd"] + +[sub_resource type="Resource" id="Resource_jaam2"] +script = ExtResource("3_vgvac") +material_east = ExtResource("2_8w148") +id = "001" +name = "Dirt" +amount = 100 +description = "Block of dirt" +item_texture = "uid://li36txj7oweq" +metadata/_custom_type_script = "uid://dwrmy4mx0mw18" + +[sub_resource type="Resource" id="Resource_4kby3"] +script = ExtResource("3_vgvac") +material_east = ExtResource("4_7yuhn") +id = "002" +name = "Stone" +amount = 100 +description = "Block of stone" +item_texture = "uid://ct1iawpfkdf5l" +metadata/_custom_type_script = "uid://dwrmy4mx0mw18" + +[sub_resource type="Resource" id="Resource_byct5"] +script = ExtResource("3_vgvac") +material_east = ExtResource("6_wqat2") +material_west = ExtResource("6_wqat2") +material_north = ExtResource("6_wqat2") +material_south = ExtResource("6_wqat2") +material_top = ExtResource("5_viap3") +material_bottom = ExtResource("5_viap3") +id = "003" +name = "Wood" +amount = 100 +description = "Wood log" +item_texture = "uid://0mw651622h01" +metadata/_custom_type_script = "uid://dwrmy4mx0mw18" + +[sub_resource type="Resource" id="Resource_qycqj"] +script = ExtResource("3_vgvac") +material_east = ExtResource("7_xd1nd") +id = "004" +name = "Leaves" +amount = 100 +description = "Tree leaves" +item_texture = "uid://goygbpyqhych" +metadata/_custom_type_script = "uid://dwrmy4mx0mw18" [resource] script = ExtResource("1_4v6mg") -inventory = Array[ExtResource("1_gg8jx")]([ExtResource("2_rssib"), ExtResource("3_rlc1a"), ExtResource("4_rlc1a"), ExtResource("5_p27bu")]) +inventory = Array[ExtResource("1_gg8jx")]([SubResource("Resource_jaam2"), SubResource("Resource_4kby3"), SubResource("Resource_byct5"), SubResource("Resource_qycqj")]) max_stack_size = 999 metadata/_custom_type_script = "uid://becun6dj78v8d" diff --git a/resources/item_resource.gd b/resources/item_resource.gd index 1d3fbf5..a481462 100644 --- a/resources/item_resource.gd +++ b/resources/item_resource.gd @@ -4,6 +4,6 @@ extends Resource @export var id: String = "000" @export var name: String = "Item Name" -@export var amount: int = 999 +@export var amount: int = 0 @export var description: String = "Item Description" @export_file var item_texture: String = "res://icon.svg" diff --git a/scenes/blocks/dropped_block.gd b/scenes/blocks/dropped_block.gd index b222b91..a82a456 100644 --- a/scenes/blocks/dropped_block.gd +++ b/scenes/blocks/dropped_block.gd @@ -22,7 +22,9 @@ func initialize(id: String, _position: Vector3) -> void: func _on_pickup_area_body_entered(body: Node3D) -> void: if not body is Player: return - # TODO: Update stack_count when we start storing that information + # TODO: Update stack count dynamically var stack_count: int = 1 - InventoryManager.item_picked_up.emit(block.get_id(), stack_count) + var item: ItemResource = (DBItems.data[block.get_id()] as Resource).duplicate() + item.amount = stack_count + InventoryManager.item_picked_up.emit(item) queue_free() diff --git a/scenes/ui/inventory/inventory.gd b/scenes/ui/inventory/inventory.gd index 7b6dfdf..017079f 100644 --- a/scenes/ui/inventory/inventory.gd +++ b/scenes/ui/inventory/inventory.gd @@ -12,12 +12,13 @@ func _input(event: InputEvent) -> void: toggle_inventory() func _ready() -> void: + InventoryManager.item_picked_up.connect(add_item.bind()) + InventoryManager.item_dropped.connect(subtract_item.bind()) for item_resource: ItemResource in inventory_resource.inventory: - print(item_resource.name + " - " + str(item_resource.amount)) add_item(item_resource) -func add_item(item_resource: ItemResource) -> void: +func add_item(item_resource: ItemResource, amount: int = 1) -> void: var item_rect: InventoryItemRect = find_item_rect(item_resource) if item_rect != null: if item_rect.item_resource.amount + item_resource.amount >= inventory_resource.max_stack_size: