> 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 top50diffs = {}
|
||||||
|
|
||||||
local isIrLeaderboardRequested = false;
|
|
||||||
local isIrLeaderboardFetching = false;
|
|
||||||
local irRequestStatus = 1; -- 0=unused, 1=not requested, 2=loading, others are status codes
|
local irRequestStatus = 1; -- 0=unused, 1=not requested, 2=loading, others are status codes
|
||||||
local irRequestTimeout = 2
|
local irRequestTimeout = 2
|
||||||
local irLeaderboard = {}
|
local irLeaderboard = {}
|
||||||
|
@ -564,7 +562,7 @@ function drawIrLeaderboard()
|
||||||
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER + gfx.TEXT_ALIGN_MIDDLE)
|
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER + gfx.TEXT_ALIGN_MIDDLE)
|
||||||
gfx.BeginPath();
|
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);
|
gfx.Text("Loading ranking...", scoreBoardX + (sbBarWidth / 2), scoreBoardY + sbBarHeight/2);
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
|
@ -670,10 +668,9 @@ function drawSearch()
|
||||||
end
|
end
|
||||||
|
|
||||||
function refreshIrLeaderboard()
|
function refreshIrLeaderboard()
|
||||||
if isIrLeaderboardRequested then
|
if irRequestStatus ~= 1 then -- Only continue if the leaderboard is requesteded, but not loading or loaded.
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
isIrLeaderboardRequested = true;
|
|
||||||
irLeaderboard = {}
|
irLeaderboard = {}
|
||||||
|
|
||||||
local song = songwheel.songs[selectedIndex];
|
local song = songwheel.songs[selectedIndex];
|
||||||
|
@ -683,7 +680,11 @@ function refreshIrLeaderboard()
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
|
|
||||||
isIrLeaderboardFetching = true;
|
irRequestStatus = 2; -- Loading
|
||||||
|
-- onIrLeaderboardFetched({
|
||||||
|
-- statusCode = 20,
|
||||||
|
-- body = {}
|
||||||
|
-- })
|
||||||
IR.Leaderboard(diff.hash, 'best', 4, onIrLeaderboardFetched)
|
IR.Leaderboard(diff.hash, 'best', 4, onIrLeaderboardFetched)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -701,8 +702,6 @@ function dump(o)
|
||||||
end
|
end
|
||||||
|
|
||||||
function onIrLeaderboardFetched(res)
|
function onIrLeaderboardFetched(res)
|
||||||
isIrLeaderboardFetching = false;
|
|
||||||
|
|
||||||
irRequestStatus = res.statusCode;
|
irRequestStatus = res.statusCode;
|
||||||
|
|
||||||
if res.statusCode == IRData.States.Success then
|
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)
|
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_TOP)
|
||||||
local debugScrollingUp= "FALSE"
|
local debugScrollingUp= "FALSE"
|
||||||
if scrollingUp then debugScrollingUp = "TRUE" end;
|
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();
|
gfx.ResetTransform();
|
||||||
end
|
end
|
||||||
|
@ -985,7 +984,7 @@ set_diff = function(newDiff)
|
||||||
end
|
end
|
||||||
|
|
||||||
selectedDifficulty = newDiff;
|
selectedDifficulty = newDiff;
|
||||||
isIrLeaderboardRequested = false;
|
irRequestStatus = 1;
|
||||||
irLeaderboard = {}
|
irLeaderboard = {}
|
||||||
irRequestTimeout = 2
|
irRequestTimeout = 2
|
||||||
end;
|
end;
|
Loading…
Reference in New Issue