# CharacterDatabase.gd
# CharacterDatabase.gd
extends Node

var character_data = {}

# Called when the node enters the scene tree for the first time.
func _ready():
	load_character_data()


# Function to load character data from the JSON file
func load_character_data():
	
	#If using json
	var file = FileAccess.open("user://MemberDatabase/memberData.json", FileAccess.READ)
	#var file = FileAccess.open("user://memberData.json", FileAccess.READ)
	if file:
		var json_text = file.get_as_text()
		#print (json_text)
		file.close()

		var json = JSON.new()
		var json_result = json.parse(json_text)
		#print (json_result)
		
		if json_result == OK:
			character_data = json.get_data()
			print("Character data loaded successfully.")
			#print(character_data)
		else:
			print("Failed to parse JSON: ", json_result.error_string)
	else:
		print("Character data file not found.")


# Function to get a character by name
func get_character(name: String) -> Dictionary:
	for character in character_data.members:
		if character.name == name:
			return character
	return {}

