Hello,
I'm working on UI for my game where I load levels from the web as an array of dictionaries.
I pass the dictionaries in lots of nodes depending on context (level selection screen / level list screen / level scores screen etc.).
Here's how I do:
# Load.gd
var screen = Screen.instance()
screen.initialize(level)
add_child(screen)
# Screen.gd
func initialize(pLevel : Dictionary) -> void:
yield(self, "ready")
level = pLevel
$VBoxContainer/LevelTitleLabel.text = level["Name"]
$VBoxContainer/CreatorNameLabel.text = "By " + level["Author"]
$HBoxContainer/Stars1.set_texture(StarFull if level["Stars"] > 0 else StarEmpty)
$HBoxContainer/Stars2.set_texture(StarFull if level["Stars"] > 1 else StarEmpty)
$HBoxContainer/Stars3.set_texture(StarFull if level["Stars"] > 2 else StarEmpty)
$HBoxContainer/Stars4.set_texture(StarFull if level["Stars"] > 3 else StarEmpty)
$TimeLabel.text = Utils.format_time(level["BestTime"]/1000)
My issue is that Dictionary are pretty error-prone. I tried to convert it to a inner class but I did not succeed since we cannot share inner class (I think?) in different nodes.
What can I do to have the compiler help me with auto-completion and compilation-time exception instead of run-time exception?