diff --git a/scripts/songselect/songwheel.lua b/scripts/songselect/songwheel.lua index 1991fec..e0725c7 100644 --- a/scripts/songselect/songwheel.lua +++ b/scripts/songselect/songwheel.lua @@ -604,7 +604,7 @@ function drawIrLeaderboard() -- local irScore = irLeaderboard[i]; if irScore then - local rank = irScore.ranking + local rank = index; gfx.TextAlign(gfx.TEXT_ALIGN_CENTER + gfx.TEXT_ALIGN_MIDDLE) gfx.BeginPath(); gfx.Text(LEADERBOARD_PLACE_NAMES[rank], sbBarContentLeftX-40, scoreBoardY + sbBarHeight/2 + rank*sbBarHeight); @@ -677,7 +677,7 @@ function refreshIrLeaderboard(deltaTime) if not IRData.Active then return; end - + if irRequestStatus ~= 1 then -- Only continue if the leaderboard is requesteded, but not loading or loaded. return end @@ -725,16 +725,25 @@ end function onIrLeaderboardFetched(res) irRequestStatus = res.statusCode; + local song = songwheel.songs[selectedIndex]; + local diff = song and song.difficulties[selectedDifficulty] or false; + irLeaderboardsCache[diff.hash] = irLeaderboard; + game.Log(diff.hash, game.LOGGER_ERROR) + if res.statusCode == IRData.States.Success then - local tempIrLeaderboard = res.body; + game.Log('Raw IR reposonse: ' .. dump(res.body), game.LOGGER_ERROR) + local tempIrLB = res.body; - for i, tempScore in ipairs(tempIrLeaderboard) do - irLeaderboard[tempScore.ranking] = tempScore - end + table.sort(tempIrLB, function (a,b) + -- game.Log(a.score .. ' ?? ' .. b.score, game.LOGGER_ERROR) + return a.score > b.score + end) - local song = songwheel.songs[selectedIndex]; - local diff = song and song.difficulties[selectedDifficulty] or false; - irLeaderboardsCache[diff.hash] = irLeaderboard; + -- for i, tempScore in ipairs(tempIrLeaderboard) do + -- irLeaderboard[tempScore.ranking] = tempScore + -- end + + irLeaderboard = tempIrLB; game.Log(dump(irLeaderboard), game.LOGGER_ERROR) else