Attempt2/src/classes/inventory_manager.gd

60 lines
1.4 KiB
GDScript3

class_name InventoryManager
extends Resource
## Currently doing this in a weird way where the inventory items are the
## dictionary keys. This would make world inventory items ownable
## by the resourse itself. At least that's what I think. We'll see.
## I'm interested in an approach where the game world items aren't
## duplicated.
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var primary_selection: Item
var secondary_selection: Item
# count of items in dictionary value
var _items :Dictionary
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func select_primary(_item :Item) -> void:
if _items.has(_item):
primary_selection = _item
func select_secondary(_item :Item) -> void:
if _items.has(_item):
secondary_selection = _item
func add_to_inventory(_item :Item) -> int:
if _items.has(_item):
_items[_item] += 1
else:
_items[_item] = 1
return _items[_item]
func remove_from_inventory (_item :Item) -> int:
if _items.has(_item):
_items[_item] -= 1
if _items[_item] == 0:
_items.erase(_item)
return 0
else:
return _items[_item]
else:
return 0
func clear_item_from_inventory (_item :Item) -> void:
if _items.has(_item):
_items.erase(_item)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass