@@ -22,13 +22,13 @@ func get_cached_entries_for_current_player(internal_name: String) -> Array:
2222 )
2323
2424## Get a list of entries for a leaderboard. The page parameter is used for pagination.
25- func get_entries (internal_name : String , page : int , alias_id = - 1 , include_archived = false ) -> Array :
25+ func get_entries (internal_name : String , page : int , alias_id = - 1 , include_archived = false ) -> EntriesPage :
2626 var url = "/%s /entries?page=%s "
2727 var url_data = [internal_name , page ]
2828
2929 if alias_id != - 1 :
3030 url += "&aliasId=%s "
31- url_data += alias_id
31+ url_data . append ( alias_id )
3232
3333 if include_archived :
3434 url += "&withDeleted=1"
@@ -37,32 +37,32 @@ func get_entries(internal_name: String, page: int, alias_id = -1, include_archiv
3737
3838 match (res .status ):
3939 200 :
40- var entries : Array = res .body .entries .map (
41- func (data : Dictionary ):
40+ var entries : Array [ TaloLeaderboardEntry ] = Array ( res .body .entries .map (
41+ func (data : Dictionary ):
4242 var entry = TaloLeaderboardEntry .new (data )
4343 _entries_manager .upsert_entry (internal_name , entry )
4444
4545 return entry
46- )
47- return [ entries , res .body .count , res .body .isLastPage ]
46+ ), TYPE_OBJECT , ( TaloLeaderboardEntry as Script ). get_instance_base_type (), TaloLeaderboardEntry )
47+ return EntriesPage . new ( entries , res .body .count , res .body .isLastPage )
4848 _ :
49- return []
49+ return null
5050
5151## Get a list of entries for a leaderboard for the current player. The page parameter is used for pagination.
52- func get_entries_for_current_player (internal_name : String , page : int , include_archived = false ) -> Array :
52+ func get_entries_for_current_player (internal_name : String , page : int , include_archived = false ) -> EntriesPage :
5353 if Talo .identity_check () != OK :
54- return []
54+ return null
5555
5656 return await get_entries (internal_name , page , Talo .current_alias .id , include_archived )
5757
5858## Add an entry to a leaderboard. The props (key-value pairs) parameter is used to store additional data with the entry.
59- func add_entry (internal_name : String , score : float , props : Dictionary = {}) -> Array :
59+ func add_entry (internal_name : String , score : float , props : Dictionary = {}) -> AddEntryResult :
6060 if Talo .identity_check () != OK :
61- return []
61+ return null
6262
63- var props_to_send = props .keys ().map (func (key : String ): return { key = key , value = str (props [key ]) })
63+ var props_to_send : Array = props .keys ().map (func (key : String ) -> Dictionary : return {key = key , value = str (props [key ])})
6464
65- var res = await client .make_request (HTTPClient .METHOD_POST , "/%s /entries" % internal_name , {
65+ var res : = await client .make_request (HTTPClient .METHOD_POST , "/%s /entries" % internal_name , {
6666 score = score ,
6767 props = props_to_send
6868 })
@@ -72,6 +72,25 @@ func add_entry(internal_name: String, score: float, props: Dictionary = {}) -> A
7272 var entry = TaloLeaderboardEntry .new (res .body .entry )
7373 _entries_manager .upsert_entry (internal_name , entry )
7474
75- return [ entry , res .body .updated ]
75+ return AddEntryResult . new ( entry , res .body .updated )
7676 _ :
77- return []
77+ return null
78+
79+ # Structs
80+ class EntriesPage :
81+ var entries : Array [TaloLeaderboardEntry ]
82+ var count : int
83+ var is_last_page : bool
84+
85+ func _init (entries : Array [TaloLeaderboardEntry ], count : int , is_last_page : bool ) -> void :
86+ self .entries = entries
87+ self .count = count
88+ self .is_last_page = is_last_page
89+
90+ class AddEntryResult :
91+ var entry : TaloLeaderboardEntry
92+ var updated : bool
93+
94+ func _init (entry : TaloLeaderboardEntry , updated : bool ) -> void :
95+ self .entry = entry
96+ self .updated = updated
0 commit comments