This commit is contained in:
Rendo 2025-10-14 21:55:24 +05:00
commit 222960a824
19 changed files with 282 additions and 22 deletions

View file

@ -14,15 +14,19 @@ class_name Queue
if value == capacity:
return
capacity = value
internal_array.resize(capacity)
for i in range(capacity):
internal_array[i] = InventorySlot.new()
get:
return capacity
## :3
@export_storage var internal_array : Array[InventorySlot] = []
func _init() -> void:
super()
internal_array.resize(capacity)
for i in range(capacity):
internal_array[i] = InventorySlot.new()
## Finds first entry of item. Returns -1 if no item found
func find(item : Item) -> int:
for i in range(len(internal_array)):
@ -34,16 +38,24 @@ func find(item : Item) -> int:
func add(stack: Stack) -> Stack:
for i in range(len(internal_array)):
if internal_array[i].held_item == null or internal_array[i].held_item == stack.held_item:
stack_added.emit(stack,i)
stack = internal_array[i].merge_stack(stack)
if stack == null:
return null
return stack
func can_add() -> bool:
for i in range(capacity):
if internal_array[i].amount == 0:
return true
return false
## Tries to take first item. Returns null if no items in inventory
func pop() -> Stack:
if internal_array[0].held_item == null:
return null
var stack_to_return = internal_array[0].extract()
stack_taken.emit(stack_to_return,0)
sort()
return stack_to_return
@ -53,6 +65,7 @@ func take(item: Item,amount: int) -> Stack:
if found == -1:
return null
var stack_to_return = internal_array[found].extract_stack(amount)
stack_taken.emit(stack_to_return,found)
sort()
return stack_to_return