fuzzyworld

godot-shooter / asteroids / files / scenes / Scores.gd

Branch asteroids · default branch · all branches

Scores.gd

1.3 KB · history · blame

1extends VBoxContainer
2
3const Utils = preload("res://utils/Utils.gd")
4const Weapons = preload("res://weapons/Weapons.gd")
5const PowerUp = preload("res://items/PowerUp.tscn")
6const Settings = preload("res://utils/Settings.gd")
7onready var scores_list = $ScoresList
8
9func _process(_delta: float) -> void:
10 update_scores()
11 pass
12
13func update_scores() -> void:
14 Utils.remove_all_children(scores_list)
15 var settings = Utils.load_user_settings()
16 if settings.high_scores.size() > 0:
17 settings.high_scores.sort_custom(self, "sort_high_scores")
18 var now = Time.get_datetime_dict_from_system()
19 for hs in settings.high_scores:
20 var date_dict = hs.date
21 var date_diff_secs = Utils.time_diff_secs(date_dict, now)
22 var date_diff = Utils.timespan_to_english(date_diff_secs)
23 var label = Label.new()
24 label.text = " %s points, %s" % [hs.score, date_diff]
25 scores_list.add_child(label)
26 else:
27 var no_scores_label = Label.new()
28 no_scores_label.text = "No high scores yet"
29 scores_list.add_child(no_scores_label)
30# var debug_label = Label.new()
31# debug_label.text = "List populated at %s" % Time.get_datetime_string_from_system(false, true)
32# scores_list.add_child(debug_label)
33
34func sort_high_scores(a, b):
35 return (a as Settings.HighScore).score > (b as Settings.HighScore).score