1
Fork 0
mirror of https://github.com/Steffo99/pineapple-surf.git synced 2024-11-21 15:34:17 +00:00

Add wip scoreboard

This commit is contained in:
Ichicoro 2023-01-09 17:43:16 +01:00
parent 3c325c4505
commit 86cb3e407d
9 changed files with 197 additions and 24 deletions

View file

@ -2,3 +2,5 @@ extends Node
var player: Player
var username: String
var time: float = 0
var should_upload: bool = false

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=18 format=3 uid="uid://bg88gc1w1gw5m"]
[ext_resource type="PackedScene" uid="uid://dh5blytk6vmdu" path="res://island/sinking/Sea.tscn" id="1_e0hpm"]
[ext_resource type="PackedScene" path="res://player/Player.tscn" id="3_5378m"]
[ext_resource type="PackedScene" path="res://island/sinking/Sea.tscn" id="1_e0hpm"]
[ext_resource type="PackedScene" uid="uid://bbp47va0yygpw" path="res://player/Player.tscn" id="3_5378m"]
[ext_resource type="PackedScene" uid="uid://cyuqnp5bfan4y" path="res://island/IslandMesh.tscn" id="3_g5ug0"]
[ext_resource type="PackedScene" uid="uid://tahdk48hqxis" path="res://island/HillMesh.tscn" id="4_5ll24"]
[ext_resource type="PackedScene" uid="uid://cxa5irr1atgke" path="res://island/PyramidSmallMesh.tscn" id="5_uf8hd"]

View file

@ -49,6 +49,9 @@ func try_to_explode():
func win():
print("YOU WIN!")
print("Time: ", time)
Singletons.time = time
# get_tree().change_scene_to_file("res://base/BaseScene.tscn")
queue_free()

View file

@ -1,13 +1,70 @@
extends Control
signal play_pressed()
var scores_downloaded := false
var scores := [] as Array[Array]
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
var url = "https://arcade.steffo.eu/score/?board=ld52&player=%s" % Singletons.name
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 }
self.is_uploading = false
_fetch_scores(true)
httpreq.queue_free()
)
self.is_uploading = true
httpreq.request(url, [
"Content-Type: application/json"
], true, HTTPClient.METHOD_PUT, str(Singletons.time))
func _fetch_scores(open_after: bool = false):
const url = "https://arcade.steffo.eu/board/?board=ld52&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])
self.scores_downloaded = true
%ScoresButton.disabled = false
print(self.scores)
httpreq.queue_free()
)
httpreq.request(url)
func play():
print("Play button was pressed.")
emit_signal("play_pressed")
func open_scores():
$ScoreboardContainer.visible = true
func close_scores():
$ScoreboardContainer.visible = false
func _on_text_edit_text_changed():
Singletons.username = $Content/Inputs/NameInput.text
%PlayButton.disabled = false

View file

