ticker
This commit is contained in:
parent
c5846aba7b
commit
074bb21ffd
18 changed files with 99 additions and 51 deletions
|
@ -30,12 +30,15 @@ class_name InventorySlot
|
|||
return amount
|
||||
|
||||
@export_storage var filter : Comparable
|
||||
@export_storage var updated : bool
|
||||
|
||||
## Get some amount of items from slot. Returns null if slot is empty
|
||||
func extract_stack(extract_amount: int) -> Stack:
|
||||
if amount == 0:
|
||||
if amount == 0 or updated:
|
||||
return null
|
||||
|
||||
updated = true
|
||||
|
||||
var return_stack : Stack
|
||||
if extract_amount > amount:
|
||||
return_stack = Stack.new(held_item,amount)
|
||||
|
@ -48,9 +51,11 @@ func extract_stack(extract_amount: int) -> Stack:
|
|||
|
||||
## Extract entire stack from slot. Returns null if slot is empty
|
||||
func extract() -> Stack:
|
||||
if amount == 0:
|
||||
if amount == 0 or updated:
|
||||
return null
|
||||
|
||||
updated = true
|
||||
|
||||
var return_stack : Stack = Stack.new(held_item,amount)
|
||||
self.amount = 0
|
||||
|
||||
|
@ -65,6 +70,8 @@ func as_stack() -> Stack:
|
|||
return return_stack
|
||||
|
||||
func can_be_merged(item : Item) -> bool:
|
||||
if updated:
|
||||
return false
|
||||
if filter != null:
|
||||
return filter.is_equal(item)
|
||||
if amount <= 0:
|
||||
|
@ -73,12 +80,14 @@ func can_be_merged(item : Item) -> bool:
|
|||
|
||||
## Add provided stack's amount to this amount. Returns null if stack is empty or items arent matching
|
||||
func merge_stack(stack: Stack) -> bool:
|
||||
if stack == null or stack.is_valid() == false:
|
||||
if stack == null or stack.is_valid() == false or updated:
|
||||
return false
|
||||
|
||||
if filter and filter.is_equal(stack.held_item) == false:
|
||||
return false
|
||||
|
||||
updated = true
|
||||
|
||||
if held_item == null:
|
||||
held_item = stack.held_item
|
||||
amount = stack.amount
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue