godot-shooter / files / scenes / Scores.gd
Scores.gd
a2c95335 2023-11-29 Pavel Safronov | 1 | extends VBoxContainer |
| 2 | ||
| 3 | const Utils = preload("res://utils/Utils.gd") | |
| 4 | const Weapons = preload("res://weapons/Weapons.gd") | |
| 5 | const PowerUp = preload("res://items/PowerUp.tscn") | |
| 6 | const Settings = preload("res://utils/Settings.gd") | |
| 7 | onready var scores_list = $ScoresList | |
| 8 | ||
176d22db 2023-12-01 Pavel Safronov | 9 | func _process(_delta: float) -> void: |
| 10 | update_scores() | |
| 11 | pass | |
| 12 | ||
| 13 | func update_scores() -> void: | |
| 14 | Utils.remove_all_children(scores_list) | |
a2c95335 2023-11-29 Pavel Safronov | 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) | |
176d22db 2023-12-01 Pavel Safronov | 23 | var label = Label.new() |
a2c95335 2023-11-29 Pavel Safronov | 24 | label.text = " %s points, %s" % [hs.score, date_diff] |
| 25 | scores_list.add_child(label) | |
176d22db 2023-12-01 Pavel Safronov | 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) | |
a2c95335 2023-11-29 Pavel Safronov | 33 | |
| 34 | func sort_high_scores(a, b): | |
| 35 | return (a as Settings.HighScore).score > (b as Settings.HighScore).score |