diff options
Diffstat (limited to 'scripts/player.gd')
| -rw-r--r-- | scripts/player.gd | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/scripts/player.gd b/scripts/player.gd index c8c40eb..746d2d9 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -1,11 +1,15 @@ extends Node +const Items = preload("res://scripts/items.gd") +var items + var cash = 1000 setget set_cash, get_cash var storage = {} +var inventory = {} func _ready(): + self.items = Items.new() _update_funds() - _update_storage() func get_cash(): return cash @@ -14,24 +18,33 @@ func set_cash(csh): cash = csh _update_funds() -func add_item(id, item, amount): +func add_item(id, amount): if storage.has(id): storage[id] += amount else: storage[id] = amount - _update_storage() + inventory[id] = items.get(id) + _update_storage(id, storage[id]) func has_item(id, amount=1): return storage.has(id) and storage[id] >= amount +func get_item(id): + return inventory[id] + +func get_item_count(id): + return storage[id] + func remove_item(id, amount): + print("remove", id, amount) if storage.has(id) and storage[id] >= amount: storage[id] -= amount - _update_storage() + print("new amount", storage[id]) + _update_storage(id, storage[id]) func _update_funds(): get_tree().get_root().get_node("Game/HUD").set_funds(cash) -func _update_storage(): - get_tree().get_root().get_node("Game/HUD").update_storage(storage) +func _update_storage(id, amount): + get_tree().get_root().get_node("Game/HUD").update_storage(id, amount)
\ No newline at end of file |
