> refactor ir leaderboard requests to only use one var for tracking the request state
This commit is contained in:
parent
6421323b14
commit
d6dbee6316
|
@ -119,8 +119,6 @@ local jacketCache = {}
|
|||
|
||||
local top50diffs = {}
|
||||
|
||||
local isIrLeaderboardRequested = false;
|
||||
local isIrLeaderboardFetching = false;
|
||||
local irRequestStatus = 1; -- 0=unused, 1=not requested, 2=loading, others are status codes
|
||||
local irRequestTimeout = 2
|
||||
local irLeaderboard = {}
|
||||
|
@ -564,7 +562,7 @@ function drawIrLeaderboard()
|
|||
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER + gfx.TEXT_ALIGN_MIDDLE)
|
||||
gfx.BeginPath();
|
||||
|
||||
if isIrLeaderboardFetching or irRequestTimeout > 0 then
|
||||
if irRequestStatus == 1 or irRequestStatus == 2 then
|
||||
gfx.Text("Loading ranking...", scoreBoardX + (sbBarWidth / 2), scoreBoardY + sbBarHeight/2);
|
||||
return;
|
||||
end
|
||||
|
@ -670,10 +668,9 @@ function drawSearch()
|
|||
end
|
||||
|
||||
function refreshIrLeaderboard()
|
||||
if isIrLeaderboardRequested then
|
||||
if irRequestStatus ~= 1 then -- Only continue if the leaderboard is requesteded, but not loading or loaded.
|
||||
return
|
||||
end
|
||||
isIrLeaderboardRequested = true;
|
||||
irLeaderboard = {}
|
||||
|
||||
local song = songwheel.songs[selectedIndex];
|
||||
|
@ -683,7 +680,11 @@ function refreshIrLeaderboard()
|
|||
return;
|
||||
end
|
||||
|
||||
isIrLeaderboardFetching = true;
|
||||
irRequestStatus = 2; -- Loading
|
||||
-- onIrLeaderboardFetched({
|
||||
-- statusCode = 20,
|
||||
-- body = {}
|
||||
-- })
|
||||
IR.Leaderboard(diff.hash, 'best', 4, onIrLeaderboardFetched)
|
||||
end
|
||||
|
||||
|
@ -701,8 +702,6 @@ function dump(o)
|
|||
end
|
||||
|
||||
function onIrLeaderboardFetched(res)
|
||||
isIrLeaderboardFetching = false;
|
||||
|
||||
irRequestStatus = res.statusCode;
|
||||
|
||||
if res.statusCode == IRData.States.Success then
|
||||
|
@ -896,7 +895,7 @@ draw_songwheel = function(x,y,w,h, deltaTime)
|
|||
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_TOP)
|
||||
local debugScrollingUp= "FALSE"
|
||||
if scrollingUp then debugScrollingUp = "TRUE" end;
|
||||
gfx.Text('S_I: ' .. selectedIndex .. ' // S_D: ' .. selectedDifficulty .. ' // S_UP: ' .. debugScrollingUp .. ' // AC_TS: ' .. transitionAfterscrollScale .. ' // L_TS: ' .. transitionLeaveScale .. ' // IR_T: ' .. irRequestTimeout, 8, 8);
|
||||
gfx.Text('S_I: ' .. selectedIndex .. ' // S_D: ' .. selectedDifficulty .. ' // S_UP: ' .. debugScrollingUp .. ' // AC_TS: ' .. transitionAfterscrollScale .. ' // L_TS: ' .. transitionLeaveScale .. ' // IR_CODE: ' .. irRequestStatus .. ' // IR_T: ' .. irRequestTimeout, 8, 8);
|
||||
|
||||
gfx.ResetTransform();
|
||||
end
|
||||
|
@ -985,7 +984,7 @@ set_diff = function(newDiff)
|
|||
end
|
||||
|
||||
selectedDifficulty = newDiff;
|
||||
isIrLeaderboardRequested = false;
|
||||
irRequestStatus = 1;
|
||||
irLeaderboard = {}
|
||||
irRequestTimeout = 2
|
||||
end;
|
Loading…
Reference in New Issue