-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathList.gd
103 lines (80 loc) · 2.56 KB
/
List.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
extends Control
var totalTimes = []
var bestLaps = []
func onVisibilityChanged() -> bool:
var newValue = visible
if newValue:
refreshLists()
timer.paused = !newValue
return newValue
func fetchBestTotalTimes():
Leaderboard.getScoresTotalTimes(onGetScoresTotalTimes_completed)
func fetchBestLaps():
Leaderboard.getScoresBestLaps(onGetScoresBestLaps_completed)
func onGetScoresTotalTimes_completed(_result, _response_code, _headers, body):
var json = JSON.parse_string(body.get_string_from_utf8())
if json == null:
fetchBestTotalTimes()
return
var result = json["dreamlo"]["leaderboard"]["entry"]
if result is Array:
totalTimes = result
else:
totalTimes = [result]
var totalTimesList: ItemList = %TotalTimesList
totalTimesList.clear()
var placement = 1
for entry in totalTimes:
# entry = entry["entry"]
var playerName = entry["name"]
var score = get_time_string_from_ticks(-(entry["score"]).to_int())
var date = entry["date"].split(" ")[0]
var row = str(placement) + "." + playerName + " - " + score + " - " + date
if entry["text"] != "":
row += " (" + entry["text"] + ")"
totalTimesList.add_item(row, null, false)
placement += 1
func onGetScoresBestLaps_completed(_result, _response_code, _headers, body):
var json = JSON.parse_string(body.get_string_from_utf8())
if json == null:
fetchBestLaps()
return
var result = json["dreamlo"]["leaderboard"]["entry"]
if result is Array:
bestLaps = result
else:
bestLaps = [result]
var bestLapsList: ItemList = %BestLapsList
bestLapsList.clear()
var placement = 1
for entry in bestLaps:
# entry = entry["entry"]
var playerName = entry["name"]
var score = get_time_string_from_ticks(-(entry["score"]).to_int())
var date = entry["date"].split(" ")[0]
var row = str(placement) + "." + playerName + " - " + score + " - " + date
if entry["text"] != "":
row += " (" + entry["text"] + ")"
bestLapsList.add_item(row, null, false)
placement += 1
var timer = null
func _ready():
visibility_changed.connect(onVisibilityChanged)
timer = Timer.new()
add_child(timer)
timer.wait_time = 10
timer.one_shot = false
timer.timeout.connect(refreshLists)
timer.start()
timer.paused = !visible
refreshLists()
%CloseButton.button_up.connect(func(): self.hide())
func refreshLists():
fetchBestTotalTimes()
fetchBestLaps()
func get_time_string_from_ticks(ticks: int) -> String:
if ticks == -1:
return "N/A"
var seconds: int = ticks / 1000
var minutes: int = seconds / 60
return "%02d:%02d:" % [minutes % 60, seconds % 60] + ("%.3f" % ((ticks % 1000) / float(1000))).split(".")[1]