From dbaa975302fce60421e82b731edc21c365ad184e Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 23 Nov 2018 15:43:31 -0300 Subject: [PATCH] Fix RequestChartLeaderboard callbacks --- .../ScreenGameplay overlay/leaderboard.lua | 9 +- .../ScreenSelectMusic decorations/default.lua | 19 +- .../ScreenSelectMusic decorations/score.lua | 251 +++++++++--------- .../BGAnimations/superscoreboard.lua | 20 +- src/DownloadManager.cpp | 112 ++++---- src/DownloadManager.h | 5 +- src/LuaReference.cpp | 2 +- src/LuaReference.h | 2 +- 8 files changed, 223 insertions(+), 197 deletions(-) diff --git a/Themes/Til Death/BGAnimations/ScreenGameplay overlay/leaderboard.lua b/Themes/Til Death/BGAnimations/ScreenGameplay overlay/leaderboard.lua index be11a63d7f..26f1fc6cc2 100644 --- a/Themes/Til Death/BGAnimations/ScreenGameplay overlay/leaderboard.lua +++ b/Themes/Til Death/BGAnimations/ScreenGameplay overlay/leaderboard.lua @@ -27,17 +27,20 @@ local jdgs = { local function arbitraryLeaderboardSpacing(value) for i, entry in ipairs(entryActors) do - entry.container:addy((i-1) * value) + entry.container:addy((i - 1) * value) end if allowedCustomization then - Movable.DeviceButton_s.Border:playcommand("ChangeHeight", {val = entryActors[#entryActors].container:GetY() + ENTRY_HEIGHT}) + Movable.DeviceButton_s.Border:playcommand( + "ChangeHeight", + {val = entryActors[#entryActors].container:GetY() + ENTRY_HEIGHT} + ) end end if not DLMAN:GetCurrentRateFilter() then DLMAN:ToggleRateFilter() end -local onlineScores = DLMAN:RequestChartLeaderBoard(GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey()) +local onlineScores = DLMAN:GetChartLeaderBoard(GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey()) local sortFunction = function(h1, h2) return h1[CRITERIA](h1) > h2[CRITERIA](h2) end diff --git a/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/default.lua b/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/default.lua index d0ee07d08e..78b3f38f79 100644 --- a/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/default.lua +++ b/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/default.lua @@ -44,16 +44,21 @@ t[#t + 1] = end end, PlayingSampleMusicMessageCommand = function(self) - local leaderboardEnabled = playerConfig:get_data(pn_to_profile_slot(PLAYER_1)).leaderboardEnabled and DLMAN:IsLoggedIn() + local leaderboardEnabled = + playerConfig:get_data(pn_to_profile_slot(PLAYER_1)).leaderboardEnabled and DLMAN:IsLoggedIn() if leaderboardEnabled then local chartkey = GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey() - DLMAN:RequestChartLeaderBoardFromOnline(chartkey) + DLMAN:RequestChartLeaderBoardFromOnline( + chartkey, + function(leaderboard) + end + ) end end, - ChartPreviewOnMessageCommand=function(self) + ChartPreviewOnMessageCommand = function(self) self:addx(capWideScale(12, 0)):addy(capWideScale(18, 0)) end, - ChartPreviewOffMessageCommand=function(self) + ChartPreviewOffMessageCommand = function(self) self:addx(capWideScale(-12, 0)):addy(capWideScale(-18, 0)) end, Def.StepsDisplayList { @@ -74,15 +79,13 @@ t[#t + 1] = end } }, - CursorP2 = Def.ActorFrame { - }, + CursorP2 = Def.ActorFrame {}, CursorP1Frame = Def.Actor { ChangeCommand = function(self) self:stoptweening():decelerate(0.05) end }, - CursorP2Frame = Def.Actor { - }, + CursorP2Frame = Def.Actor {} } } diff --git a/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/score.lua b/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/score.lua index 2c1c6dc9b7..ac5c82fb02 100644 --- a/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/score.lua +++ b/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/score.lua @@ -93,8 +93,12 @@ local function updateLeaderBoardForCurrentChart() local top = SCREENMAN:GetTopScreen() if top:GetMusicWheel():IsSettled() and ((getTabIndex() == 2 and nestedTab == 2) or collapsed) then local steps = GAMESTATE:GetCurrentSteps(PLAYER_1) - if steps then - DLMAN:RequestChartLeaderBoardFromOnline(steps:GetChartKey()) + if steps then + DLMAN:RequestChartLeaderBoardFromOnline( + steps:GetChartKey(), + function(leaderboard) + end + ) moped:queuecommand("ChartLeaderboardUpdate") else moped:queuecommand("Bort") @@ -108,12 +112,12 @@ local ret = moped = self:GetChild("ScoreDisplay") self:queuecommand("Set"):visible(false) self:GetChild("LocalScores"):xy(frameX, frameY):visible(false) - self:GetChild("ScoreDisplay"):xy(frameX, frameY):visible(false) + moped:xy(frameX, frameY):visible(false) if FILTERMAN:oopsimlazylol() then -- set saved position and auto collapse nestedTab = 2 self:GetChild("LocalScores"):visible(false) - self:GetChild("ScoreDisplay"):xy(FILTERMAN:grabposx("Doot"), FILTERMAN:grabposy("Doot")):visible(true) + moped:xy(FILTERMAN:grabposx("Doot"), FILTERMAN:grabposy("Doot")):visible(true) self:playcommand("Collapse") end end, @@ -168,7 +172,8 @@ local ret = MESSAGEMAN:Broadcast("TabChanged") end, PlayingSampleMusicMessageCommand = function(self) - local leaderboardEnabled = playerConfig:get_data(pn_to_profile_slot(PLAYER_1)).leaderboardEnabled and DLMAN:IsLoggedIn() + local leaderboardEnabled = + playerConfig:get_data(pn_to_profile_slot(PLAYER_1)).leaderboardEnabled and DLMAN:IsLoggedIn() if not leaderboardEnabled then -- this is taken care of by default.lua instead. updateLeaderBoardForCurrentChart() end @@ -283,9 +288,7 @@ local t = Def.Quad { Name = "FrameDisplay", InitCommand = function(self) - self:zoomto(frameWidth, frameHeight):halign(0):valign(0):diffuse( - color("#333333CC") - ) + self:zoomto(frameWidth, frameHeight):halign(0):valign(0):diffuse(color("#333333CC")) end, CollapseCommand = function(self) self:visible(false) @@ -300,45 +303,42 @@ local t = t[#t + 1] = Def.Quad { InitCommand = function(self) - self:zoomto(frameWidth, offsetY):halign(0):valign(0):diffuse(getMainColor("frames")):diffusealpha( - 0.5 - ) + self:zoomto(frameWidth, offsetY):halign(0):valign(0):diffuse(getMainColor("frames")):diffusealpha(0.5) end } -local l = Def.ActorFrame{ -- stuff inside the frame.. so we can move it all at once - InitCommand=function(self) - self:xy(offsetX, offsetY+headeroffY) +local l = + Def.ActorFrame { + -- stuff inside the frame.. so we can move it all at once + InitCommand = function(self) + self:xy(offsetX, offsetY + headeroffY) end, LoadFont("Common Large") .. - { - Name = "Grades", - InitCommand = function(self) - self:y(20):zoom(0.6):halign(0):maxwidth(50 / 0.6):settext("") - end, - DisplayCommand = function(self) - self:settext(THEME:GetString("Grade", ToEnumShortString(score:GetWifeGrade()))) - self:diffuse(getGradeColor(score:GetWifeGrade())) - end - }, - --- Wife display + { + Name = "Grades", + InitCommand = function(self) + self:y(20):zoom(0.6):halign(0):maxwidth(50 / 0.6):settext("") + end, + DisplayCommand = function(self) + self:settext(THEME:GetString("Grade", ToEnumShortString(score:GetWifeGrade()))) + self:diffuse(getGradeColor(score:GetWifeGrade())) + end + }, + -- Wife display LoadFont("Common Normal") .. - { - Name = "Wife", - InitCommand = function(self) - self:xy(55, 15):zoom(0.6):halign(0):settext("") - end, - DisplayCommand = function(self) - if score:GetWifeScore() == 0 then - self:settextf("NA") - else - self:settextf("%05.2f%%", notShit.floor(score:GetWifeScore() * 10000) / 100):diffuse(byGrade(score:GetWifeGrade())) + { + Name = "Wife", + InitCommand = function(self) + self:xy(55, 15):zoom(0.6):halign(0):settext("") + end, + DisplayCommand = function(self) + if score:GetWifeScore() == 0 then + self:settextf("NA") + else + self:settextf("%05.2f%%", notShit.floor(score:GetWifeScore() * 10000) / 100):diffuse(byGrade(score:GetWifeGrade())) + end end - end - }, - - + }, LoadFont("Common Normal") .. { Name = "Score", @@ -350,11 +350,9 @@ local l = Def.ActorFrame{ -- stuff inside the frame.. so we can move it all at o self:settext("") else local overall = score:GetSkillsetSSR("Overall") - self:settextf("%.2f", overall):diffuse(byMSD(overall)) + self:settextf("%.2f", overall):diffuse(byMSD(overall)) end - end - }, - + }, LoadFont("Common Normal") .. { Name = "Score", @@ -382,92 +380,91 @@ local l = Def.ActorFrame{ -- stuff inside the frame.. so we can move it all at o self:settext(getClearTypeFromScore(pn, score, 0)) self:diffuse(getClearTypeFromScore(pn, score, 2)) end - }, - + },rtLeaderboard callbacks LoadFont("Common Normal") .. - { - Name = "Combo", - InitCommand = function(self) - self:y(58):zoom(0.4):halign(0):settext("Max Combo:") - end, - DisplayCommand = function(self) - self:settextf("Max Combo: %d", score:GetMaxCombo()) - end - }, - - + { + Name = "Combo", + InitCommand = function(self) + self:y(58):zoom(0.4):halign(0):settext("Max Combo:") + end, + DisplayCommand = function(self) + self:settextf("Max Combo: %d", score:GetMaxCombo()) + end + }, LoadFont("Common Normal") .. - { - Name = "MissCount", - InitCommand = function(self) - self:y(73):zoom(0.4):halign(0):settext("Miss Count:") - end, - DisplayCommand = function(self) - local missCount = getScoreMissCount(score) - if missCount ~= nil then - self:settext("Miss Count: " .. missCount) - else - self:settext("Miss Count: -") + { + Name = "MissCount", + InitCommand = function(self) + self:y(73):zoom(0.4):halign(0):settext("Miss Count:") + end, + DisplayCommand = function(self) + local missCount = getScoreMissCount(score) + if missCount ~= nil then + self:settext("Miss Count: " .. missCount) + else + self:settext("Miss Count: -") + end end - end - }, - + }, LoadFont("Common Normal") .. - { - Name = "Date", - InitCommand = function(self) - self:y(88):zoom(0.4):halign(0):settext("Date Achieved:") - end, - DisplayCommand = function(self) - self:settext("Date Achieved: " .. getScoreDate(score)) - end - }, + { + Name = "Date", + InitCommand = function(self) + self:y(88):zoom(0.4):halign(0):settext("Date Achieved:") + end, + DisplayCommand = function(self) + self:settext("Date Achieved: " .. getScoreDate(score)) + end + }, LoadFont("Common Normal") .. - { - Name = "Mods", - InitCommand = function(self) - self:y(103):zoom(0.4):halign(0):settext("Mods:") - end, - DisplayCommand = function(self) - self:settext("Mods: " .. score:GetModifiers()) - end - }, + { + Name = "Mods", + InitCommand = function(self) + self:y(103):zoom(0.4):halign(0):settext("Mods:") + end, + DisplayCommand = function(self) + self:settext("Mods: " .. score:GetModifiers()) + end + }, LoadFont("Common Normal") .. - { - InitCommand = function(self) - self:xy(frameWidth - offsetX - frameX, frameHeight - headeroffY - 10 - offsetY):zoom(0.4):halign(1):settext( - "No Scores Saved" - ) - end, - DisplayCommand = function(self) - self:settextf("Rate %s - Showing %d/%d", rates[rateIndex], scoreIndex, #rtTable[rates[rateIndex]]) - end - }, + { + InitCommand = function(self) + self:xy(frameWidth - offsetX - frameX, frameHeight - headeroffY - 10 - offsetY):zoom(0.4):halign(1):settext( + "No Scores Saved" + ) + end, + DisplayCommand = function(self) + self:settextf("Rate %s - Showing %d/%d", rates[rateIndex], scoreIndex, #rtTable[rates[rateIndex]]) + end + }, LoadFont("Common Normal") .. - { - Name = "ChordCohesion", - InitCommand = function(self) - self:y(frameHeight - headeroffY - 10 - offsetY):zoom(0.4):halign(0):settext("Chord Cohesion:") - end, - DisplayCommand = function(self) - if score:GetChordCohesion() then - self:settext("Chord Cohesion: Yes") - else - self:settext("Chord Cohesion: No") + { + Name = "ChordCohesion", + InitCommand = function(self) + self:y(frameHeight - headeroffY - 10 - offsetY):zoom(0.4):halign(0):settext("Chord Cohesion:") + end, + DisplayCommand = function(self) + if score:GetChordCohesion() then + self:settext("Chord Cohesion: Yes") + else + self:settext("Chord Cohesion: No") + end end - end - }, - LoadFont("Common Normal") .. { - Name = "Judge", - InitCommand = function(self) - self:xy((frameWidth - offsetX - frameX) / 2, frameHeight - headeroffY - 10 - offsetY):zoom(0.4):settext("") - end, - DisplayCommand = function(self) - local j = table.find(ms.JudgeScalers , notShit.round(score:GetJudgeScale(), 2)) - if not j then j = 4 end - self:settext("Judge "..j) - end - } + }, + LoadFont("Common Normal") .. + { + Name = "Judge", + InitCommand = function(self) + self:xy((frameWidth - offsetX - frameX) / 2, frameHeight - headeroffY - 10 - offsetY):zoom(0.4):settext("") + end, + DisplayCommand = function(self) + local j = table.find(ms.JudgeScalers, notShit.round(score:GetJudgeScale(), 2)) + if not j then + j = 4 + end + self:settext("Judge " .. j) + end + } } local function makeText(index) @@ -668,14 +665,15 @@ l[#l + 1] = if nestedTab == 1 then if getTabIndex() == 2 and isOver(self) then DLMAN:SendReplayDataForOldScore(score:GetScoreKey()) - ms.ok("Uploading Replay Data...") --should have better feedback -mina + ms.ok("Uploading Replay Data...") --should have better feedback -mina end end end } t[#t + 1] = l -t[#t+1] = Def.Quad { +t[#t + 1] = + Def.Quad { Name = "ScrollBar", InitCommand = function(self) self:x(frameWidth):zoomto(4, 0):halign(1):valign(1):diffuse(getMainColor("highlight")):diffusealpha(0.75) @@ -688,13 +686,12 @@ t[#t+1] = Def.Quad { end } - ret[#ret + 1] = t function nestedTabButton(i) return Def.ActorFrame { InitCommand = function(self) - self:xy(frameX + offsetX + (i - 1) * (nestedTabButtonWidth - capWideScale(100,80)), frameY + offsetY - 2) + self:xy(frameX + offsetX + (i - 1) * (nestedTabButtonWidth - capWideScale(100, 80)), frameY + offsetY - 2) self:SetUpdateFunction(highlight) end, CollapseCommand = function(self) @@ -736,7 +733,7 @@ function nestedTabButton(i) } end --- online score display +-- online score display ret[#ret + 1] = LoadActor("../superscoreboard") for i = 1, #nestedTabs do diff --git a/Themes/Til Death/BGAnimations/superscoreboard.lua b/Themes/Til Death/BGAnimations/superscoreboard.lua index bced658842..8f5d89d137 100644 --- a/Themes/Til Death/BGAnimations/superscoreboard.lua +++ b/Themes/Til Death/BGAnimations/superscoreboard.lua @@ -9,7 +9,7 @@ local ind = 0 local offx = 5 local width = SCREEN_WIDTH * 0.56 local dwidth = width - offx * 2 -local height = (numscores + 2) * packspaceY - packspaceY/3 -- account dumbly for header being moved up +local height = (numscores + 2) * packspaceY - packspaceY / 3 -- account dumbly for header being moved up local adjx = 14 local c0x = 10 @@ -106,7 +106,7 @@ local o = SCREENMAN:GetTopScreen():AddInputCallback(input) end, ChartLeaderboardUpdateMessageCommand = function(self) - scoretable = DLMAN:RequestChartLeaderBoard(GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey(), currentCountry) + scoretable = DLMAN:GetChartLeaderBoard(GAMESTATE:GetCurrentSteps(PLAYER_1):GetChartKey(), currentCountry) ind = 0 self:playcommand("Update") end, @@ -183,7 +183,7 @@ local o = offx = 5 width = SCREEN_WIDTH * 0.56 dwidth = width - offx * 2 - height = (numscores + 2) * packspaceY - packspaceY/3 + height = (numscores + 2) * packspaceY - packspaceY / 3 adjx = 14 c0x = 10 @@ -230,7 +230,9 @@ local o = -- grabby thing Def.Quad { InitCommand = function(self) - self:xy(dwidth / 4, headeroff):zoomto(dwidth - dwidth / 4, pdh - 8 * tzoom):halign(0):diffuse(getMainColor("frames")):diffusealpha(0.5):valign(1) + self:xy(dwidth / 4, headeroff):zoomto(dwidth - dwidth / 4, pdh - 8 * tzoom):halign(0):diffuse(getMainColor("frames")):diffusealpha( + 0.5 + ):valign(1) end, WHAZZZAAAACommand = function(self) if isOver(self) and collapsed then @@ -407,8 +409,9 @@ local function makeScoreDisplay(i) self:addy(-row2yoff) end }, - LoadFont("Common normal") .. { - Name = "Burt"..i, + LoadFont("Common normal") .. + { + Name = "Burt" .. i, InitCommand = function(self) self:x(c2x):zoom(tzoom + 0.1):maxwidth((c3x - c2x - capWideScale(10, 40)) / tzoom):halign(0):valign(1) if collapsed then @@ -433,8 +436,9 @@ local function makeScoreDisplay(i) end end }, - LoadFont("Common normal") .. { - Name = "Ernie"..i, + LoadFont("Common normal") .. + { + Name = "Ernie" .. i, InitCommand = function(self) if not collapsed then self:x(c2x):zoom(tzoom - 0.05):halign(0):valign(0):maxwidth(width / 2 / tzoom):addy(row2yoff) diff --git a/src/DownloadManager.cpp b/src/DownloadManager.cpp index c570009d5f..0de3356e75 100644 --- a/src/DownloadManager.cpp +++ b/src/DownloadManager.cpp @@ -26,7 +26,7 @@ #include #include "PlayerStageStats.h" #include "Grade.h" -#include "SongManager.h" // i didn't want to do this but i also didn't want to figure how not to have to so... -mina +#include "SongManager.h" // i didn't want to do this but i also didn't want to figure how not to have to so... -mina using json = nlohmann::json; #ifdef _WIN32 #include @@ -1024,11 +1024,11 @@ DownloadManager::UploadScoreWithReplayData(HighScore* hs) HTTPRequests.push_back(req); return; } -void // not tested exhaustively -mina +void // not tested exhaustively -mina DownloadManager::UploadScoreWithReplayDataFromDisk(string sk) { if (!LoggedIn()) - return; + return; auto doot = SCOREMAN->GetScoresByKey(); auto hs = doot[sk]; @@ -1089,7 +1089,8 @@ DownloadManager::UploadScoreWithReplayDataFromDisk(string sk) DLMAN->sessionPass, [hs](bool logged) { if (logged) { - DLMAN->UploadScoreWithReplayDataFromDisk(hs->GetScoreKey()); + DLMAN->UploadScoreWithReplayDataFromDisk( + hs->GetScoreKey()); } }); } else if (status == 404 || status == 405 || @@ -1379,29 +1380,10 @@ DownloadManager::RefreshCountryCodes() void DownloadManager::RequestChartLeaderBoard(string chartkey, LuaReference ref) { - RequestChartLeaderBoard(chartkey); - if (unlikely(!ref.IsNil())) { - Lua* L = LUA->Get(); - ref.PushSelf(L); - if (lua_isnil(L, -1)) { - LUA->Release(L); - LuaHelpers::ReportScriptErrorFmt("Error compiling RequestChartLeaderBoard Finish Function"); - return; - } - RString Error = "Error running RequestChartLeaderBoard Finish Function: "; - LuaHelpers::RunScriptOnStack(L, Error, 2, 0, true); // 1 args, 0 results - LUA->Release(L); - } -} - -void -DownloadManager::RequestChartLeaderBoard(string chartkey) -{ - auto done = [chartkey](HTTPRequest& req, CURLMsg*) { + auto done = [chartkey, ref](HTTPRequest& req, CURLMsg*) { vector& vec = DLMAN->chartLeaderboards[chartkey]; vec.clear(); // unordered_set userswithscores; - Message msg("ChartLeaderboardUpdate"); try { auto j = json::parse(req.result); if (j.find("errors") != j.end()) @@ -1410,13 +1392,10 @@ DownloadManager::RequestChartLeaderBoard(string chartkey) for (auto scoreJ : (*scores)) { auto score = *(scoreJ.find("attributes")); - // i don't really want to do this very iteration but oh well - // -mina - msg.SetParam("songid", - RString(score.value("songId", "").c_str())); - OnlineScore tmp; + // tmp.songId = score.value("songId", 0); auto user = *(score.find("user")); + tmp.songId = score.value("songId", 0); tmp.username = user.value("userName", "").c_str(); tmp.avatar = user.value("avatar", "").c_str(); tmp.userid = user.value("userId", 0); @@ -1515,13 +1494,33 @@ DownloadManager::RequestChartLeaderBoard(string chartkey) // json failed } + Message msg("ChartLeaderboardUpdate"); + vector leaderboardHS; + // This is like a functional map + transform(vec.begin(), + vec.end(), + back_inserter(leaderboardHS), + [](auto s) { return &(s.hs); }); + + if (!ref.IsNil() && ref.IsSet()) { + Lua* L = LUA->Get(); + ref.PushSelf(L); + if (!lua_isnil(L, -1)) { + RString Error = + "Error running RequestChartLeaderBoard Finish Function: "; + LuaHelpers::CreateTableFromArray(leaderboardHS, L); + LuaHelpers::RunScriptOnStack( + L, Error, 1, 0, true); // 1 args, 0 results + } + LUA->Release(L); + } // float ProbablyUnderratedness = // mythicalmathymathsProbablyUnderratedness(chartkey); float coop = // overratedness(chartkey); // Renaming these 2 requires renaming them in lua wherever theyre used // msg.SetParam("mmm", ProbablyUnderratedness); // msg.SetParam("ixmixblixb", 2); - MESSAGEMAN->Broadcast(msg); // see start of function + MESSAGEMAN->Broadcast(msg); }; SendRequest("/charts/" + chartkey + "/leaderboards", vector>(), @@ -2229,23 +2228,38 @@ class LunaDownloadManager : public Luna // this will not update a leaderboard to a new state. static int RequestChartLeaderBoardFromOnline(T* p, lua_State* L) { - if (!lua_isfunction(L, 2)) { - LuaReference ref; + string chart = SArg(1); + LuaReference ref; + auto& leaderboardScores = DLMAN->chartLeaderboards[chart]; + if (lua_isfunction(L, 2)) { lua_pushvalue(L, 2); ref.SetFromStack(L); - if (DLMAN->chartLeaderboards[SArg(1)].size() == 0) { - DLMAN->RequestChartLeaderBoard(SArg(1), ref); + } + if (leaderboardScores.size() != 0) { + vector leaderboardHS; + // This is like a functional map + transform(leaderboardScores.begin(), + leaderboardScores.end(), + back_inserter(leaderboardHS), + [](auto s) { return &(s.hs); }); + if (!ref.IsNil()) { + ref.PushSelf(L); + if (!lua_isnil(L, -1)) { + RString Error = + "Error running RequestChartLeaderBoard Finish Function: "; + LuaHelpers::CreateTableFromArray(leaderboardHS, L); + LuaHelpers::RunScriptOnStack( + L, Error, 1, 0, true); // 1 args, 0 results + } } - } else { - if (DLMAN->chartLeaderboards[SArg(1)].size() == 0) - DLMAN->RequestChartLeaderBoard(SArg(1)); + return 0; } - return 1; + DLMAN->RequestChartLeaderBoard(chart, ref); + + return 0; } - // This does not actually request the leaderboard from online. - // It gets the already retrieved data from DLMAN - static int RequestChartLeaderBoard(T* p, lua_State* L) + static int GetChartLeaderBoard(T* p, lua_State* L) { vector filteredLeaderboardScores; unordered_set userswithscores; @@ -2258,12 +2272,12 @@ class LunaDownloadManager : public Luna for (auto& score : leaderboardScores) { auto& leaderboardHighScore = score.hs; - if (lround(leaderboardHighScore.GetMusicRate() * 10000.f) != - lround(currentrate * 10000.f) && - p->currentrateonly) + if (p->currentrateonly && + lround(leaderboardHighScore.GetMusicRate() * 10000.f) != + lround(currentrate * 10000.f)) continue; - if (userswithscores.count(leaderboardHighScore.GetName()) == 1 && - p->topscoresonly) + if (p->topscoresonly && + userswithscores.count(leaderboardHighScore.GetName()) == 1) continue; if (country != "" && country != "Global" && leaderboardHighScore.countryCode != country) @@ -2324,7 +2338,11 @@ class LunaDownloadManager : public Luna ADD_METHOD(GetLastVersion); ADD_METHOD(GetRegisterPage); ADD_METHOD(RequestChartLeaderBoardFromOnline); - ADD_METHOD(RequestChartLeaderBoard); + ADD_METHOD(GetChartLeaderBoard); + // This does not actually request the leaderboard from online. + // It gets the already retrieved data from DLMAN + // Why does this alias exist? + AddMethod("GetChartLeaderboard", GetChartLeaderBoard); ADD_METHOD(ToggleRateFilter); ADD_METHOD(GetCurrentRateFilter); ADD_METHOD(ToggleTopScoresOnlyFilter); diff --git a/src/DownloadManager.h b/src/DownloadManager.h index 541354df42..d236536a07 100644 --- a/src/DownloadManager.h +++ b/src/DownloadManager.h @@ -148,6 +148,7 @@ class OnlineScore int marvelous{ 0 }; int minehits{ 0 }; int held{ 0 }; + int songId{ 0 }; int letgo{ 0 }; bool valid{ false }; bool nocc{ false }; @@ -275,8 +276,8 @@ class DownloadManager bool currentrateonly = false; bool topscoresonly = true; void RefreshCountryCodes(); - void RequestChartLeaderBoard(string chartkey, LuaReference ref); - void RequestChartLeaderBoard(string chartkey); + void RequestChartLeaderBoard(string chartkey, + LuaReference ref = LuaReference()); void RefreshUserData(); string countryCode; void RefreshUserRank(); diff --git a/src/LuaReference.cpp b/src/LuaReference.cpp index 5451ff8061..a59c777fdc 100644 --- a/src/LuaReference.cpp +++ b/src/LuaReference.cpp @@ -5,7 +5,7 @@ REGISTER_CLASS_TRAITS(LuaReference, new LuaReference(*pCopy)) LuaReference::LuaReference() { - m_iReference = LUA_NOREF; + m_iReference = LUA_REFNIL; } LuaReference::~LuaReference() diff --git a/src/LuaReference.h b/src/LuaReference.h index fb4fd41b14..9d0ab7e859 100644 --- a/src/LuaReference.h +++ b/src/LuaReference.h @@ -19,7 +19,7 @@ class LuaReference // Convenience constructor. LuaReference(Lua* L) - : m_iReference(LUA_NOREF) + : m_iReference(LUA_REFNIL) { SetFromStack(L); }