1
Fork 0
mirror of https://github.com/Steffo99/pineapple-surf.git synced 2024-11-21 23:34:21 +00:00
This commit is contained in:
Steffo 2023-01-09 21:01:41 +01:00
parent d839cb02d3
commit 56c60c6072
Signed by: steffo
GPG key ID: 2A24051445686895
8 changed files with 100 additions and 94 deletions

View file

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

View file

@ -1,6 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://cj86x6gplsbrb"]
[gd_scene load_steps=3 format=3 uid="uid://cj86x6gplsbrb"]
[ext_resource type="Script" path="res://base/BaseScene.gd" id="1_n2o7j"]
[ext_resource type="PackedScene" uid="uid://tmxndy6x0u3l" path="res://menu/ScoreboardContainer.tscn" id="2_tjx6n"]
[node name="BaseScene" type="Node"]
script = ExtResource("1_n2o7j")
[node name="ScoreboardContainer" parent="." instance=ExtResource("2_tjx6n")]

View file

@ -7,7 +7,7 @@ var is_exploded: bool = false
@export var size_per_prayer: float = 0.05
@export var pitch_per_prayer: float = 0.02
@export var explode_at: int = 150
@export var explode_at: int = 1
@export var explosion_scene: PackedScene = preload("res://island/FunnyExplosion.tscn")
@onready var player: Player = Singletons.player
@ -49,11 +49,7 @@ func try_to_explode():
func win():
print("YOU WIN!")
print("Time: ", time)
Singletons.should_upload = true
Singletons.time = time
$"/root/BaseScene".move_to_menu()
# get_tree().change_scene_to_file("res://base/BaseScene.tscn")
$"/root/BaseScene/ScoreboardContainer".upload_score(time)
queue_free()

View file

@ -2,73 +2,6 @@ extends Control
signal play_pressed()
var scores_downloaded := false
var scores := [] as Array[Array]
var score_scene := preload("res://menu/score.tscn")
var is_uploading := false
func _ready() -> void:
if Singletons.should_upload:
# do request...
_upload_score()
_fetch_scores()
func _upload_score():
Singletons.should_upload = false
var url = "https://arcade.steffo.eu/score/?board=ld52&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",
"Accept: application/json",
"Authorization: Bearer pineapples-everywhere"
], 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=50"
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 $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 = "%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:
$ScoreboardContainer.show_scores()
httpreq.queue_free()
)
httpreq.request(url)
func play():
print("Player ", Singletons.username, " started playing!")
@ -78,3 +11,12 @@ func play():
func _on_name_input_text_changed():
Singletons.username = $Content/Inputs/NameInput.text
%PlayButton.disabled = false
func _on_fetched_scores():
$Content/Buttons/HBoxContainer/ScoresButton.disabled = false
$Content/Buttons/HBoxContainer/ScoresButton.connect("pressed", $"/root/BaseScene/ScoreboardContainer".show_scores)
func _ready():
$"/root/BaseScene/ScoreboardContainer".connect("fetched_scores", _on_fetched_scores)

View file

@ -1,9 +1,8 @@
[gd_scene load_steps=5 format=3 uid="uid://bufi0wh54u5x5"]
[gd_scene load_steps=4 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://tmxndy6x0u3l" path="res://menu/ScoreboardContainer.tscn" id="4_6ss1l"]
[node name="Menu" type="Control"]
texture_filter = 1
@ -88,7 +87,6 @@ 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
@ -103,9 +101,5 @@ size_flags_vertical = 1
text = "Ludum Dare 52 - Harvest"
horizontal_alignment = 1
[node name="ScoreboardContainer" parent="." instance=ExtResource("4_6ss1l")]
layout_mode = 1
[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="ScoreboardContainer" method="show_scores"]

View file

@ -1,9 +1,80 @@
extends Control
var scores_downloaded := false
var scores := [] as Array[Array]
var score_scene := preload("res://menu/score.tscn")
var is_uploading := false
var prev_mouse_mode := Input.MOUSE_MODE_VISIBLE
signal fetched_scores()
func _ready() -> void:
_fetch_scores()
func upload_score(score: float):
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",
"Accept: application/json",
"Authorization: Bearer hahaha-ronaldinho-soccer"
], true, HTTPClient.METHOD_PUT, str(score))
_fetch_scores(true)
func _fetch_scores(open_after: bool = false):
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 $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 = "%0.3f s" % score[1]
$Panel/VBoxContainer/ScrollContainer/ScoresVBox.add_child(score_sc)
self.scores_downloaded = true
print(self.scores)
emit_signal("fetched_scores")
if open_after:
show_scores()
httpreq.queue_free()
)
httpreq.request(url)
func show_scores():
prev_mouse_mode = Input.mouse_mode
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
visible = true
func hide_scores():
Input.set_mouse_mode(prev_mouse_mode)
visible = false

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://tmxndy6x0u3l"]
[gd_scene load_steps=6 format=3 uid="uid://tmxndy6x0u3l"]
[ext_resource type="PackedScene" uid="uid://b7h36f4ai0qmq" path="res://menu/score.tscn" id="1_a00v5"]
[ext_resource type="Theme" uid="uid://c5a1nyqumj46j" path="res://menu/menu_theme.tres" id="1_pm2j4"]
[ext_resource type="Script" path="res://menu/ScoreboardContainer.gd" id="1_rc765"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_uie3v"]
@ -12,12 +13,15 @@ shadow_color = Color(0, 0, 0, 0.431373)
[node name="ScoreboardContainer" type="Control"]
visible = false
z_index = 4096
z_as_relative = false
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_pm2j4")
script = ExtResource("1_rc765")
[node name="ColorRect" type="ColorRect" parent="."]
@ -58,8 +62,8 @@ horizontal_alignment = 1
size_flags_vertical = 3
[node name="ScoresVBox" type="VBoxContainer" parent="Panel/VBoxContainer/ScrollContainer"]
offset_right = 120.0
offset_bottom = 26.0
offset_right = 100.0
offset_bottom = 18.0
size_flags_horizontal = 3
size_flags_vertical = 0
@ -70,6 +74,9 @@ theme_override_constants/margin_bottom = 2
[node name="closebtn" type="Button" parent="Panel/VBoxContainer/MarginContainer"]
custom_minimum_size = Vector2(52, 2.08165e-12)
offset_top = 6.0
offset_right = 52.0
offset_bottom = 24.0
size_flags_horizontal = 4
size_flags_vertical = 4
theme_override_font_sizes/font_size = 0

View file

@ -5,20 +5,15 @@ 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
layout_mode = 2
alignment = 1
[node name="Name" type="Label" parent="HBoxContainer"]
offset_right = 46.0
offset_bottom = 26.0
layout_mode = 2
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
layout_mode = 2
size_flags_horizontal = 10
text = "1512.50"