diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index 5cc87150a8..ce877e83a4 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -129,15 +129,15 @@ CString Profile::GetProfileDisplayNameFromDir( CString sDir ) return pro.GetDisplayName(); } -int Profile::GetSongNumTimesPlayed( Song* pSong ) +int Profile::GetSongNumTimesPlayed( const Song* pSong ) const { int iTotalNumTimesPlayed = 0; vector vpSteps; pSong->GetSteps( vpSteps ); for( unsigned i=0; iGetStepsHighScoreList(pSteps).iNumTimesPlayed; + const Steps* pSteps = vpSteps[i]; + iTotalNumTimesPlayed += ((Profile*) this)->GetStepsHighScoreList(pSteps).iNumTimesPlayed; } return iTotalNumTimesPlayed; } @@ -154,6 +154,12 @@ void Profile::AddStepsHighScore( const Steps* pSteps, HighScore hs, int &iIndexO iter->second.hs.AddHighScore( hs, iIndexOut ); } +const HighScoreList& Profile::GetStepsHighScoreList( const Steps* pSteps ) const +{ + /* We're const, but insert a blank entry anyway if the requested pointer doesn't exist. */ + return ((Profile *) this)->m_StepsHighScores[pSteps].hs; +} + HighScoreList& Profile::GetStepsHighScoreList( const Steps* pSteps ) { std::map::iterator iter = m_StepsHighScores.find( pSteps ); @@ -197,6 +203,11 @@ void Profile::AddCourseHighScore( const Course* pCourse, StepsType st, HighScore iter->second.hs[st].AddHighScore( hs, iIndexOut ); } +const HighScoreList& Profile::GetCourseHighScoreList( const Course* pCourse, StepsType st ) const +{ + return ((Profile *)this)->m_CourseHighScores[pCourse].hs[st]; +} + HighScoreList& Profile::GetCourseHighScoreList( const Course* pCourse, StepsType st ) { std::map::iterator iter = m_CourseHighScores.find( pCourse ); @@ -235,6 +246,11 @@ void Profile::AddCategoryHighScore( StepsType st, RankingCategory rc, HighScore m_CategoryHighScores[st][rc].AddHighScore( hs, iIndexOut ); } +const HighScoreList& Profile::GetCategoryHighScoreList( StepsType st, RankingCategory rc ) const +{ + return ((Profile *)this)->m_CategoryHighScores[st][rc]; +} + HighScoreList& Profile::GetCategoryHighScoreList( StepsType st, RankingCategory rc ) { return m_CategoryHighScores[st][rc]; @@ -300,7 +316,7 @@ bool Profile::LoadGeneralDataFromDir( CString sDir ) return true; } -bool Profile::SaveGeneralDataToDir( CString sDir ) +bool Profile::SaveGeneralDataToDir( CString sDir ) const { CString sIniPath = sDir + PROFILE_INI; @@ -327,11 +343,11 @@ bool Profile::SaveGeneralDataToDir( CString sDir ) return ini.WriteFile(); } -void Profile::SaveSongScoresToDir( CString sDir ) +void Profile::SaveSongScoresToDir( CString sDir ) const { CHECKPOINT; - Profile* pProfile = this; + const Profile* pProfile = this; ASSERT( pProfile ); CString fn = sDir + SONG_SCORES_XML; @@ -366,7 +382,7 @@ void Profile::SaveSongScoresToDir( CString sDir ) LPXNode pStepsNode = pSongNode->AppendChild( "Steps" ); - HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps ); + const HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps ); pStepsNode->AppendChild( "StepsType", pSteps->m_StepsType ); pStepsNode->AppendChild( "Difficulty", pSteps->GetDifficulty() ); @@ -721,11 +737,11 @@ void Profile::LoadCourseScoresFromDirSM390a12( CString sDir ) } -void Profile::SaveCourseScoresToDir( CString sDir ) +void Profile::SaveCourseScoresToDir( CString sDir ) const { CHECKPOINT; - Profile* pProfile = this; + const Profile* pProfile = this; ASSERT( pProfile ); CString fn = sDir + COURSE_SCORES_XML; @@ -755,7 +771,7 @@ void Profile::SaveCourseScoresToDir( CString sDir ) LPXNode pStepsTypeNode = pCourseNode->AppendChild( "StepsType", st ); - HighScoreList &hsl = pProfile->GetCourseHighScoreList( pCourse, st ); + const HighScoreList &hsl = pProfile->GetCourseHighScoreList( pCourse, st ); pStepsTypeNode->AppendChild( hsl.CreateNode() ); } @@ -817,11 +833,11 @@ void Profile::LoadCourseScoresFromDir( CString sDir ) xml.SaveToFile( fn ); } -void Profile::SaveCategoryScoresToDir( CString sDir ) +void Profile::SaveCategoryScoresToDir( CString sDir ) const { CHECKPOINT; - Profile* pProfile = this; + const Profile* pProfile = this; ASSERT( pProfile ); CString fn = sDir + CATEGORY_SCORES_XML; @@ -845,7 +861,7 @@ void Profile::SaveCategoryScoresToDir( CString sDir ) XNode* pRankingCategoryNode = pStepsTypeNode->AppendChild( "RankingCategory", rc ); - HighScoreList &hsl = pProfile->GetCategoryHighScoreList( (StepsType)st, (RankingCategory)rc ); + const HighScoreList &hsl = pProfile->GetCategoryHighScoreList( (StepsType)st, (RankingCategory)rc ); pRankingCategoryNode->AppendChild( hsl.CreateNode() ); } @@ -902,27 +918,27 @@ void Profile::LoadCategoryScoresFromDir( CString sDir ) } } -void Profile::DeleteSongScoresFromDirSM390a12( CString sDir ) +void Profile::DeleteSongScoresFromDirSM390a12( CString sDir ) const { CString fn = sDir + SM_390A12_SONG_SCORES_DAT; // FIXME } -void Profile::DeleteCourseScoresFromDirSM390a12( CString sDir ) +void Profile::DeleteCourseScoresFromDirSM390a12( CString sDir ) const { CString fn = sDir + SM_390A12_COURSE_SCORES_DAT; // FIXME } -void Profile::DeleteCategoryScoresFromDirSM390a12( CString sDir ) +void Profile::DeleteCategoryScoresFromDirSM390a12( CString sDir ) const { CString fn = sDir + SM_390A12_CATEGORY_SCORES_DAT; // FIXME } -void Profile::SaveStatsWebPageToDir( CString sDir ) +void Profile::SaveStatsWebPageToDir( CString sDir ) const { - Profile* pProfile = this; + const Profile* pProfile = this; CString fn = sDir + STATS_HTML; @@ -1203,7 +1219,7 @@ void Profile::SaveStatsWebPageToDir( CString sDir ) Steps* pSteps = pSong->GetStepsByDifficulty( st, dc, false ); if( pSteps ) { - HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps ); + const HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps ); CString sHighScore; if( !hsl.vHighScores.empty() ) { @@ -1331,7 +1347,7 @@ void Profile::SaveStatsWebPageToDir( CString sDir ) Steps* pSteps = vpSteps[j]; if( pSteps->IsAutogen() ) continue; // skip autogen - HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps ); + const HighScoreList &hsl = pProfile->GetStepsHighScoreList( pSteps ); CString s = GAMEMAN->NotesTypeToString(pSteps->m_StepsType) + " - " + @@ -1341,7 +1357,7 @@ void Profile::SaveStatsWebPageToDir( CString sDir ) for( unsigned i=0; im_sLastUsedHighScoreName; @@ -290,7 +290,7 @@ bool ProfileManager::DeleteLocalProfile( CString sProfileID ) return FILEMAN->Remove( sProfileDir ); } -void ProfileManager::SaveMachineScoresToDisk() +void ProfileManager::SaveMachineScoresToDisk() const { m_MachineProfile.SaveAllToDir( MACHINE_PROFILE_DIR ); } @@ -399,7 +399,7 @@ CString ProfileManager::GetProfileDir( ProfileSlot slot ) } } -Profile* ProfileManager::GetProfile( ProfileSlot slot ) +const Profile* ProfileManager::GetProfile( ProfileSlot slot ) const { switch( slot ) { @@ -420,7 +420,7 @@ Profile* ProfileManager::GetProfile( ProfileSlot slot ) // // Song stats // -int ProfileManager::GetSongNumTimesPlayed( Song* pSong, ProfileSlot slot ) +int ProfileManager::GetSongNumTimesPlayed( const Song* pSong, ProfileSlot slot ) const { return GetProfile(slot)->GetSongNumTimesPlayed( pSong ); } diff --git a/stepmania/src/ProfileManager.h b/stepmania/src/ProfileManager.h index 9890e3d2d6..9071599e87 100644 --- a/stepmania/src/ProfileManager.h +++ b/stepmania/src/ProfileManager.h @@ -55,8 +55,10 @@ public: return false; } } - Profile* GetProfile( PlayerNumber pn ); - Profile* GetProfile( ProfileSlot slot ); + const Profile* GetProfile( PlayerNumber pn ) const; + Profile* GetProfile( PlayerNumber pn ) { return (Profile*) ((const ProfileManager *) this)->GetProfile(pn); } + const Profile* GetProfile( ProfileSlot slot ) const; + Profile* GetProfile( ProfileSlot slot ) { return (Profile*) ((const ProfileManager *) this)->GetProfile(slot); } CString GetProfileDir( ProfileSlot slot ); Profile* GetMachineProfile() { return &m_MachineProfile; } @@ -69,13 +71,13 @@ public: // High scores // void InitMachineScoresFromDisk(); - void SaveMachineScoresToDisk(); + void SaveMachineScoresToDisk() const; // // Song stats // - int GetSongNumTimesPlayed( Song* pSong, ProfileSlot card ); - bool IsSongNew( Song* pSong ) { return GetSongNumTimesPlayed(pSong,PROFILE_SLOT_MACHINE)==0; } + int GetSongNumTimesPlayed( const Song* pSong, ProfileSlot card ) const; + bool IsSongNew( const Song* pSong ) const { return GetSongNumTimesPlayed(pSong,PROFILE_SLOT_MACHINE)==0; } void AddStepsHighScore( const Steps* pSteps, PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut ); void IncrementStepsPlayCount( const Steps* pSteps, PlayerNumber pn ); HighScore GetHighScoreForDifficulty( const Song *s, const StyleDef *st, ProfileSlot slot, Difficulty dc );