mirror of
https://github.com/Steffo99/pineapple-surf.git
synced 2024-11-21 15:34:17 +00:00
Scoreboards work (change url before deploy)
This commit is contained in:
parent
0f0b7a00af
commit
cd25d45031
5 changed files with 141 additions and 114 deletions
|
@ -36,6 +36,7 @@ func move_to_island():
|
|||
func move_to_menu():
|
||||
print("Going to the menu...")
|
||||
emit_signal("moving_to_menu")
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
current_scene = load("res://menu/Menu.tscn").instantiate()
|
||||
current_scene.connect("play_pressed", move_to_island)
|
||||
emit_signal("moved_to_menu")
|
||||
|
|
36
menu/Menu.gd
36
menu/Menu.gd
|
@ -8,77 +8,73 @@ var scores := [] as Array[Array]
|
|||
var score_scene := preload("res://menu/score.tscn")
|
||||
|
||||
var is_uploading := false
|
||||
var should_open_scores_after_upload := false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if Singletons.should_upload:
|
||||
# do request...
|
||||
_upload_score()
|
||||
self.should_open_scores_after_upload = true
|
||||
_fetch_scores()
|
||||
|
||||
|
||||
func _upload_score():
|
||||
if not (Singletons.should_upload and len(Singletons.name) > 0 and Singletons.time):
|
||||
return
|
||||
Singletons.should_upload = false
|
||||
|
||||
var url = "https://arcade.steffo.eu/score/?board=ld52&player=%s" % Singletons.name
|
||||
var url = "https://arcade.steffo.eu/score/?board=test&player=%s" % Singletons.username
|
||||
|
||||
var httpreq = HTTPRequest.new()
|
||||
add_child(httpreq)
|
||||
httpreq.connect("request_completed", func(result, response_code, headers, body):
|
||||
var json = JSON.parse_string(body.get_string_from_utf8())
|
||||
# { score, rank }
|
||||
print(json)
|
||||
self.is_uploading = false
|
||||
_fetch_scores(true)
|
||||
httpreq.queue_free()
|
||||
)
|
||||
self.is_uploading = true
|
||||
httpreq.request(url, [
|
||||
"Content-Type: application/json"
|
||||
"Content-Type: application/json",
|
||||
"Accept: application/json",
|
||||
"Authorization: Bearer hahaha-ronaldinho-soccer"
|
||||
], true, HTTPClient.METHOD_PUT, str(Singletons.time))
|
||||
|
||||
_fetch_scores(true)
|
||||
|
||||
|
||||
func _fetch_scores(open_after: bool = false):
|
||||
const url = "https://arcade.steffo.eu/board/?board=ld52&offset=0&size=10"
|
||||
const url = "https://arcade.steffo.eu/board/?board=test&offset=0&size=10"
|
||||
var httpreq = HTTPRequest.new()
|
||||
add_child(httpreq)
|
||||
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():
|
||||
for child in $ScoreboardContainer/Panel/VBoxContainer/ScrollContainer/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)
|
||||
score_sc.get_node("HBoxContainer/Score").text = "%0.3f s" % score[1]
|
||||
$ScoreboardContainer/Panel/VBoxContainer/ScrollContainer/ScoresVBox.add_child(score_sc)
|
||||
|
||||
self.scores_downloaded = true
|
||||
%ScoresButton.disabled = false
|
||||
print(self.scores)
|
||||
if open_after:
|
||||
open_scores()
|
||||
$ScoreboardContainer.show_scores()
|
||||
|
||||
httpreq.queue_free()
|
||||
)
|
||||
httpreq.request(url)
|
||||
|
||||
|
||||
func play():
|
||||
print("Play button was pressed.")
|
||||
print("Player ", Singletons.username, " started playing!")
|
||||
emit_signal("play_pressed")
|
||||
|
||||
|
||||
func open_scores():
|
||||
$ScoreboardContainer.visible = true
|
||||
|
||||
func close_scores():
|
||||
$ScoreboardContainer.visible = false
|
||||
|
||||
|
||||
func _on_text_edit_text_changed():
|
||||
func _on_name_input_text_changed():
|
||||
Singletons.username = $Content/Inputs/NameInput.text
|
||||
%PlayButton.disabled = false
|
||||
|
|
124
menu/Menu.tscn
124
menu/Menu.tscn
|
@ -1,16 +1,9 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://bufi0wh54u5x5"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://bufi0wh54u5x5"]
|
||||
|
||||
[ext_resource type="Theme" uid="uid://c5a1nyqumj46j" path="res://menu/menu_theme.tres" id="1_mkxnc"]
|
||||
[ext_resource type="Script" path="res://menu/Menu.gd" id="2_6amk3"]
|
||||
[ext_resource type="Texture2D" uid="uid://bxyximtgui1ux" path="res://assets/grass_menu_tile.png" id="2_q14jx"]
|
||||
[ext_resource type="PackedScene" uid="uid://b7h36f4ai0qmq" path="res://menu/score.tscn" id="4_ec4at"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_uie3v"]
|
||||
bg_color = Color(0.184314, 0.341176, 0.32549, 1)
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_xmwgs"]
|
||||
shadow_size = 0
|
||||
shadow_color = Color(0, 0, 0, 0.431373)
|
||||
[ext_resource type="PackedScene" uid="uid://tmxndy6x0u3l" path="res://menu/ScoreboardContainer.tscn" id="4_6ss1l"]
|
||||
|
||||
[node name="Menu" type="Control"]
|
||||
texture_filter = 1
|
||||
|
@ -25,7 +18,6 @@ theme = ExtResource("1_mkxnc")
|
|||
script = ExtResource("2_6amk3")
|
||||
|
||||
[node name="Panel" type="TextureRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
@ -35,7 +27,6 @@ texture = ExtResource("2_q14jx")
|
|||
stretch_mode = 1
|
||||
|
||||
[node name="Content" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
@ -44,25 +35,32 @@ grow_vertical = 2
|
|||
alignment = 1
|
||||
|
||||
[node name="Authors" type="Label" parent="Content"]
|
||||
layout_mode = 2
|
||||
offset_right = 284.0
|
||||
offset_bottom = 18.0
|
||||
text = "A game by Ichicoro and Steffo"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Title" type="Label" parent="Content"]
|
||||
layout_mode = 2
|
||||
offset_top = 22.0
|
||||
offset_right = 284.0
|
||||
offset_bottom = 72.0
|
||||
size_flags_vertical = 6
|
||||
theme_override_font_sizes/font_size = 48
|
||||
text = "Harvest"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Inputs" type="Control" parent="Content"]
|
||||
layout_mode = 2
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_left = 142.0
|
||||
offset_top = 90.0
|
||||
offset_right = 142.0
|
||||
offset_bottom = 90.0
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 6
|
||||
|
||||
[node name="NameInput" type="TextEdit" parent="Content/Inputs"]
|
||||
custom_minimum_size = Vector2(140, 28)
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
@ -72,11 +70,14 @@ size_flags_vertical = 6
|
|||
placeholder_text = "What's your name?"
|
||||
|
||||
[node name="Buttons" type="Control" parent="Content"]
|
||||
layout_mode = 2
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_top = 123.0
|
||||
offset_right = 284.0
|
||||
offset_bottom = 123.0
|
||||
size_flags_vertical = 6
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Content/Buttons"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
@ -87,7 +88,9 @@ alignment = 1
|
|||
[node name="PlayButton" type="Button" parent="Content/Buttons/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(36, 2.08165e-12)
|
||||
layout_mode = 2
|
||||
offset_left = 96.0
|
||||
offset_right = 132.0
|
||||
offset_bottom = 18.0
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
theme_override_font_sizes/font_size = 0
|
||||
|
@ -97,7 +100,9 @@ text = "Play"
|
|||
[node name="ScoresButton" type="Button" parent="Content/Buttons/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(52, 2.08165e-12)
|
||||
layout_mode = 2
|
||||
offset_left = 136.0
|
||||
offset_right = 188.0
|
||||
offset_bottom = 18.0
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
theme_override_font_sizes/font_size = 0
|
||||
|
@ -105,84 +110,15 @@ disabled = true
|
|||
text = "Scores"
|
||||
|
||||
[node name="Authors2" type="Label" parent="Content"]
|
||||
layout_mode = 2
|
||||
offset_top = 142.0
|
||||
offset_right = 284.0
|
||||
offset_bottom = 160.0
|
||||
size_flags_vertical = 1
|
||||
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
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
[node name="ScoreboardContainer" parent="." instance=ExtResource("4_6ss1l")]
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="ScoreboardContainer"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0, 0, 0, 0.635294)
|
||||
|
||||
[node name="Panel" type="Panel" parent="ScoreboardContainer"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -97.0
|
||||
offset_top = -67.0
|
||||
offset_right = 97.0
|
||||
offset_bottom = 67.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_uie3v")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="ScoreboardContainer/Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Authors" type="Label" parent="ScoreboardContainer/Panel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Scores"
|
||||
label_settings = SubResource("LabelSettings_xmwgs")
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="ScoreboardContainer/Panel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="ScoresVBox" type="VBoxContainer" parent="ScoreboardContainer/Panel/VBoxContainer/ScrollContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 0
|
||||
|
||||
[node name="score" parent="ScoreboardContainer/Panel/VBoxContainer/ScrollContainer/ScoresVBox" instance=ExtResource("4_ec4at")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="ScoreboardContainer/Panel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_bottom = 2
|
||||
|
||||
[node name="closebtn" type="Button" parent="ScoreboardContainer/Panel/VBoxContainer/MarginContainer"]
|
||||
custom_minimum_size = Vector2(52, 2.08165e-12)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
theme_override_font_sizes/font_size = 0
|
||||
text = "Close"
|
||||
|
||||
[connection signal="text_changed" from="Content/Inputs/NameInput" to="." method="_on_text_edit_text_changed"]
|
||||
[connection signal="text_changed" from="Content/Inputs/NameInput" to="." method="_on_name_input_text_changed"]
|
||||
[connection signal="pressed" from="Content/Buttons/HBoxContainer/PlayButton" to="." method="play"]
|
||||
[connection signal="pressed" from="Content/Buttons/HBoxContainer/ScoresButton" to="." method="open_scores"]
|
||||
[connection signal="pressed" from="ScoreboardContainer/Panel/VBoxContainer/MarginContainer/closebtn" to="." method="close_scores"]
|
||||
[connection signal="pressed" from="Content/Buttons/HBoxContainer/ScoresButton" to="ScoreboardContainer" method="show_scores"]
|
||||
|
|
9
menu/ScoreboardContainer.gd
Normal file
9
menu/ScoreboardContainer.gd
Normal file
|
@ -0,0 +1,9 @@
|
|||
extends Control
|
||||
|
||||
|
||||
func show_scores():
|
||||
visible = true
|
||||
|
||||
|
||||
func hide_scores():
|
||||
visible = false
|
85
menu/ScoreboardContainer.tscn
Normal file
85
menu/ScoreboardContainer.tscn
Normal file
|
@ -0,0 +1,85 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://tmxndy6x0u3l"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b7h36f4ai0qmq" path="res://menu/score.tscn" id="1_a00v5"]
|
||||
[ext_resource type="Script" path="res://menu/ScoreboardContainer.gd" id="1_rc765"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_uie3v"]
|
||||
bg_color = Color(0.184314, 0.341176, 0.32549, 1)
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_xmwgs"]
|
||||
shadow_size = 0
|
||||
shadow_color = Color(0, 0, 0, 0.431373)
|
||||
|
||||
[node name="ScoreboardContainer" type="Control"]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_rc765")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0, 0, 0, 0.635294)
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -97.0
|
||||
offset_top = -67.0
|
||||
offset_right = 97.0
|
||||
offset_bottom = 67.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_uie3v")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Authors" type="Label" parent="Panel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Scores"
|
||||
label_settings = SubResource("LabelSettings_xmwgs")
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="Panel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="ScoresVBox" type="VBoxContainer" parent="Panel/VBoxContainer/ScrollContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 0
|
||||
|
||||
[node name="score" parent="Panel/VBoxContainer/ScrollContainer/ScoresVBox" instance=ExtResource("1_a00v5")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Panel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_bottom = 2
|
||||
|
||||
[node name="closebtn" type="Button" parent="Panel/VBoxContainer/MarginContainer"]
|
||||
custom_minimum_size = Vector2(52, 2.08165e-12)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
theme_override_font_sizes/font_size = 0
|
||||
text = "Close"
|
||||
|
||||
[connection signal="pressed" from="Panel/VBoxContainer/MarginContainer/closebtn" to="." method="hide_scores"]
|
Loading…
Reference in a new issue