-
Notifications
You must be signed in to change notification settings - Fork 1
/
leaderboard.gd
68 lines (58 loc) · 2.12 KB
/
leaderboard.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
extends Control
var entries = []
var hide_balloon_scores: bool = true
var metadata
func get_scores() -> Dictionary:
return await Leaderboards.get_scores(Global.LEADERBOARD_ID)
func _ready() -> void:
var scores = await get_scores()
scores = scores["scores"] # the data is a dictionary containing a scores array
print(scores)
for i in scores:
metadata = i["metadata"]
if i["is_current_player"]:
%items.add_item("You!",get_platform_image(metadata["platform"]), false)
%scores.add_item(str(i["score"]),null, false)
else:
%items.add_item(i["name"],get_platform_image(metadata["platform"]), false)
%scores.add_item(str(i["score"]),null, false)
entries.append(i)
func _on_texture_button_pressed() -> void:
Scenes.title()
func _on_check_button_toggled(toggled_on: bool) -> void:
var scores = await Leaderboards.get_scores(Global.LEADERBOARD_ID)
scores = scores["scores"]
print(scores)
%items.clear()
%scores.clear()
if !toggled_on and !entries[0]["metadata"]["balloon used?"]:
%items.remove_item(0)
%scores.remove_item(0)
for i in scores:
metadata = i["metadata"]
if metadata["balloon used?"] and toggled_on:
if i["is_current_player"]:
%items.add_item("You!", get_platform_image(metadata["platform"]), false)
else:
%items.add_item(i["name"], get_platform_image(metadata["platform"]), false)
%scores.add_item(str(i["score"]),null, false)
elif metadata["balloon used?"] == false:
if i["is_current_player"]:
%items.add_item("You!", get_platform_image(metadata["platform"]), false)
%scores.add_item(str(i["score"]),null, false)
else:
%items.add_item(i["name"], get_platform_image(metadata["platform"]), false)
%scores.add_item(str(i["score"]),null, false)
entries.append(i)
func get_platform_image(platform: String) -> Texture:
match platform:
"web":
return preload("res://assets/img/platform_images/web.png")
"windows":
return preload("res://assets/img/platform_images/windows.png")
"android":
return preload("res://assets/img/platform_images/android.png")
"linux":
return preload("res://assets/img/cat.png")
_:
return null # No image for unknown platforms