Skip to content

Commit 228da82

Browse files
add getbestgrades for a song inside profile
more or less copy pasta'd musicwheel code for grade display, can likely be optimized added to unbreak grade sorting at music wheel uses new scoreman stuff obv
1 parent 0cfee43 commit 228da82

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/Profile.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,39 @@ void Profile::IncrementStepsPlayCount( const Song* pSong, const Steps* pSteps )
472472
GetStepsHighScoreList(pSong,pSteps).IncrementPlayCount( now );
473473
}
474474

475+
Grade Profile::GetBestGrade(const Song* pSong, StepsType st) const
476+
{
477+
Grade gradeBest = Grade_Invalid;
478+
if (pSong != nullptr) {
479+
bool hasCurrentStyleSteps = false;
480+
FOREACH_ENUM_N(Difficulty, 6, i) {
481+
Steps* pSteps = SongUtil::GetStepsByDifficulty(pSong, st, i);
482+
if (pSteps != NULL) {
483+
hasCurrentStyleSteps = true;
484+
Grade dcg = SCOREMAN->GetBestGradeFor(pSteps->GetChartKey());
485+
if (gradeBest >= dcg) {
486+
gradeBest = dcg;
487+
}
488+
}
489+
}
490+
//If no grade was found for the current style/stepstype
491+
if (!hasCurrentStyleSteps) {
492+
//Get the best grade among all steps
493+
auto& allSteps = pSong->GetAllSteps();
494+
for (auto& stepsPtr : allSteps) {
495+
if (stepsPtr->m_StepsType == st) //Skip already checked steps of type st
496+
continue;
497+
Grade dcg = SCOREMAN->GetBestGradeFor(stepsPtr->GetChartKey());
498+
if (gradeBest >= dcg) {
499+
gradeBest = dcg;
500+
}
501+
}
502+
}
503+
}
504+
505+
return gradeBest;
506+
}
507+
475508
void Profile::GetGrades( const Song* pSong, StepsType st, int iCounts[NUM_Grade] ) const
476509
{
477510
SongID songID;

src/Profile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ class Profile
298298
HighScoreList& GetStepsHighScoreList( const Song* pSong, const Steps* pSteps );
299299
int GetStepsNumTimesPlayed( const Song* pSong, const Steps* pSteps ) const;
300300
void IncrementStepsPlayCount( const Song* pSong, const Steps* pSteps );
301+
Grade GetBestGrade(const Song * pSong, StepsType st) const;
301302
void GetGrades( const Song* pSong, StepsType st, int iCounts[NUM_Grade] ) const;
302303
int GetSongNumTimesPlayed( const Song* pSong ) const;
303304
int GetSongNumTimesPlayed( const SongID& songID ) const;

0 commit comments

Comments
 (0)