@ -1,8 +1,16 @@
[gd_scene load_steps=4 format=3 uid="uid://bufi0wh54u5x5"]
[gd_scene load_steps=7 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)
[node name="Menu" type="Control"]
texture_filter = 1
@ -67,29 +75,113 @@ placeholder_text = "What's your name?"
layout_mode = 2
size_flags_vertical = 6
[node name="Play" type="Button" parent="Content/Buttons"]
[node name="HBoxContainer" type="HBoxContainer" parent="Content/Buttons"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -18.0
offset_top = -9.0
offset_right = 18.0
offset_bottom = 9.0
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
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
size_flags_horizontal = 4
size_flags_vertical = 4
theme_override_font_sizes/font_size = 0
disabled = true
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
size_flags_horizontal = 4
size_flags_vertical = 4
theme_override_font_sizes/font_size = 0
disabled = true
text = "Scores"
[node name="Authors2" type="Label" parent="Content"]
layout_mode = 2
size_flags_vertical = 1
text = "Ludum Dare 52 - Harvest"
horizontal_alignment = 1
[node name="ScoreboardContainer" type="Control" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[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="pressed" from="Content/Buttons/Play" to="." method="play"]
[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"]

24
menu/score.tscn Normal file
View file

@ -0,0 +1,24 @@
[gd_scene format=3 uid="uid://b7h36f4ai0qmq"]
[node name="MarginContainer" type="MarginContainer"]
theme_override_constants/margin_left = 5
theme_override_constants/margin_right = 5
[node name="HBoxContainer" type="HBoxContainer" parent="."]
offset_left = 5.0
offset_right = 115.0
offset_bottom = 26.0
alignment = 1
[node name="Name" type="Label" parent="HBoxContainer"]
offset_right = 46.0
offset_bottom = 26.0
size_flags_horizontal = 2
text = "Steffo"
[node name="Score" type="Label" parent="HBoxContainer"]
offset_left = 50.0
offset_right = 110.0
offset_bottom = 26.0
size_flags_horizontal = 10
text = "1512.50"

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=3]
[gd_scene load_steps=14 format=3 uid="uid://bbp47va0yygpw"]
[ext_resource type="Script" path="res://player/Player.gd" id="1_rujcr"]
[ext_resource type="Script" path="res://player/Head.gd" id="2_ohlgu"]
@ -79,7 +79,6 @@ grow_horizontal = 2
grow_vertical = 2
[node name="CameraViewportContainer" type="SubViewportContainer" parent="Head/Viewport"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
@ -119,7 +118,6 @@ theme = SubResource("Theme_smyke")
[node name="SubViewportContainer" type="SubViewportContainer" parent="HUD"]
show_behind_parent = true
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
@ -149,7 +147,6 @@ scale = Vector2(1.65, 1)
metadata/_edit_lock_ = true
[node name="PineappleLabel" type="Label" parent="HUD"]
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
@ -164,7 +161,6 @@ text = "0 harvested"
vertical_alignment = 2
[node name="AmmoLabel" type="Label" parent="HUD"]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
@ -184,7 +180,6 @@ vertical_alignment = 2
[node name="Crosshair" type="ColorRect" parent="HUD"]
material = SubResource("ShaderMaterial_2p6rt")
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=9 format=3 uid="uid://dkkjtqeta3aul"]
[ext_resource type="PackedScene" uid="uid://bjjjpgtdtub3r" path="res://assets/peashooter/peashooter.gltf" id="1_qt7i2"]
[ext_resource type="LightmapGIData" path="res://player/onhand/peashooter_model.lmbake" id="2_iui2b"]
[ext_resource type="LightmapGIData" uid="uid://46xj1uu6nj0n" path="res://player/onhand/peashooter_model.lmbake" id="2_iui2b"]
[sub_resource type="GDScript" id="GDScript_mxvns"]
script/source = "extends Node3D
@ -16,7 +16,7 @@ func _ready() -> void:
# mat.ao_enabled = true
"
[sub_resource type="Image" id="Image_435th"]
[sub_resource type="Image" id="Image_fnu2o"]
data = {
"data": PackedByteArray(158, 191, 83, 255, 74, 102, 67, 255, 33, 63, 46, 255, 23, 42, 46, 255, 43, 35, 53, 255, 42, 44, 86, 255, 61, 78, 112, 255, 110, 168, 180, 255, 181, 211, 215, 255, 116, 109, 119, 255, 59, 58, 60, 255, 50, 47, 52, 255, 0, 0, 0, 255, 42, 26, 35, 255, 78, 27, 29, 255, 127, 49, 64, 255, 174, 105, 107, 255, 244, 247, 171, 255, 228, 177, 125, 255, 187, 117, 57, 255, 146, 76, 52, 255, 93, 64, 50, 255, 84, 59, 53, 255, 71, 42, 42, 255, 55, 36, 36, 255, 85, 205, 252, 255, 255, 255, 255, 255, 247, 168, 184, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 75, 75, 75, 255, 0, 0, 0, 0),
"format": "RGBA8",
@ -26,7 +26,7 @@ data = {
}
[sub_resource type="ImageTexture" id="ImageTexture_7gqgu"]
image = SubResource("Image_435th")
image = SubResource("Image_fnu2o")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_00xel"]
resource_local_to_scene = true