|
|
@ -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) |