Item void

This commit is contained in:
Rendo 2025-10-17 01:11:01 +05:00
commit fa6212400b
7 changed files with 43 additions and 29 deletions

View file

@ -20,6 +20,7 @@ class_name InventorySlot
amount = 0
return
if held_item == null:
amount = 0
return
if value > held_item.stack_size:
amount = held_item.stack_size
@ -66,7 +67,7 @@ func as_stack() -> Stack:
func can_be_merged(item : Item) -> bool:
if filter != null:
return filter.is_equal(item)
if amount == 0:
if amount <= 0:
return true
return item == held_item

View file

@ -44,7 +44,7 @@ func add(stack: Stack, _context: InventoryContext = null) -> Stack:
if stack.is_valid() == false:
return null
for i in range(len(internal_array)):
if internal_array[i].held_item == null or internal_array[i].held_item == stack.held_item:
if internal_array[i].can_be_merged(stack.held_item):
stack_added.emit(stack,i)
internal_array[i].merge_stack(stack)
if stack.is_valid() == false:
@ -54,13 +54,13 @@ func add(stack: Stack, _context: InventoryContext = null) -> Stack:
func can_add(item : Item = null, _context: InventoryContext = null) -> bool:
if item == null:
for i in range(capacity):
return internal_array[i].amount == 0
if internal_array[i].can_be_merged(item):
return true
return false
else:
for i in range(capacity):
if internal_array[i].amount == 0:
return (internal_array[i].filter != null and internal_array[i].filter.is_equal(item)) or internal_array[i].filter == null
return internal_array[i].held_item.is_equal(item)
if internal_array[i].can_be_merged(item):
return true
return false
## Tries to take first item. Returns null if no items in inventory

View file

@ -0,0 +1,29 @@
extends Inventory
## Base class for simple storages with no differentiation.
class_name VoidInventory
## Tries to add an item into inventory. Returns not stored stack of item.
func add(stack : Stack, context: InventoryContext = null) -> Stack:
return null
## Returns if conditions of adding are met
func can_add(item : Item = null, context: InventoryContext = null) -> bool:
return true
## Tries to take first item. Returns null if no items in inventory
func pop() -> Stack:
return null
func peek() -> Stack:
return null
## Tries to take certain item from inventory. Returns null if no item found
func take(item : Item,amount: int) -> Stack:
return null
## Finds first entry of item. Returns -1 if no item found
func find(item : Item) -> int:
return -1

View file

@ -0,0 +1 @@
uid://conadqnb0asi0

View file

@ -1,9 +0,0 @@
extends StructureBehaviour
@onready var inventory : Storage = structure_parent.inventory
func _ready() -> void:
inventory.stack_added.connect(on_stack_added)
func on_stack_added(_stack : Stack, _position: int) -> void:
inventory.internal_array[0].amount = 0

View file

@ -1 +0,0 @@
uid://dwx8y8c6guldd