From 0f0b7a00af4193e4f45e67410e75439ce924b8f1 Mon Sep 17 00:00:00 2001 From: Ichicoro Date: Mon, 9 Jan 2023 17:59:08 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Improve=20code=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- menu/Menu.gd | 14 ++++++++++++++ menu/Menu.tscn | 1 + 2 files changed, 15 insertions(+) diff --git a/menu/Menu.gd b/menu/Menu.gd index a68d887..bd26836 100644 --- a/menu/Menu.gd +++ b/menu/Menu.gd @@ -5,6 +5,8 @@ signal play_pressed() var scores_downloaded := false var scores := [] as Array[Array] +var score_scene := preload("res://menu/score.tscn") + var is_uploading := false var should_open_scores_after_upload := false @@ -45,9 +47,21 @@ func _fetch_scores(open_after: bool = false): httpreq.connect("request_completed", func(result, response_code, headers, body): var json = JSON.parse_string(body.get_string_from_utf8()) self.scores = (json as Array).map(func(element): return [element.name, element.score]) + + for child in %ScoresVBox.get_children(): + child.queue_free() + + for score in self.scores: + var score_sc = score_scene.instantiate() + score_sc.get_node("HBoxContainer/Name").text = score[0] + score_sc.get_node("HBoxContainer/Score").text = "%d" % score[1] + %ScoresVBox.add_child(score_sc) + self.scores_downloaded = true %ScoresButton.disabled = false print(self.scores) + if open_after: + open_scores() httpreq.queue_free() ) httpreq.request(url) diff --git a/menu/Menu.tscn b/menu/Menu.tscn index a0a7f45..731cdc0 100644 --- a/menu/Menu.tscn +++ b/menu/Menu.tscn @@ -111,6 +111,7 @@ text = "Ludum Dare 52 - Harvest" horizontal_alignment = 1 [node name="ScoreboardContainer" type="Control" parent="."] +visible = false layout_mode = 1 anchors_preset = 15 anchor_right = 1.0