diff --git a/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/profile.lua b/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/profile.lua index a3ea54954e..571726487b 100644 --- a/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/profile.lua +++ b/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/profile.lua @@ -9,7 +9,6 @@ local t = Def.ActorFrame{ self:finishtweening() if getTabIndex() == 4 then - self:queuecommand("On") self:visible(true) update = true @@ -31,7 +30,7 @@ local scorestodisplay = 25 local distY = 15 local offsetX = 10 local offsetY = 20 -local rankingSkillset=0 +local rankingSkillset=1 local rankingPage=1 local rankingWidth = frameWidth-capWideScale(15,50) local rankingX = capWideScale(30,50) @@ -40,7 +39,6 @@ local rankingTitleWidth = (rankingWidth/(#ms.SkillSets + 1)) if GAMESTATE:IsPlayerEnabled(PLAYER_1) then profile = GetPlayerOrMachineProfile(PLAYER_1) - profile:SortAllSSRs() -- should be fine this way now - mina end @@ -61,7 +59,7 @@ local function rankingLabel(i) local t = Def.ActorFrame{ InitCommand=cmd(visible, false), UpdateRankingMessageCommand=function(self) - if rankingSkillset > 0 then + if rankingSkillset > 1 then self:visible(true) else self:visible(false) @@ -73,12 +71,11 @@ local function rankingLabel(i) if update then self:diffuse(getMainColor("positive")) self:settext(((rankingPage-1)*25)+i..".") - ths = profile:GetTopSSRHighScore(i+(scorestodisplay*(rankingPage-1)), rankingSkillset) + ths = SCOREMAN:GetTopSSRHighScore(i+(scorestodisplay*(rankingPage-1)), ms.SkillSets[rankingSkillset]) if ths then ck = ths:GetChartKey() thssong = SONGMAN:GetSongByChartKey(ck) thssteps = SONGMAN:GetStepsByChartKey(ck) - if not thssong or not thssteps then ths = nil end end end @@ -88,10 +85,10 @@ local function rankingLabel(i) LoadFont("Common Large") .. { InitCommand=cmd(xy,frameX+rankingX,frameY+rankingY+110-(11-i)*10;halign,0;zoom,0.25;diffuse,getMainColor('positive');maxwidth,160), SetCommand=function(self) - if update and rankingSkillset > 0 then + if update and rankingSkillset > 1 then if ths then - local a=profile:GetTopSSRValue(i+(scorestodisplay*(rankingPage-1)), rankingSkillset) - self:settextf("%5.2f", a) + local val = ths:GetSkillsetSSR(ms.SkillSets[rankingSkillset]) + self:settextf("%5.2f", val) if not ths:GetEtternaValid() then self:diffuse(byJudgment("TapNoteScore_Miss")) else @@ -161,11 +158,9 @@ local function rankingLabel(i) InitCommand=cmd(xy,frameX+rankingX+310,frameY+rankingY+110-(11-i)*10;halign,0.5;zoom,0.25;diffuse,getMainColor('positive');maxwidth,rankingWidth*4-160), SetCommand=function(self) if update and ths then - if (thssteps ~= nil) then - local diff = thssteps:GetDifficulty() - self:diffuse(byDifficulty(diff)) - self:settext(getShortDifficulty(diff)) - end + local diff = thssteps:GetDifficulty() + self:diffuse(byDifficulty(diff)) + self:settext(getShortDifficulty(diff)) else self:settext( ' - ' ) self:diffuse(getMainColor('positive')) @@ -206,7 +201,7 @@ local function rankingButton(i) Def.Quad{ InitCommand=cmd(xy,frameX+rankingX+(i-1+i*(1/(1+#ms.SkillSets)))*rankingTitleWidth,frameY+rankingY-30;zoomto,rankingTitleWidth,30;halign,0.5;valign,0;diffuse,getMainColor('frames');diffusealpha,0.35), SetCommand=function(self) - if i-1 == rankingSkillset then + if i == rankingSkillset then self:diffusealpha(1) else self:diffusealpha(0.35) @@ -214,8 +209,10 @@ local function rankingButton(i) end, MouseLeftClickMessageCommand=function(self) if isOver(self) then - rankingSkillset = i-1 + rankingSkillset = i rankingPage = 1 + SCOREMAN:SortSSRs(ms.SkillSets[rankingSkillset]) + ms.ok(ms.SkillSets[rankingSkillset]) MESSAGEMAN:Broadcast("UpdateRanking") end end, @@ -237,7 +234,7 @@ end r[#r+1] = Def.Quad{ InitCommand=cmd(xy,frameX+frameWidth-30,frameY+rankingY+265;zoomto,40,20;halign,0.5;valign,0;diffuse,getMainColor('frames');diffusealpha,0.35), SetCommand=function(self) - if rankingSkillset > 0 then + if rankingSkillset > 1 then self:visible(true) else self:visible(false) @@ -259,7 +256,7 @@ r[#r+1] = Def.Quad{ r[#r+1] = LoadFont("Common Large") .. { InitCommand=cmd(xy,frameX+frameWidth-30,frameY+rankingY+275;halign,0.5;zoom,0.3;diffuse,getMainColor('positive');settext,"Next"), SetCommand=function(self) - if rankingSkillset > 0 then + if rankingSkillset > 1 then self:visible(true) else self:visible(false) @@ -271,7 +268,7 @@ r[#r+1] = LoadFont("Common Large") .. { r[#r+1] = Def.Quad{ InitCommand=cmd(xy,frameX+40,frameY+rankingY+265;zoomto,65,20;halign,0.5;valign,0;diffuse,getMainColor('frames');diffusealpha,0.35), SetCommand=function(self) - if rankingSkillset > 0 then + if rankingSkillset > 1 then self:visible(true) else self:visible(false) @@ -294,7 +291,7 @@ r[#r+1] = Def.Quad{ r[#r+1] = LoadFont("Common Large") .. { InitCommand=cmd(xy,frameX+40,frameY+rankingY+275;halign,0.5;zoom,0.3;diffuse,getMainColor('positive');settext,"Previous"), SetCommand=function(self) - if rankingSkillset > 0 then + if rankingSkillset > 1 then self:visible(true) else self:visible(false) @@ -306,7 +303,7 @@ r[#r+1] = LoadFont("Common Large") .. { r[#r+1] = LoadFont("Common Large") .. { InitCommand=cmd(xy,frameX+frameWidth/2,frameY+rankingY+275;halign,0.5;zoom,0.3;diffuse,getMainColor('positive')), SetCommand=function(self) - if rankingSkillset > 0 then + if rankingSkillset > 1 then self:visible(true) self:settextf("%i-%i", ((rankingPage-1)*25)+1, rankingPage*25) else @@ -332,7 +329,7 @@ t[#t+1] = r local function littlebits(i) local t = Def.ActorFrame{ UpdateRankingMessageCommand=function(self) - if rankingSkillset == 0 then + if rankingSkillset == 1 then self:visible(true) else self:visible(false) @@ -362,14 +359,14 @@ local function littlebits(i) return t end -for i=2,#ms.SkillSets do +for i=1,#ms.SkillSets do t[#t+1] = littlebits(i) end t[#t+1] = Def.Quad{ InitCommand=cmd(xy,frameX+80,frameY+rankingY+265;zoomto,100,20;halign,0.5;valign,0;diffuse,getMainColor('frames');diffusealpha,0.35), SetCommand=function(self) - if rankingSkillset == 0 then + if rankingSkillset == 1 then self:visible(true) else self:visible(false) @@ -391,7 +388,7 @@ t[#t+1] = Def.Quad{ t[#t+1] = Def.Quad{ InitCommand=cmd(xy,frameX+320,frameY+rankingY+265;zoomto,100,20;halign,0.5;valign,0;diffuse,getMainColor('frames');diffusealpha,0.35), SetCommand=function(self) - if rankingSkillset == 0 then + if rankingSkillset == 1 then self:visible(true) else self:visible(false) @@ -413,7 +410,7 @@ t[#t+1] = Def.Quad{ t[#t+1] = LoadFont("Common Large") .. { InitCommand=cmd(xy,frameX+80,frameY+rankingY+275;halign,0.5;zoom,0.3;diffuse,getMainColor('positive');settext,"Save Profile"), SetCommand=function(self) - if rankingSkillset == 0 then + if rankingSkillset == 1 then self:visible(true) else self:visible(false) @@ -425,7 +422,7 @@ t[#t+1] = LoadFont("Common Large") .. { t[#t+1] = Def.Quad{ InitCommand=cmd(xy,frameX+210,frameY+rankingY+265;zoomto,100,20;halign,0.5;valign,0;diffuse,getMainColor('frames');diffusealpha,0.35), SetCommand=function(self) - if rankingSkillset == 0 then + if rankingSkillset == 1 then self:visible(true) else self:visible(false) @@ -442,7 +439,7 @@ t[#t+1] = Def.Quad{ t[#t+1] = LoadFont("Common Large") .. { InitCommand=cmd(xy,frameX+210,frameY+rankingY+275;halign,0.5;zoom,0.3;diffuse,getMainColor('positive');settext,"Validate All"), SetCommand=function(self) - if rankingSkillset == 0 then + if rankingSkillset == 1 then self:visible(true) else self:visible(false) diff --git a/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/score.lua b/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/score.lua index ed9c818fec..825a2097d9 100644 --- a/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/score.lua +++ b/Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/score.lua @@ -111,7 +111,7 @@ t[#t+1] = LoadFont("Common Large")..{ Name="Grades", InitCommand=cmd(xy,frameX+offsetX,frameY+offsetY+20;zoom,0.6;halign,0;maxwidth,50/0.6), SetCommand=function(self) - if score ~= nil then + if score and update then self:settext(THEME:GetString("Grade",ToEnumShortString(score:GetGrade()))) self:diffuse(getGradeColor(score:GetGrade())) else @@ -126,7 +126,7 @@ t[#t+1] = LoadFont("Common Normal")..{ Name="Score", InitCommand=cmd(xy,frameX+offsetX+55,frameY+offsetY+28;zoom,0.5;halign,0), SetCommand=function(self) - if score ~= nil then + if score and update then if score:GetWifeScore() == 0 then self:settextf("NA (%s)", "Wife") else @@ -144,7 +144,7 @@ t[#t+1] = LoadFont("Common Normal")..{ -- Name="Score", -- InitCommand=cmd(xy,frameX+offsetX+155,frameY+offsetY+14;zoom,0.5;halign,0), -- SetCommand=function(self) - -- if score ~= nil then + -- if score and update then -- if score:GetWifeScore() == 0 then -- self:settextf("NA (%s)", "Wife") -- else @@ -161,7 +161,7 @@ t[#t+1] = LoadFont("Common Normal")..{ -- Name="Score", -- InitCommand=cmd(xy,frameX+offsetX+155,frameY+offsetY+58;zoom,0.5;halign,0), -- SetCommand=function(self) - -- if score ~= nil then + -- if score and update then -- if score:GetWifeScore() == 0 then -- self:settext("") -- else @@ -178,7 +178,7 @@ t[#t+1] = LoadFont("Common Normal")..{ Name="ClearType", InitCommand=cmd(xy,frameX+offsetX,frameY+offsetY+41;zoom,0.5;halign,0); SetCommand=function(self) - if score ~= nil then + if score and update then self:settext(getClearTypeFromScore(pn,score,0)) self:diffuse(getClearTypeFromScore(pn,score,2)) end @@ -190,7 +190,7 @@ t[#t+1] = LoadFont("Common Normal")..{ Name="Combo", InitCommand=cmd(xy,frameX+offsetX,frameY+offsetY+58;zoom,0.4;halign,0); SetCommand=function(self) - if score ~= nil then + if score and update then local maxCombo = getScoreMaxCombo(score) self:settextf("Max Combo: %d",maxCombo) else @@ -204,7 +204,7 @@ t[#t+1] = LoadFont("Common Normal")..{ Name="MissCount", InitCommand=cmd(xy,frameX+offsetX,frameY+offsetY+73;zoom,0.4;halign,0); SetCommand=function(self) - if score ~= nil then + if score and update then local missCount = getScoreMissCount(score) if missCount ~= nil then self:settext("Miss Count: "..missCount) @@ -222,7 +222,7 @@ t[#t+1] = LoadFont("Common Normal")..{ Name="Date", InitCommand=cmd(xy,frameX+offsetX,frameY+offsetY+88;zoom,0.4;halign,0); SetCommand=function(self) - if score ~= nil then + if score and update then self:settext("Date Achieved: "..getScoreDate(score)) else self:settext("Date Achieved: ") @@ -235,7 +235,7 @@ t[#t+1] = LoadFont("Common Normal")..{ Name="Mods", InitCommand=cmd(xy,frameX+offsetX,frameY+offsetY+103;zoom,0.4;halign,0); SetCommand=function(self) - if score ~= nil then + if score and update then self:settext("Mods: " ..score:GetModifiers()) else self:settext("Mods:") @@ -249,7 +249,7 @@ t[#t+1] = LoadFont("Common Normal")..{ InitCommand=cmd(xy,frameX+frameWidth-offsetX,frameY+offsetY+10;zoom,0.5;halign,1), SetCommand=function(self) local steps = GAMESTATE:GetCurrentSteps(pn) - if steps ~= nil then + if score and update then local diff = getDifficulty(steps:GetDifficulty()) local stype = ToEnumShortString(steps:GetStepsType()):gsub("%_"," ") local meter = steps:GetMeter() @@ -278,7 +278,7 @@ t[#t+1] = LoadFont("Common Normal")..{ Name="ChordCohesion", InitCommand=cmd(xy,frameX+frameWidth/40,frameY+frameHeight-10;zoom,0.4;halign,0), SetCommand=function(self) - if score ~= nil then + if score and update then if score:GetChordCohesion() == true then self:settext("Chord Cohesion: Yes") else @@ -352,7 +352,7 @@ local function makeJudge(index,judge) t[#t+1] = LoadFont("Common Normal")..{ InitCommand=cmd(x,120;zoom,0.5;halign,1), SetCommand=function(self) - if score ~= nil then + if score and update then if judge ~= 'HoldNoteScore_Held' and judge ~= 'HoldNoteScore_LetGo' then self:settext(getScoreTapNoteScore(score,judge)) else diff --git a/Themes/Til Death/BGAnimations/_PlayerInfo.lua b/Themes/Til Death/BGAnimations/_PlayerInfo.lua index a83518aca3..2e9e7772c0 100644 --- a/Themes/Til Death/BGAnimations/_PlayerInfo.lua +++ b/Themes/Til Death/BGAnimations/_PlayerInfo.lua @@ -26,11 +26,7 @@ t[#t+1] = Def.Actor{ if GAMESTATE:IsPlayerEnabled(PLAYER_1) then profile = GetPlayerOrMachineProfile(PLAYER_1) if profile ~= nil then - if profile == PROFILEMAN:GetMachineProfile() then - profileName = "Player 1" - else - profileName = profile:GetDisplayName() - end + profileName = profile:GetDisplayName() playCount = profile:GetTotalNumSongsPlayed() playTime = profile:GetTotalSessionSeconds() noteCount = profile:GetTotalTapsAndHolds() diff --git a/Themes/Til Death/Scripts/Scores.lua b/Themes/Til Death/Scripts/Scores.lua index 51f6bcc2dc..02679e207f 100644 --- a/Themes/Til Death/Scripts/Scores.lua +++ b/Themes/Til Death/Scripts/Scores.lua @@ -326,7 +326,7 @@ function getScoresByKey(pn) profile = GetPlayerOrMachineProfile(pn) steps = GAMESTATE:GetCurrentSteps(pn) if profile ~= nil and steps ~= nil and song ~= nil then - return profile:GetScoresByKey(steps:GetChartKey()) + return SCOREMAN:GetScoresByKey(steps:GetChartKey()) end end return nil diff --git a/src/HighScore.cpp b/src/HighScore.cpp index 14d85bf0e2..e8af708fae 100644 --- a/src/HighScore.cpp +++ b/src/HighScore.cpp @@ -1085,8 +1085,7 @@ class LunaHighScore: public Luna } static int GetSkillsetSSR(T* p, lua_State *L) { - Skillset lel = static_cast(IArg(1)-1); - lua_pushnumber(L, p->GetSkillsetSSR(lel)); + lua_pushnumber(L, p->GetSkillsetSSR(Enum::Check(L, 1))); return 1; } static int ToggleEtternaValidation(T* p, lua_State *L) { diff --git a/src/Profile.cpp b/src/Profile.cpp index 6c812b93b4..97e644ee20 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -1829,32 +1829,6 @@ void Profile::DeleteGoal(RString ck, DateTime assigned) { } } - -float Profile::GetTopSSRValue(unsigned int rank, int ss) { - if (rank < 0) - rank = 0; - HighScore *highScorePtr = GetTopSSRHighScore(rank, ss); - //Empty HighScore Pointer = NULL then return 0 - if(highScorePtr == NULL) - return 0.f; - - if (ss >= 0 && ss < NUM_Skillset && rank < SCOREMAN->TopSSRs.size()) - return highScorePtr->GetSkillsetSSR(static_cast(ss)); - - //Undefined skillset - return 0.f; -} - -HighScore* Profile::GetTopSSRHighScore(unsigned int rank, int ss) { - if (rank < 0) - rank = 0; - - if (ss >= 0 && ss < NUM_Skillset && rank < SCOREMAN->TopSSRs.size()) - return &(*SCOREMAN->TopSSRs[rank]); - - return NULL; -} - XNode* Profile::SaveCategoryScoresCreateNode() const { CHECKPOINT_M("Getting the node that saves category scores."); @@ -2245,21 +2219,8 @@ class LunaProfile : public Luna lua_pushnil(L); return 1; } - static int GetTopSSRValue(T* p, lua_State *L) { - lua_pushnumber(L, p->GetTopSSRValue(IArg(1) - 1, IArg(2))); - return 1; - } - static int GetTopSSRHighScore(T* p, lua_State *L) { - HighScore* ths = p->GetTopSSRHighScore(IArg(1) - 1, IArg(2)); - if (ths) - ths->PushSelf(L); - else - lua_pushnil(L); - return 1; - } static int GetPlayerSkillsetRating(T* p, lua_State *L) { - Skillset lel = static_cast(IArg(1) - 1); - lua_pushnumber(L, p->m_fPlayerSkillsets[lel]); + lua_pushnumber(L, p->m_fPlayerSkillsets[Enum::Check(L, 1)]); return 1; } @@ -2323,8 +2284,6 @@ class LunaProfile : public Luna ADD_METHOD( GetPlayerRating ); ADD_METHOD( GetPlayerSkillsetRating ); ADD_METHOD( GetNumFaves ); - ADD_METHOD( GetTopSSRValue ); - ADD_METHOD( GetTopSSRHighScore ); ADD_METHOD( GetAllGoals ); } }; diff --git a/src/Profile.h b/src/Profile.h index 1bfd774e1f..1465f9282f 100644 --- a/src/Profile.h +++ b/src/Profile.h @@ -245,9 +245,6 @@ class Profile void AddToFavorites(RString ck) { FavoritedCharts.emplace_back(ck); } void RemoveFromFavorites(RString ck); - // uses the keyed scoremap -mina - vector GetScoresByKey(RString ck); - // Vector for now, we can make this more efficient later vector FavoritedCharts; @@ -378,11 +375,6 @@ class Profile // Lua void PushSelf( lua_State *L ); - - - //TopSSRs - HighScore* GetTopSSRHighScore(unsigned int rank, int skillset); - float GetTopSSRValue(unsigned int rank, int skillset); private: const HighScoresForASong *GetHighScoresForASong( const SongID& songID ) const; diff --git a/src/ProfileManager.cpp b/src/ProfileManager.cpp index 230b752b21..14e14f1671 100644 --- a/src/ProfileManager.cpp +++ b/src/ProfileManager.cpp @@ -701,14 +701,7 @@ void ProfileManager::IncrementCategoryPlayCount( StepsType st, RankingCategory r bool ProfileManager::IsPersistentProfile( ProfileSlot slot ) const { - switch( slot ) - { - case ProfileSlot_Player1: - case ProfileSlot_Player2: - return GAMESTATE->IsHumanPlayer((PlayerNumber)slot) && !m_sProfileDir[slot].empty(); - default: - FAIL_M("Invalid profile slot chosen: unable to get profile info!"); - } + return true; } void ProfileManager::GetLocalProfileIDs( vector &vsProfileIDsOut ) const @@ -784,6 +777,11 @@ class LunaProfileManager: public Luna } static int IsPersistentProfile( T* p, lua_State *L ) { lua_pushboolean(L, p->IsPersistentProfile(Enum::Check(L, 1)) ); return 1; } static int GetProfile( T* p, lua_State *L ) { PlayerNumber pn = Enum::Check(L, 1); Profile* pP = p->GetProfile(pn); ASSERT(pP != NULL); pP->PushSelf(L); return 1; } + static int GetMachineProfile(T* p, lua_State *L) { + Profile* pP = p->GetProfile(PLAYER_1); + pP->PushSelf(L); + return 1; + } static int GetLocalProfile( T* p, lua_State *L ) { Profile *pProfile = p->GetLocalProfile(SArg(1)); @@ -860,6 +858,7 @@ class LunaProfileManager: public Luna ADD_METHOD(SetStatsPrefix); ADD_METHOD( IsPersistentProfile ); ADD_METHOD( GetProfile ); + ADD_METHOD(GetMachineProfile); ADD_METHOD( GetLocalProfile ); ADD_METHOD( GetLocalProfileFromIndex ); ADD_METHOD( GetLocalProfileIDFromIndex ); diff --git a/src/ScoreManager.cpp b/src/ScoreManager.cpp index b7e3ca76c4..3660d1a54d 100644 --- a/src/ScoreManager.cpp +++ b/src/ScoreManager.cpp @@ -6,6 +6,7 @@ #include "ScoreManager.h" #include "XmlFile.h" #include "XmlFileUtil.h" +#include "SongManager.h" ScoreManager* SCOREMAN = NULL; @@ -101,30 +102,29 @@ vector ScoresForChart::GetPlayedRates() { return o; } -vector ScoresForChart::GetPlayedRateKeys() const{ +vector ScoresForChart::GetPlayedRateKeys() { vector o; - FOREACHM_CONST(int, ScoresAtRate, ScoresByRate, i) + FOREACHM(int, ScoresAtRate, ScoresByRate, i) o.emplace_back(i->first); return o; } -vector ScoresForChart::GetPlayedRateDisplayStrings() const { - vector& rates = GetPlayedRateKeys(); - vector o(rates.size()); - for(size_t i = 0; i < rates.size(); ++i) { - o[i] = RateKeyToDisplayString(rates[i]); - } - +vector ScoresForChart::GetPlayedRateDisplayStrings() { + vector rates = GetPlayedRates(); + vector o; + for(size_t i = 0; i < rates.size(); ++i) + o.emplace_back(RateKeyToDisplayString(rates[i])); return o; } -RString ScoresForChart::RateKeyToDisplayString(int& key) const { - RString rate = ssprintf("%.2f", rate); + +RString ScoresForChart::RateKeyToDisplayString(float rate) { + RString rs = ssprintf("%.2f", rate); int j = 1; - if (rate.find_last_not_of('0') == rate.find('.')) + if (rs.find_last_not_of('0') == rs.find('.')) j = 2; - rate.erase(rate.find_last_not_of('0') + j, rate.npos); - rate.append("x"); - return rate; + rs.erase(rs.find_last_not_of('0') + j, rs.npos); + rs.append("x"); + return rs; } @@ -152,19 +152,6 @@ HighScore* ScoreManager::GetChartPBUpTo(RString& ck, float& rate) { -void ScoreManager::SortTopSSRPtrs(Skillset ss) { - TopSSRs.clear(); - FOREACHM(RString, ScoresForChart, pscores, i) { - if (!IsChartLoaded(i->first)) - continue; - vector pbs = i->second.GetAllPBPtrs(); - FOREACH(HighScore*, pbs, hs) { - TopSSRs.emplace_back(*hs); - } - } - auto ssrcomp = [&ss](HighScore* a, HighScore* b) { return (a->GetSkillsetSSR(ss) > b->GetSkillsetSSR(ss)); }; - sort(TopSSRs.begin(), TopSSRs.end(), ssrcomp); -} void ScoreManager::RecalculateSSRs() { return; @@ -206,6 +193,30 @@ float ScoreManager::AggregateSSRs(Skillset ss, float rating, float res, int iter return AggregateSSRs(ss, rating - res, res / 2.f, iter + 1); } +void ScoreManager::SortTopSSRPtrs(Skillset ss) { + TopSSRs.clear(); + FOREACHM(RString, ScoresForChart, pscores, i) { + if (!SONGMAN->IsChartLoaded(i->first)) + continue; + vector pbs = i->second.GetAllPBPtrs(); + FOREACH(HighScore*, pbs, hs) { + TopSSRs.emplace_back(*hs); + } + } + + auto ssrcomp = [&ss](HighScore* a, HighScore* b) { return (a->GetSkillsetSSR(ss) > b->GetSkillsetSSR(ss)); }; + sort(TopSSRs.begin(), TopSSRs.end(), ssrcomp); +} + +HighScore* ScoreManager::GetTopSSRHighScore(unsigned int rank, int ss) { + if (rank < 0) + rank = 0; + + if (ss >= 0 && ss < NUM_Skillset && rank < TopSSRs.size()) + return TopSSRs[rank]; + + return NULL; +} @@ -356,7 +367,6 @@ class LunaScoreManager : public Luna vector ratekeys = scores->GetPlayedRateKeys(); vector ratedisplay = scores->GetPlayedRateDisplayStrings(); for (size_t i = 0; i < ratekeys.size(); ++i) { - LuaHelpers::Push(L, ratedisplay[i]); scores->GetScoresAtRate(ratekeys[i])->PushSelf(L); lua_rawset(L, -3); @@ -369,9 +379,8 @@ class LunaScoreManager : public Luna return 1; } - static int SortAllSSRs(T* p, lua_State *L) { - for (size_t i = 0; i < NUM_Skillset; ++i) - p->SortTopSSRPtrs(static_cast(i)); + static int SortSSRs(T* p, lua_State *L) { + p->SortTopSSRPtrs(Enum::Check(L, 1)); return 1; } @@ -380,11 +389,21 @@ class LunaScoreManager : public Luna return 1; } + static int GetTopSSRHighScore(T* p, lua_State *L) { + HighScore* ths = p->GetTopSSRHighScore(IArg(1) - 1, Enum::Check(L, 2)); + if (ths) + ths->PushSelf(L); + else + lua_pushnil(L); + return 1; + } + LunaScoreManager() { ADD_METHOD(GetScoresByKey); - ADD_METHOD(SortAllSSRs); + ADD_METHOD(SortSSRs); ADD_METHOD(ValidateAllScores); + ADD_METHOD(GetTopSSRHighScore); } }; diff --git a/src/ScoreManager.h b/src/ScoreManager.h index cbc415f418..1e8b6d32d7 100644 --- a/src/ScoreManager.h +++ b/src/ScoreManager.h @@ -51,9 +51,9 @@ struct ScoresForChart void AddScore(HighScore& hs); vector GetPlayedRates(); - vector GetPlayedRateKeys() const; - vector GetPlayedRateDisplayStrings() const; - RString RateKeyToDisplayString(int& key) const; + vector GetPlayedRateKeys(); + vector GetPlayedRateDisplayStrings(); + RString RateKeyToDisplayString(float rate); int RateToKey(float& rate) { return lround(rate * 10000.f); } float KeyToRate(int key) { return static_cast(key) / 10000.f; } @@ -67,8 +67,6 @@ struct ScoresForChart void LoadFromNode(const XNode* node, const RString& ck); ScoresAtRate operator[](const int rate) { return ScoresByRate.at(rate); } - void Insert(int rate, ScoresAtRate scores) { LOG->Warn("asINSERTfasd"), ScoresByRate.emplace(rate, scores); } - map> ScoresByRate; private: /* It makes sense internally to have the map keys sorted highest rate to lowest @@ -105,10 +103,13 @@ class ScoreManager void RecalculateSSRs(); void EnableAllScores(); void CalcPlayerRating(float& prating, float* pskillsets); - float AggregateSSRs(Skillset ss, float rating, float res, int iter) const; + float AggregateSSRs(Skillset ss, float rating, float res, int iter) const; + + float GetTopSSRValue(unsigned int rank, int ss); + + HighScore * GetTopSSRHighScore(unsigned int rank, int ss); - bool IsChartLoaded(const RString& ck) { return true; } - bool KeyHasScores(const RString& ck) { return pscores.count(ck); } + bool KeyHasScores(const RString& ck) { return pscores.count(ck) == 1; } @@ -123,11 +124,14 @@ class ScoreManager void PushSelf(lua_State *L); vector zz; - // Instead of storing pointers for each skillset just reshuffle the same set of pointers - vector TopSSRs; + + private: std::map pscores; // Profile scores + // Instead of storing pointers for each skillset just reshuffle the same set of pointers + // it's inexpensive and not called often + vector TopSSRs; }; diff --git a/src/SongManager.cpp b/src/SongManager.cpp index 84a24b9a54..6b208c6e85 100644 --- a/src/SongManager.cpp +++ b/src/SongManager.cpp @@ -1323,6 +1323,7 @@ class LunaSongManager: public Luna DEFINE_METHOD( ShortenGroupName, ShortenGroupName( SArg(1) ) ) DEFINE_METHOD( GetSongGroupBannerPath, GetSongGroupBannerPath(SArg(1)) ); DEFINE_METHOD( DoesSongGroupExist, DoesSongGroupExist(SArg(1)) ); + DEFINE_METHOD(IsChartLoaded, IsChartLoaded(SArg(1))); static int GetPopularSongs( T* p, lua_State *L ) { @@ -1388,6 +1389,7 @@ class LunaSongManager: public Luna ADD_METHOD( WasLoadedFromAdditionalSongs ); ADD_METHOD( GetSongByChartKey ); ADD_METHOD( GetStepsByChartKey ); + ADD_METHOD(GetStepsByChartKey); } }; diff --git a/src/SongManager.h b/src/SongManager.h index 075979525f..4d6c1d97a5 100644 --- a/src/SongManager.h +++ b/src/SongManager.h @@ -72,6 +72,7 @@ class SongManager Song * GetSongByChartkey(RString ck); Steps* GetStepsByChartkey(const StepsID& sid); Song * GetSongByChartkey(const StepsID& sid); + bool IsChartLoaded(RString ck) { return SongsByKey.count(ck) == 1; } void ResetGroupColors();