Skip to content

Commit

Permalink
send PB along with vote
Browse files Browse the repository at this point in the history
  • Loading branch information
sylae committed Oct 12, 2022
1 parent c71983d commit ab0a257
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
19 changes: 18 additions & 1 deletion TrackRatings/TrackRatings.as
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void Main() {
try {
auto map = app.RootMap;

if(windowVisible && map !is null && map.MapInfo.MapUid != "" && app.Editor is null) {
if(map !is null && map.MapInfo.MapUid != "" && app.Editor is null) {
if(currentMapUid != map.MapInfo.MapUid) {
currentMapUid = map.MapInfo.MapUid;
}
Expand All @@ -95,11 +95,28 @@ void Main() {
trApi.getMapInfo(trDat, currentTrack, playerInfo);
}

// update our PB - code cribbed from Ultimate Medals plugin
trDat.PB = 0;
auto network = cast<CTrackManiaNetwork>(app.Network);
if(network.ClientManiaAppPlayground !is null) {
auto userMgr = network.ClientManiaAppPlayground.UserMgr;
MwId userId;
if (userMgr.Users.Length > 0) {
userId = userMgr.Users[0].Id;
} else {
userId.Value = uint(-1);
}

auto scoreMgr = network.ClientManiaAppPlayground.ScoreMgr;
trDat.PB = scoreMgr.Map_GetRecord_v2(userId, currentTrack.uid, "PersonalBest", "", "TimeAttack", "");
}

} else if(map is null || map.MapInfo.MapUid == "") {
currentMapUid = "";
trDat.upCount = 0;
trDat.downCount = 0;
trDat.yourVote = "O";
trDat.PB = -1;
}

if (map !is null && (currentTrack is null || currentTrack.uid != currentMapUid)) {
Expand Down
1 change: 1 addition & 0 deletions TrackRatings/classes/ServerCommunicator.as
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ServerCommunicator {
payload["playerInfo"] = player.jsonEncode();
payload["trackInfo"] = map.jsonEncode();
payload["vote"] = vote;
payload["pb"] = trDat.PB;

Json::Value result;
Net::HttpRequest req;
Expand Down
2 changes: 2 additions & 0 deletions TrackRatings/classes/TrackRating.as
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class TrackRating {
int upCount;
int downCount;
string yourVote;

int PB;

string getUpCount() {
return fmt(upCount);
Expand Down

0 comments on commit ab0a257

Please sign in to comment.