Fixed confict between null inventories, non conveyor inventories and conveyor

This commit is contained in:
Rendo 2025-10-15 00:38:41 +05:00
commit 2f68d123d7
4 changed files with 17 additions and 1 deletions

View file

@ -13,10 +13,14 @@ func _init() -> void:
## Tries to add an item into inventory. Returns not stored stack of item. ## Tries to add an item into inventory. Returns not stored stack of item.
@abstract @abstract
func add(stack : Stack) -> Stack func add(stack : Stack) -> Stack
@abstract
func add_from_side(stack : Stack, ang_diff : float) -> Stack
## Returns if conditions of adding are met ## Returns if conditions of adding are met
@abstract @abstract
func can_add() -> bool func can_add() -> bool
@abstract
func can_add_from_side(ang_diff : float) -> bool
## Tries to take first item. Returns null if no items in inventory ## Tries to take first item. Returns null if no items in inventory
@abstract @abstract

View file

@ -44,12 +44,18 @@ func add(stack: Stack) -> Stack:
return null return null
return stack return stack
func add_from_side(stack : Stack, _ang_diff : float) -> Stack:
return add(stack)
func can_add() -> bool: func can_add() -> bool:
for i in range(capacity): for i in range(capacity):
if internal_array[i].amount == 0: if internal_array[i].amount == 0:
return true return true
return false return false
func can_add_from_side(_ang_diff : float) -> bool:
return can_add()
## Tries to take first item. Returns null if no items in inventory ## Tries to take first item. Returns null if no items in inventory
func pop() -> Stack: func pop() -> Stack:
if internal_array[0].held_item == null: if internal_array[0].held_item == null:

View file

@ -48,12 +48,18 @@ func add(stack: Stack) -> Stack:
return null return null
return stack return stack
func add_from_side(stack : Stack, _ang_diff : float) -> Stack:
return add(stack)
func can_add() -> bool: func can_add() -> bool:
for i in range(capacity): for i in range(capacity):
if internal_array[i].amount == 0: if internal_array[i].amount == 0:
return true return true
return false return false
func can_add_from_side(_ang_diff : float) -> bool:
return can_add()
## Tries to take first item. Returns null if no items in inventory ## Tries to take first item. Returns null if no items in inventory
func pop() -> Stack: func pop() -> Stack:
for i in range(len(internal_array)): for i in range(len(internal_array)):

View file

@ -20,7 +20,7 @@ func _process(delta: float) -> void:
inventory.advance(delta) inventory.advance(delta)
queue_redraw() queue_redraw()
var next : Structure = get_next() var next : Structure = get_next()
if next == null or next.inventory.can_add_from_side(Globals.facing_difference(next.facing,parent_structure.facing)) == false: if next == null or next.inventory == null or next.inventory.can_add_from_side(Globals.facing_difference(next.facing,parent_structure.facing)) == false:
return return
var popped = inventory.pop() var popped = inventory.pop()
if popped == null: if popped == null: