Scoreboard Part 2
This commit is contained in:
parent
7328ab1349
commit
3bcc0c1f4c
6 changed files with 43 additions and 25 deletions
|
@ -7,20 +7,26 @@ var highscore
|
||||||
var level_nr
|
var level_nr
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
score_label.set_text("%.f" % highscore)
|
score_label.set_text(Globals.config.Username)
|
||||||
|
|
||||||
func _on_sumbit_button_pressed():
|
func _on_submit_button_pressed():
|
||||||
pass #insert score sumbitting function here
|
var factory = RequestFactory.new($HTTPRequest, Globals.config.HighscoreServerAddr)
|
||||||
#then proceed to highscore screen
|
var score = Score.new(name_field.text, {"level"+str(level_nr): highscore})
|
||||||
|
factory.resolve_submit_request(func (result, response_code, h, body):
|
||||||
|
if response_code == 200:
|
||||||
|
var json = JSON.parse_string(body.get_string_from_utf8())
|
||||||
|
print(json)
|
||||||
|
var scores = load("res://src/gui/menu/scores.tscn").instantiate()
|
||||||
|
scores.scores = json
|
||||||
|
scores.level_nr = level_nr
|
||||||
|
get_parent().add_child((scores))
|
||||||
|
else:
|
||||||
|
return # TODO: Show Dialog
|
||||||
|
, score)
|
||||||
|
|
||||||
func _on_retry_button_pressed():
|
func _on_retry_button_pressed():
|
||||||
get_tree().reload_current_scene()
|
get_tree().reload_current_scene()
|
||||||
|
|
||||||
|
|
||||||
func _on_submit_button_pressed():
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
func _on_next_button_pressed():
|
func _on_next_button_pressed():
|
||||||
var next_level = level_nr + 1
|
var next_level = level_nr + 1
|
||||||
if next_level > 12:
|
if next_level > 12:
|
||||||
|
|
|
@ -127,6 +127,8 @@ size_flags_vertical = 8
|
||||||
focus_neighbor_bottom = NodePath("../StartButton")
|
focus_neighbor_bottom = NodePath("../StartButton")
|
||||||
text = "NEXT LEVEL"
|
text = "NEXT LEVEL"
|
||||||
|
|
||||||
|
[node name="HTTPRequest" type="HTTPRequest" parent="."]
|
||||||
|
|
||||||
[connection signal="pressed" from="Panel/RetryButton" to="." method="_on_retry_button_pressed"]
|
[connection signal="pressed" from="Panel/RetryButton" to="." method="_on_retry_button_pressed"]
|
||||||
[connection signal="pressed" from="Panel/SubmitButton" to="." method="_on_submit_button_pressed"]
|
[connection signal="pressed" from="Panel/SubmitButton" to="." method="_on_submit_button_pressed"]
|
||||||
[connection signal="pressed" from="Panel/NextButton" to="." method="_on_next_button_pressed"]
|
[connection signal="pressed" from="Panel/NextButton" to="." method="_on_next_button_pressed"]
|
||||||
|
|
|
@ -6,18 +6,22 @@ extends Control
|
||||||
@export var scrollboard_vbox: Control
|
@export var scrollboard_vbox: Control
|
||||||
@export var scrollboard_item: Control
|
@export var scrollboard_item: Control
|
||||||
|
|
||||||
|
var scores
|
||||||
|
var level_nr
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
level_first_selection.grab_focus()
|
level_first_selection.grab_focus()
|
||||||
scrollboard_item.hide()
|
scrollboard_item.hide()
|
||||||
|
if level_nr != null:
|
||||||
|
level_select.hide()
|
||||||
|
load_level(level_nr)
|
||||||
|
|
||||||
func _on_quit_button_pressed():
|
func _on_quit_button_pressed():
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
|
|
||||||
func _on_back_button_pressed():
|
func _on_back_button_pressed():
|
||||||
level_select.hide()
|
level_select.hide()
|
||||||
|
|
||||||
|
|
||||||
func _on_level_button_pressed(level: int):
|
func _on_level_button_pressed(level: int):
|
||||||
load_level(level)
|
load_level(level)
|
||||||
|
@ -38,8 +42,6 @@ func load_leaderboard_content(level: int):
|
||||||
children[1].text = json[k].player
|
children[1].text = json[k].player
|
||||||
children[2].text = str(json[k].score)
|
children[2].text = str(json[k].score)
|
||||||
scrollboard_vbox.add_child(node)
|
scrollboard_vbox.add_child(node)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return
|
return # TODO: Show dialog
|
||||||
# TODO: Show dialog
|
|
||||||
, "level" + str(level))
|
, "level" + str(level))
|
||||||
|
|
|
@ -298,7 +298,7 @@ grow_vertical = 0
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 8
|
size_flags_vertical = 8
|
||||||
focus_neighbor_bottom = NodePath("../StartButton")
|
focus_neighbor_bottom = NodePath("../StartButton")
|
||||||
text = "BACK"
|
text = "PLAY LEVEL"
|
||||||
|
|
||||||
[node name="BackButton" type="Button" parent="Leaderboard/BackButton"]
|
[node name="BackButton" type="Button" parent="Leaderboard/BackButton"]
|
||||||
custom_minimum_size = Vector2(120, 40)
|
custom_minimum_size = Vector2(120, 40)
|
||||||
|
@ -316,8 +316,7 @@ grow_vertical = 0
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 8
|
size_flags_vertical = 8
|
||||||
focus_neighbor_bottom = NodePath("../StartButton")
|
focus_neighbor_bottom = NodePath("../StartButton")
|
||||||
text = "NEXT
|
text = "PLAY NEXT"
|
||||||
"
|
|
||||||
|
|
||||||
[node name="BackButton" type="Button" parent="Leaderboard/BackButton/BackButton"]
|
[node name="BackButton" type="Button" parent="Leaderboard/BackButton/BackButton"]
|
||||||
custom_minimum_size = Vector2(120, 40)
|
custom_minimum_size = Vector2(120, 40)
|
||||||
|
@ -336,8 +335,7 @@ grow_vertical = 0
|
||||||
size_flags_horizontal = 4
|
size_flags_horizontal = 4
|
||||||
size_flags_vertical = 8
|
size_flags_vertical = 8
|
||||||
focus_neighbor_bottom = NodePath("../StartButton")
|
focus_neighbor_bottom = NodePath("../StartButton")
|
||||||
text = "PREVIOUS
|
text = "BACK"
|
||||||
"
|
|
||||||
|
|
||||||
[node name="Label2" type="Label" parent="Leaderboard"]
|
[node name="Label2" type="Label" parent="Leaderboard"]
|
||||||
layout_mode = 0
|
layout_mode = 0
|
||||||
|
|
|
@ -13,9 +13,8 @@ func _init(node: HTTPRequest, base_uri: String):
|
||||||
self.node = node
|
self.node = node
|
||||||
|
|
||||||
func new_submit_request(score: Score) -> ApiRequest:
|
func new_submit_request(score: Score) -> ApiRequest:
|
||||||
score.ValKey = score.valKey()
|
score.valkey = score.valKey()
|
||||||
var body = JSON.stringify(score)
|
var body = JSON.stringify(score)
|
||||||
print(body)
|
|
||||||
return ApiRequest.new(self.base_uri + "/score/submit/" + Config.ProjectName.to_lower(), self.headers, HTTPClient.METHOD_POST, body)
|
return ApiRequest.new(self.base_uri + "/score/submit/" + Config.ProjectName.to_lower(), self.headers, HTTPClient.METHOD_POST, body)
|
||||||
|
|
||||||
func new_list_request(key: String, offset: int = 0, limit: int = -1) -> ApiRequest:
|
func new_list_request(key: String, offset: int = 0, limit: int = -1) -> ApiRequest:
|
||||||
|
@ -23,6 +22,12 @@ func new_list_request(key: String, offset: int = 0, limit: int = -1) -> ApiReque
|
||||||
self.base_uri + "/score/list/" + Config.ProjectName.to_lower() + "?key=" + key + "&offset=" + str(offset) + "&limit=" + str(limit),
|
self.base_uri + "/score/list/" + Config.ProjectName.to_lower() + "?key=" + key + "&offset=" + str(offset) + "&limit=" + str(limit),
|
||||||
self.headers, HTTPClient.METHOD_GET)
|
self.headers, HTTPClient.METHOD_GET)
|
||||||
|
|
||||||
|
func resolve_submit_request(f: Callable, score: Score):
|
||||||
|
score.valkey = score.valKey()
|
||||||
|
var body = JSON.stringify(score)
|
||||||
|
self.node.request_completed.connect(f)
|
||||||
|
self.node.request(self.base_uri + "/score/submit/" + Config.ProjectName.to_lower(), headers, HTTPClient.METHOD_GET, body)
|
||||||
|
|
||||||
func resolve_list_request(f: Callable, key: String, offset: int = 0, limit: int = -1):
|
func resolve_list_request(f: Callable, key: String, offset: int = 0, limit: int = -1):
|
||||||
self.node.request_completed.connect(f)
|
self.node.request_completed.connect(f)
|
||||||
self.node.request(self.base_uri + "/score/list/" + Config.ProjectName.to_lower() + "?key=" + key + "&offset=" + str(offset) + "&limit=" + str(limit), headers, HTTPClient.METHOD_GET)
|
self.node.request(self.base_uri + "/score/list/" + Config.ProjectName.to_lower() + "?key=" + key + "&offset=" + str(offset) + "&limit=" + str(limit), headers, HTTPClient.METHOD_GET)
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
class_name Score
|
class_name Score
|
||||||
|
|
||||||
var Name: String
|
var name: String
|
||||||
var Scores: Dictionary
|
var scores: Dictionary
|
||||||
|
var valkey: String
|
||||||
|
|
||||||
|
func _init(name: String, scores: Dictionary):
|
||||||
|
self.name = name
|
||||||
|
self.scores = scores
|
||||||
|
|
||||||
func valKey() -> String:
|
func valKey() -> String:
|
||||||
var scorestr = ""
|
var scorestr = ""
|
||||||
for i in self.Scores:
|
for i in self.scores:
|
||||||
scorestr += i + self.Scores[i]
|
scorestr += i + str(self.scores[i])
|
||||||
return String(Config.ProjectName.to_lower() + self.Name + scorestr + Secrets.ValKey).sha256_text()
|
return String(Config.ProjectName.to_lower() + self.name + scorestr + Secrets.ValKey).sha256_text()
|
||||||
|
|
Loading…
Reference in a new issue