Item get event
This commit is contained in:
@@ -19,8 +19,8 @@ const ITEM_STACK_SIZE_MAX = 99;
|
||||
|
||||
var contents:Array[ItemStack] = [];
|
||||
|
||||
func addItem(item: Item, quantity: int = 1) -> void:
|
||||
if !item.isStackable():
|
||||
func addItem(item:Item.ItemType, quantity: int = 1) -> void:
|
||||
if !Item.isStackable(item):
|
||||
# Item cannot be stacked, add each item to inv
|
||||
for i in range(quantity):
|
||||
contents.append(ItemStack.new(item, 1))
|
||||
@@ -46,7 +46,7 @@ func addItem(item: Item, quantity: int = 1) -> void:
|
||||
contents.append(ItemStack.new(item, newStackQuantity));
|
||||
quantity -= newStackQuantity;
|
||||
|
||||
func removeItem(item: Item, quantity: int) -> void:
|
||||
func removeItem(item:Item.ItemType, quantity:int) -> void:
|
||||
var totalQuantity = 0
|
||||
|
||||
# Calculate total quantity of the item in the inventory
|
||||
@@ -78,7 +78,7 @@ func removeItem(item: Item, quantity: int) -> void:
|
||||
func removeStack(stack: ItemStack) -> void:
|
||||
self.removeItem(stack.item, stack.quantity);
|
||||
|
||||
func hasItem(item: Item, quantity: int = 1) -> bool:
|
||||
func hasItem(item:Item.ItemType, quantity: int = 1) -> bool:
|
||||
var totalQuantity = 0
|
||||
|
||||
for stack in contents:
|
||||
|
@@ -11,6 +11,11 @@ enum ItemCategory {
|
||||
INGREDIENT
|
||||
};
|
||||
|
||||
static func isStackable(itemType:ItemType) -> bool:
|
||||
match itemType:
|
||||
_:
|
||||
return true
|
||||
|
||||
# func getName() -> String:
|
||||
# push_error("getName() must be overridden in derived classes");
|
||||
# return "";
|
||||
|
@@ -1,8 +1,8 @@
|
||||
class_name ItemStack
|
||||
|
||||
var item:Item;
|
||||
var item:Item.ItemType;
|
||||
var quantity:int;
|
||||
|
||||
func _init(item:Item, quantity:int = 1):
|
||||
func _init(item:Item.ItemType, quantity:int = 1):
|
||||
self.item = item;
|
||||
self.quantity = quantity;
|
||||
|
Reference in New Issue
Block a user