Skip to content

Commit

Permalink
Add a lua shortcut for finding best grade per song
Browse files Browse the repository at this point in the history
  • Loading branch information
poco0317 committed Nov 3, 2020
1 parent 1e79be0 commit 6529522
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Etterna/Models/Songs/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <set>
#include <map>

#include "Etterna/Singletons/ScoreManager.h"

using std::vector;

//-Nick12 Used for song file hashing
Expand Down Expand Up @@ -2415,6 +2417,20 @@ class LunaSong : public Luna<Song>
LuaHelpers::CreateTableFromArray(p->GetChartsMatchingFilter(), L);
return 1;
}
static int GetHighestGrade(T* p, lua_State* L)
{
// this shadows (and essentially doesnt even do remotely the same thing as) the MusicWheelItem best grade thing for the item grades
auto charts = p->GetChartsMatchingFilter();

Grade best = Grade_Invalid;
for (auto& c : charts) {
auto g = SCOREMAN->GetBestGradeFor(c->GetChartKey());
if (best >= g)
best = g;
}
LuaHelpers::Push(L, best);
return 1;
}
LunaSong()
{
ADD_METHOD(GetDisplayFullTitle);
Expand Down Expand Up @@ -2482,6 +2498,7 @@ class LunaSong : public Luna<Song>
ADD_METHOD(PlaySampleMusicExtended);
ADD_METHOD(GetChartsOfCurrentGameMode);
ADD_METHOD(GetChartsMatchingFilter);
ADD_METHOD(GetHighestGrade);
}
};

Expand Down

0 comments on commit 6529522

Please sign in to comment.