Skip to content

Commit

Permalink
Merge pull request #197 from Tom3s/load-placement-in-medal-menu
Browse files Browse the repository at this point in the history
[#196] Show Placement after completing runs
  • Loading branch information
Tom3s authored Jan 30, 2024
2 parents 5bc0ba4 + 42d1e61 commit 4b9c928
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 5 deletions.
1 change: 1 addition & 0 deletions GameScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func setup(
map.bestLapTime,
totalTimePB,
lapTimePB,
map.trackId
)

%GameEventListener.replayGhost.setTimeMultiplier(timeMultiplier)
Expand Down
2 changes: 2 additions & 0 deletions GameScene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ visible = false
[node name="IngameMedalMenu" parent="UniversalCanvas" instance=ExtResource("6_64ltm")]
unique_name_in_owner = true
visible = false
currentTime = null
currentLap = null

[node name="RaceInputHandler" type="Node3D" parent="."]
unique_name_in_owner = true
Expand Down
33 changes: 33 additions & 0 deletions Global/RequestHandler.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
extends Node

func sendRequest(
requesterNodeName: String,
requestUrl: String,
headers: Array,
method: int,
payload: String,
timeout: float,
onRequestSuccess: Callable,
) -> void:
var request = HTTPRequest.new()
add_child(request)
request.timeout = timeout

request.request_completed.connect(func(_result, response_code, _headers, _body):
if response_code != 200:
print("[" + requesterNodeName + "'s request] Error with response: " + _body.get_string_from_utf8())
return
onRequestSuccess.call(_body)
)

headers.append("Content-Type: application/json")

var httpError = request.request(
requestUrl,
headers,
method,
payload
)

if httpError != OK:
print("[" + requesterNodeName + "'s request] Error while sending request: " + error_string(httpError))
2 changes: 1 addition & 1 deletion Global/VersionCheck.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends Control

var offline = true

var currentVersion = "v1.2.0"
var currentVersion = "v1.2.1"

var versionCheckComplete = false

Expand Down
43 changes: 40 additions & 3 deletions Menu/IngameMedalMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ var currentTime: int = 0
@export
var currentLap: int = 0

var trackId: String = ""

signal closePressed()
signal restartPressed()
signal leaderboardPressed()
Expand Down Expand Up @@ -154,11 +156,18 @@ func _ready():

set_physics_process(true)

func setup(initChronoTime: int, initBlitzTime: int, initTotalTimePB: int, initLapTimePB: int) -> void:
func setup(
initChronoTime: int,
initBlitzTime: int,
initTotalTimePB: int,
initLapTimePB: int,
initTrackId: String
) -> void:
chronoTime = initChronoTime
blitzTime = initBlitzTime
totalTimePB = initTotalTimePB
lapTimePB = initLapTimePB
trackId = initTrackId

totalPBContainer.visible = false
totalBeatenContainer.visible = false
Expand Down Expand Up @@ -190,6 +199,21 @@ signal totalLabelAnimationFinished()
var inLabelAnimation: bool = false

func setTotalTimePB(time: int) -> void:
RequestHandler.sendRequest(
"IngameMedalMenu.gd",
Backend.BACKEND_IP_ADRESS + "/api/leaderboard/placement/" + trackId,
[
'Session-Token: ' + GlobalProperties.SESSION_TOKEN,
],
HTTPClient.METHOD_GET,
"",
5,
func(body: PackedByteArray) -> void:
totalPlacement.text = body.get_string_from_utf8()
)

totalPlacementContainer.modulate = Color(1, 1, 1, 0)

var tween = create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_EXPO)

if totalTimePB == 9223372036854775807 || time <= totalTimePB:
Expand Down Expand Up @@ -313,7 +337,6 @@ func setTotalTimePB(time: int) -> void:
totalNextMedal.text = IngameHUD.getTimeStringFromTicks(floori(chronoTime * MedalMenu.BRONZE_MULTIPLIER))
totalNextDiff.text = IngameHUD.getTimeStringFromTicks(time - floori(chronoTime * MedalMenu.BRONZE_MULTIPLIER))

totalPlacementContainer.modulate = Color(1, 1, 1, 0)
inLabelAnimation = true
tween.tween_property(totalPlacementContainer, "modulate", Color(1, 1, 1, 1), LABEL_ANIMATION_TIME)
tween.tween_callback(playClickSFX)
Expand Down Expand Up @@ -387,6 +410,21 @@ func animateInTotalMedals(nrMedals: int) -> void:


func setLapTimePB(time: int) -> void:
RequestHandler.sendRequest(
"IngameMedalMenu.gd",
Backend.BACKEND_IP_ADRESS + "/api/leaderboard/placement/" + trackId + "?sortByLap=true",
[
'Session-Token: ' + GlobalProperties.SESSION_TOKEN,
],
HTTPClient.METHOD_GET,
"",
5,
func(body: PackedByteArray) -> void:
lapPlacement.text = body.get_string_from_utf8()
)

lapPlacementContainer.modulate = Color(1, 1, 1, 0)

var tween = create_tween().set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_EXPO)

if inLabelAnimation:
Expand Down Expand Up @@ -495,7 +533,6 @@ func setLapTimePB(time: int) -> void:
lapNextMedal.text = IngameHUD.getTimeStringFromTicks(floori(blitzTime * MedalMenu.BRONZE_MULTIPLIER))
lapNextDiff.text = IngameHUD.getTimeStringFromTicks(time - floori(blitzTime * MedalMenu.BRONZE_MULTIPLIER))

lapPlacementContainer.modulate = Color(1, 1, 1, 0)
tween.tween_property(lapPlacementContainer, "modulate", Color(1, 1, 1, 1), LABEL_ANIMATION_TIME)
tween.tween_callback(playClickSFX)

Expand Down
2 changes: 2 additions & 0 deletions Menu/IngameMedalMenu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_otuec")
currentTime = null
currentLap = null

[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
Expand Down
2 changes: 1 addition & 1 deletion Menu/MapOverviewMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func fetchPersonalBestLap():
)

var httpError = request.request(
Backend.BACKEND_IP_ADRESS + "/api/leaderboard/pb/" + trackId + "?bestLap=true",
Backend.BACKEND_IP_ADRESS + "/api/leaderboard/pb/" + trackId + "?sortByLap=true",
[
"Content-Type: application/json",
"Session-Token: " + GlobalProperties.SESSION_TOKEN
Expand Down
1 change: 1 addition & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Leaderboard="*res://Global/Leaderboard.gd"
AlertManager="*res://Global/AlertManager.gd"
VersionCheck="*res://Global/VersionCheck.gd"
BillboardTextureLoader="*res://Global/BillboardTextureLoader.gd"
RequestHandler="*res://Global/RequestHandler.gd"

[debug]

Expand Down

0 comments on commit 4b9c928

Please sign in to comment.