class_name ItemSystem extends Node const Inventory = preload("res://scripts/Item/Inventory.gd") static var PLAYER_INVENTORY = Inventory.new(); static var ITEM_MAP:Dictionary[Item.Type,Item] func _addItemRecursively(node:Node) -> void: if node is Item: if ITEM_MAP.has(node.type): assert(false, "Duplicate item type found: " + str(node.type)) ITEM_MAP[node.type] = node for childIndex in node.get_child_count(): _addItemRecursively(node.get_child(childIndex)) func _enter_tree() -> void: # Add all items ITEM_MAP = {} _addItemRecursively(self) # Check if we are missing any item types. for itemType in Item.Type.values(): if !ITEM_MAP.has(itemType): assert(false, "Missing item type: " + Item.Type.find_key(itemType)) func getItem(type:Item.Type) -> Item: if !ITEM_MAP.has(type): assert(false, "Item type not found: " + Item.Type.find_key(type)) return null return ITEM_MAP[type] func isStackable(itemType:Item.Type) -> bool: return getItem(itemType).stackable func getItemName(itemType:Item.Type, count:int = 1) -> String: var item = getItem(itemType) return tr_n(item.title, item.title + "_plural", count).format({ "count": count }) func getItemDescription(itemType:Item.Type) -> String: return getItem(itemType).description_text func getItemCategory(itemType:Item.Type) -> Item.Category: return getItem(itemType).category