Browse Source

wip: Add signal InventoryManager.remove_from_quickslot to simplify removing from quickslot

pull/24/head
Ryan Reed 3 weeks ago
parent
commit
1a857f3d0a
3 changed files with 18 additions and 10 deletions
  1. +16
    -8
      autoloads/inventory_manager.gd
  2. +1
    -1
      scenes/player/player.gd
  3. +1
    -1
      scenes/player/ray_cast_look.gd

+ 16
- 8
autoloads/inventory_manager.gd View File

@ -13,6 +13,7 @@ signal inventory_closed
signal inventory_opened
signal inventory_slot_updated(slot_index: int)
signal remove_from_inventory(item_id: String, amount: int)
signal remove_from_quickslot(amount: int)
signal remove_from_slot(slot_index: int, amount: int)
#endregion
@ -40,6 +41,7 @@ func _ready() -> void:
self.clear_inventory.connect(_on_clear_inventory)
self.quick_slot_selected.connect(_on_quick_slot_selected)
self.remove_from_inventory.connect(_on_remove_from_inventory)
self.remove_from_quickslot.connect(_on_remove_from_quickslot)
self.remove_from_slot.connect(_on_remove_from_slot)
func available_space(item_id: String) -> int:
@ -77,6 +79,17 @@ func _find_stacks_with_space(item_resource: DBItemResource, item_id: String) ->
)
)
func _remove_from_slot(slot_index: int, amount: int) -> void:
if slot_index >= max_inventory_items:
printerr("Slot Index ", slot_index, " out of inventory range")
return
inventory[slot_index].amount -= amount
if inventory[slot_index].amount <= 0:
inventory[slot_index] = null
inventory_slot_updated.emit(slot_index)
func _update_cache_total(item_id: String, amount: int) -> void:
if not _inventory_cache.get(item_id):
_inventory_cache[item_id] = {"total": 0}
@ -176,12 +189,7 @@ func _on_quick_slot_selected(slot_index: int) -> void:
## Removes an amount of items from a specific slot
## If the amount exceeds the amount of the slot, will NOT remove from other stacks
func _on_remove_from_slot(slot_index: int, amount: int) -> void:
if slot_index >= max_inventory_items:
printerr("Slot Index ", slot_index, " out of inventory range")
return
_remove_from_slot(slot_index, amount)
inventory[slot_index].amount -= amount
if inventory[slot_index].amount <= 0:
inventory[slot_index] = null
inventory_slot_updated.emit(slot_index)
func _on_remove_from_quickslot(amount: int) -> void:
_remove_from_slot(selected_quick_slot, amount)

+ 1
- 1
scenes/player/player.gd View File

@ -39,7 +39,7 @@ func _input(event: InputEvent) -> void:
elif event.is_action_pressed("throw_item"): # TODO: Move to state?
if InventoryManager.get_inventory_item() != null:
EntityManager.drop_block.emit(InventoryManager.get_quick_slot_item_id(), head.global_position, -head.global_basis.z, throw_velocity)
InventoryManager.remove_from_inventory.emit(InventoryManager.get_quick_slot_item_id(), 1)
InventoryManager.remove_from_quickslot.emit(1)
func _physics_process(delta: float) -> void:
is_crouching = Input.is_action_pressed("crouch") or ray_cast_crouch.is_colliding()


+ 1
- 1
scenes/player/ray_cast_look.gd View File

@ -18,7 +18,7 @@ func _process(_delta: float) -> void:
return
EntityManager.create_block.emit(InventoryManager.get_quick_slot_item_id(), block_pos)
InventoryManager.remove_from_slot.emit(InventoryManager.selected_quick_slot, 1)
InventoryManager.remove_from_quickslot.emit(1)
if Waila.ref.get_target() == collider:
return


Loading…
Cancel
Save