Skip to content

Commit 1a26323

Browse files
committed
Update GJUser.hx
1 parent bbcf493 commit 1a26323

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/gamejolt/GJUser.hx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,17 @@ class GJUser
9595
* @param extra_data If there's some extra data about this Score achievement, you can set it here.
9696
* @param table_id The ID of the Score Table this Score is gonna be added to.
9797
* (If you leave this `null`, this Score will be added to the Primary Score Table of your game)
98-
* @return A `Future` instance holding the success state of the request.
98+
* @return A `Future` instance holding the data of the submitted score if the request was successful.
9999
*/
100-
public function addScore(sort:Int, tag:String, ?extra_data:String, ?table_id:Int):Future<Bool>
100+
public function addScore(sort:Int, tag:String, ?extra_data:String, ?table_id:Int):Future<Score>
101101
{
102-
var promise:Promise<Bool> = new Promise<Bool>();
103-
104-
new GJRequest().urlFromType(SCORES_ADD(data.username, token, '$sort $tag', sort, extra_data, table_id))
102+
var promise:Promise<Score> = new Promise<Score>();
103+
new GJRequest().urlFromBatch([
104+
SCORES_ADD(data.username, token, '$sort $tag', sort, extra_data, table_id),
105+
SCORES_FETCH(table_id, null, sort - 1, data.username, token)
106+
])
105107
.execute(true)
106-
.onComplete(res -> promise.complete(res.success))
108+
.onComplete(res -> promise.complete(Lambda.find(res.responses[1].scores, s -> sort == s.sort)))
107109
.onError(e -> promise.error(e));
108110
return promise.future;
109111
}
@@ -114,25 +116,26 @@ class GJUser
114116
* @param removeAfter Whether to remove the Trophy after achieving it or not,
115117
* useful when it comes to Trophy testing and stuff.
116118
* Default is `false`.
117-
* @return A `Future` instance holding the success state of the request.
119+
* @return A `Future` instance holding the updated info of such Trophy if the request was successful.
118120
*/
119-
public function addTrophy(trophyID:Int, removeAfter:Bool = false):Future<Bool>
121+
public function addTrophy(trophyID:Int, removeAfter:Bool = false):Future<Trophy>
120122
{
121-
var promise:Promise<Bool> = new Promise<Bool>();
123+
var promise:Promise<Trophy> = new Promise<Trophy>();
122124

123-
if (!logged || token == "")
125+
if (token == "")
124126
{
125-
promise.complete(false);
127+
promise.error("User's game token is missing for trophy achievement");
126128
return promise.future;
127129
}
128130

129131
var requests:Array<RequestType> = [TROPHIES_ADD(data.username, token, trophyID)];
130132
if (removeAfter)
131133
requests.push(TROPHIES_REMOVE(data.username, token, trophyID));
134+
requests.push(TROPHIES_FETCH(data.username, token, trophyID));
132135

133136
new GJRequest().urlFromBatch(requests)
134137
.execute(true)
135-
.onComplete(res -> promise.complete(res.responses[0].success))
138+
.onComplete(res -> promise.complete(res.responses[removeAfter ? 2 : 1].trophies[0]))
136139
.onError(e -> promise.error(e));
137140
return promise.future;
138141
}

0 commit comments

Comments
 (0)