Browse Source

Adding to and subtracting from inventory on DroppedItem pickup

pull/4/head
Ryan Reed 1 month ago
parent
commit
5635c15e6e
9 changed files with 67 additions and 16 deletions
  1. +2
    -1
      autoloads/inventory_manager.gd
  2. +1
    -1
      resources/blocks/001_dirt.tres
  3. +1
    -1
      resources/blocks/002_stone.tres
  4. +1
    -1
      resources/blocks/003_wood.tres
  5. +1
    -1
      resources/blocks/004_leaves.tres
  6. +53
    -6
      resources/inventory/player_inventory_testing.tres
  7. +1
    -1
      resources/item_resource.gd
  8. +4
    -2
      scenes/blocks/dropped_block.gd
  9. +3
    -2
      scenes/ui/inventory/inventory.gd

+ 2
- 1
autoloads/inventory_manager.gd View File

@ -4,7 +4,8 @@ signal next_quick_slot
signal previous_quick_slot signal previous_quick_slot
signal select_quick_slot(slot_index: int) signal select_quick_slot(slot_index: int)
signal quick_slot_item_changed(item_id: String) 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_opened
signal inventory_closed signal inventory_closed


+ 1
- 1
resources/blocks/001_dirt.tres View File

@ -8,7 +8,7 @@ script = ExtResource("1_ljghb")
material_east = ExtResource("1_n1cq6") material_east = ExtResource("1_n1cq6")
id = "001" id = "001"
name = "Dirt" name = "Dirt"
amount = 998
amount = 0
description = "Block of dirt" description = "Block of dirt"
item_texture = "uid://li36txj7oweq" item_texture = "uid://li36txj7oweq"
metadata/_custom_type_script = "uid://dwrmy4mx0mw18" metadata/_custom_type_script = "uid://dwrmy4mx0mw18"

+ 1
- 1
resources/blocks/002_stone.tres View File

@ -8,7 +8,7 @@ script = ExtResource("1_63t5s")
material_east = ExtResource("1_6chm7") material_east = ExtResource("1_6chm7")
id = "002" id = "002"
name = "Stone" name = "Stone"
amount = 998
amount = 0
description = "Block of stone" description = "Block of stone"
item_texture = "uid://ct1iawpfkdf5l" item_texture = "uid://ct1iawpfkdf5l"
metadata/_custom_type_script = "uid://dwrmy4mx0mw18" metadata/_custom_type_script = "uid://dwrmy4mx0mw18"

+ 1
- 1
resources/blocks/003_wood.tres View File

@ -14,7 +14,7 @@ material_top = ExtResource("1_1n8h6")
material_bottom = ExtResource("1_1n8h6") material_bottom = ExtResource("1_1n8h6")
id = "003" id = "003"
name = "Wood" name = "Wood"
amount = 998
amount = 0
description = "Wood log" description = "Wood log"
item_texture = "uid://0mw651622h01" item_texture = "uid://0mw651622h01"
metadata/_custom_type_script = "uid://dwrmy4mx0mw18" metadata/_custom_type_script = "uid://dwrmy4mx0mw18"

+ 1
- 1
resources/blocks/004_leaves.tres View File

@ -8,7 +8,7 @@ script = ExtResource("3_kuops")
material_east = ExtResource("1_dbmit") material_east = ExtResource("1_dbmit")
id = "004" id = "004"
name = "Leaves" name = "Leaves"
amount = 998
amount = 0
description = "Tree leaves" description = "Tree leaves"
item_texture = "uid://goygbpyqhych" item_texture = "uid://goygbpyqhych"
metadata/_custom_type_script = "uid://dwrmy4mx0mw18" metadata/_custom_type_script = "uid://dwrmy4mx0mw18"

+ 53
- 6
resources/inventory/player_inventory_testing.tres View File

@ -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://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="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] [resource]
script = ExtResource("1_4v6mg") 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 max_stack_size = 999
metadata/_custom_type_script = "uid://becun6dj78v8d" metadata/_custom_type_script = "uid://becun6dj78v8d"

+ 1
- 1
resources/item_resource.gd View File

@ -4,6 +4,6 @@ extends Resource
@export var id: String = "000" @export var id: String = "000"
@export var name: String = "Item Name" @export var name: String = "Item Name"
@export var amount: int = 999
@export var amount: int = 0
@export var description: String = "Item Description" @export var description: String = "Item Description"
@export_file var item_texture: String = "res://icon.svg" @export_file var item_texture: String = "res://icon.svg"

+ 4
- 2
scenes/blocks/dropped_block.gd View File

@ -22,7 +22,9 @@ func initialize(id: String, _position: Vector3) -> void:
func _on_pickup_area_body_entered(body: Node3D) -> void: func _on_pickup_area_body_entered(body: Node3D) -> void:
if not body is Player: return 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 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() queue_free()

+ 3
- 2
scenes/ui/inventory/inventory.gd View File

@ -12,12 +12,13 @@ func _input(event: InputEvent) -> void:
toggle_inventory() toggle_inventory()
func _ready() -> void: 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: for item_resource: ItemResource in inventory_resource.inventory:
print(item_resource.name + " - " + str(item_resource.amount))
add_item(item_resource) 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) var item_rect: InventoryItemRect = find_item_rect(item_resource)
if item_rect != null: if item_rect != null:
if item_rect.item_resource.amount + item_resource.amount >= inventory_resource.max_stack_size: if item_rect.item_resource.amount + item_resource.amount >= inventory_resource.max_stack_size:


Loading…
Cancel
Save