Initial commit

This commit is contained in:
2024-02-08 22:16:58 +01:00
commit 89e97a200c
524 changed files with 15626 additions and 0 deletions

45
singletons/Inventory.gd Normal file
View File

@@ -0,0 +1,45 @@
extends Node
"""
Minimal inventory system implementation.
It's just a dictionary where items are identified by a string key and hold an int amount
"""
# action can be 'added' some amount of some items is added and 'removed' when some amount
# of some item is removed
signal item_changed(action, type, amount)
var inventory = {}
func get_item(type:String) -> int:
if inventory.has(type):
return inventory[type]
else:
return 0
func add_item(type:String, amount:int) -> bool:
if inventory.has(type):
inventory[type] += amount
emit_signal("item_changed", "added", type, amount)
return true
else:
inventory[type] = amount
emit_signal("item_changed", "added", type, amount)
return true
func remove_item(type:String, amount:int) -> bool:
if inventory.has(type) and inventory[type] >= amount:
inventory[type] -= amount
if inventory[type] == 0:
inventory.erase(type)
emit_signal("item_changed", "removed", type, amount)
return true
else:
return false
func list() -> Dictionary:
return inventory.duplicate()