diff --git a/autoloads/inventory_manager.gd b/autoloads/inventory_manager.gd index 4adffd6..08fb202 100644 --- a/autoloads/inventory_manager.gd +++ b/autoloads/inventory_manager.gd @@ -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) diff --git a/scenes/player/player.gd b/scenes/player/player.gd index d5a13a4..9495e8d 100644 --- a/scenes/player/player.gd +++ b/scenes/player/player.gd @@ -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() diff --git a/scenes/player/ray_cast_look.gd b/scenes/player/ray_cast_look.gd index f2a433c..73cbf0f 100644 --- a/scenes/player/ray_cast_look.gd +++ b/scenes/player/ray_cast_look.gd @@ -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