40 lines
953 B
GDScript
40 lines
953 B
GDScript
# BossDatabase.gd
|
|
extends Node
|
|
|
|
var boss_data = {}
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
load_boss_data()
|
|
|
|
|
|
# Function to load character data from the JSON file
|
|
func load_boss_data():
|
|
#var file = FileAccess.open("res://Boss/bossData.json", FileAccess.READ)
|
|
var file = FileAccess.open("user://Boss/bossData.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:
|
|
boss_data = json.get_data()
|
|
print("Boss data loaded successfully.")
|
|
#print(character_data)
|
|
else:
|
|
print("Failed to parse JSON: ", json_result.error_string)
|
|
else:
|
|
print("Boss data file not found.")
|
|
|
|
|
|
# Function to get a character by name
|
|
func get_boss(name: String) -> Dictionary:
|
|
for boss in boss_data.bosses:
|
|
if boss.name == name:
|
|
return boss
|
|
return {}
|