From a93fbd11bd99bd24e065ce1634f6d18cd39834c8 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 8 Dec 2003 06:41:30 +0000 Subject: [PATCH] fix machine profile saving --- stepmania/src/GameState.cpp | 25 ++++++--- stepmania/src/ProfileManager.cpp | 94 ++++++++++++++++++++++++++++---- stepmania/src/StepMania.cpp | 6 ++ stepmania/src/song.h | 1 + 4 files changed, 109 insertions(+), 17 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index e381639fa5..49a44cc68d 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -167,6 +167,8 @@ void GameState::EndGame() if( iPlaySeconds < 0 ) iPlaySeconds = 0; + Profile* pMachineProfile = PROFILEMAN->GetMachineProfile(); + for( int p=0; pGetProfile( (PlayerNumber)p ); - if( pProfile==NULL ) - continue; + Profile* pPlayerProfile = PROFILEMAN->GetProfile( (PlayerNumber)p ); - pProfile->m_iTotalPlaySeconds += iPlaySeconds; - pProfile->m_iTotalGameplaySeconds += iGameplaySeconds; - pProfile->m_iTotalPlays++; - pProfile->m_iCurrentCombo = + pMachineProfile->m_iTotalPlaySeconds += iPlaySeconds; + pMachineProfile->m_iTotalGameplaySeconds += iGameplaySeconds; + + if( pPlayerProfile ) + pPlayerProfile->m_iTotalPlaySeconds += iPlaySeconds; + if( pPlayerProfile ) + pPlayerProfile->m_iTotalGameplaySeconds += iGameplaySeconds; + if( pPlayerProfile ) + pPlayerProfile->m_iTotalPlays++; + if( pPlayerProfile ) + pPlayerProfile->m_iCurrentCombo = PREFSMAN->m_bComboContinuesBetweenSongs ? GAMESTATE->m_CurStageStats.iCurCombo[p] : 0; } + pMachineProfile->m_iTotalPlays++; + pMachineProfile->m_iCurrentCombo = 0; + + BOOKKEEPER->WriteToDisk(); PROFILEMAN->SaveMachineScoresToDisk(); } diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index e223efd0b2..cad1bdfef8 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -128,6 +128,8 @@ bool ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIs bool ProfileManager::CreateProfile( CString sProfileDir, CString sName ) { + ASSERT( !sName.empty() ); + bool bResult; Profile pro; @@ -345,6 +347,8 @@ bool ProfileManager::DeleteLocalProfile( CString sProfileID ) void ProfileManager::SaveMachineScoresToDisk() { + m_MachineProfile.SaveToIni( MACHINE_PROFILE_DIR PROFILE_FILE ); + SaveCategoryScoresToFile( MACHINE_PROFILE_DIR CATEGORY_SCORES_FILE, MEMORY_CARD_MACHINE ); SaveSongScoresToFile( MACHINE_PROFILE_DIR SONG_SCORES_FILE, MEMORY_CARD_MACHINE ); SaveCourseScoresToFile( MACHINE_PROFILE_DIR COURSE_SCORES_FILE, MEMORY_CARD_MACHINE ); @@ -589,6 +593,12 @@ void ProfileManager::InitMachineScoresFromDisk() ReadCategoryScoresFromFile( MACHINE_PROFILE_DIR CATEGORY_SCORES_FILE, MEMORY_CARD_MACHINE ); ReadSongScoresFromFile( MACHINE_PROFILE_DIR SONG_SCORES_FILE, MEMORY_CARD_MACHINE ); ReadCourseScoresFromFile( MACHINE_PROFILE_DIR COURSE_SCORES_FILE, MEMORY_CARD_MACHINE ); + + if( !m_MachineProfile.LoadFromIni(MACHINE_PROFILE_DIR PROFILE_FILE) ) + { + CreateProfile(MACHINE_PROFILE_DIR, "Machine"); + m_MachineProfile.LoadFromIni(MACHINE_PROFILE_DIR PROFILE_FILE); + } } void ProfileManager::ReadSM300NoteScores() @@ -858,6 +868,19 @@ static CString HTMLQuoteDoubleQuotes( CString str ) void ProfileManager::SaveStatsWebPageToFile( CString fn, MemoryCard mc ) { + // + // Get Profile + // + Profile* pProfile; + if( mc == MEMORY_CARD_MACHINE ) + pProfile = GetMachineProfile(); + else + pProfile = GetProfile( (PlayerNumber)mc ); + ASSERT(pProfile); + + // + // Open file + // RageFile f; if( !f.Open( fn, RageFile::WRITE ) ) { @@ -865,6 +888,15 @@ void ProfileManager::SaveStatsWebPageToFile( CString fn, MemoryCard mc ) return; } + // + // Make local song list + // + vector vpSongs = SONGMAN->GetAllSongs(); + SortSongPointerArrayByGroupAndTitle( vpSongs ); + + // + // print HTML headers + // f.PutLine( "" ); f.PutLine( "" ); f.PutLine( "" ); @@ -872,35 +904,77 @@ void ProfileManager::SaveStatsWebPageToFile( CString fn, MemoryCard mc ) f.PutLine( "" ); f.PutLine( "" ); - vector vpSongs = SONGMAN->GetAllSongs(); - SortSongPointerArrayByGroupAndTitle( vpSongs ); + // + // Print table of contents + // + f.PutLine( "

Table of Contents


\n" ); + f.PutLine( "My Statistics
\n" ); + f.PutLine( "Song/Steps List
\n" ); + f.PutLine( "Difficulty Table
\n" ); + f.PutLine( "
\n" ); + + // + // Print My Statistics + // + f.PutLine( "

My Statistics


top\n" ); + f.PutLine( "" ); +#define PRINT_STAT_S(szName,sVal) f.Write( ssprintf("\n",szName,sVal.c_str()) ) +#define PRINT_STAT_B(szName,bVal) f.Write( ssprintf("\n",szName,bVal?"yes":"no") ) +#define PRINT_STAT_I(szName,iVal) f.Write( ssprintf("\n",szName,iVal) ) + if( pProfile->m_sLastUsedHighScoreName.empty() ) + PRINT_STAT_S( "Name", pProfile->m_sName ); + else + PRINT_STAT_S( "Name", pProfile->m_sLastUsedHighScoreName ); + PRINT_STAT_B( "UsingProfileDefaultModifiers", pProfile->m_bUsingProfileDefaultModifiers ); + PRINT_STAT_S( "DefaultModifiers", pProfile->m_sDefaultModifiers ); + PRINT_STAT_I( "TotalPlays", pProfile->m_iTotalPlays ); + PRINT_STAT_I( "TotalPlaySeconds", pProfile->m_iTotalPlaySeconds ); + PRINT_STAT_I( "TotalGameplaySeconds", pProfile->m_iTotalGameplaySeconds ); + PRINT_STAT_I( "CurrentCombo", pProfile->m_iCurrentCombo ); +//#undef PRINT_STAT_S +//#undef PRINT_STAT_B +//#undef PRINT_STAT_I + f.PutLine( "
%s%s
%s%s
%s%d
\n
" ); // // Print song list // - f.PutLine( "" ); + f.PutLine( "

Song/Steps List

top
\n" ); for( unsigned i=0; i" ); + f.PutLine( "
" ); /* XXX: We can't call pSong->HasBanner on every song; it'll effectively re-traverse the entire * song directory tree checking if each banner file really exists. * * (Note for testing this: remember that we'll cache directories for a time; this is only slow if * the directory cache expires before we get here.) */ + /* Don't print the song banner anyway since this is going on the memory card. -Chris */ //CString sImagePath = pSong->HasBanner() ? pSong->GetBannerPath() : (pSong->HasBackground() ? pSong->GetBackgroundPath() : "" ); - f.Write( "" ); - f.Write( ssprintf("", pSong->GetTranslitArtist().c_str()) ); - f.PutLine( "" ); + PRINT_STAT_S( "MainTitle", pSong->GetTranslitMainTitle() ); + PRINT_STAT_S( "SubTitle", pSong->GetTranslitSubTitle() ); + PRINT_STAT_S( "Artist", pSong->GetTranslitArtist() ); + + // + // Print Steps list + // + vector vpSteps = pSong->GetAllSteps(); + for( unsigned j=0; jIsAutogen() ) + continue; + PRINT_STAT_S( "Difficulty", DifficultyToString(pSteps->GetDifficulty()) ); + } + + f.PutLine( "
%s
", pSong->GetTranslitMainTitle().c_str()) ); - f.Write( ssprintf("%s
", pSong->GetTranslitSubTitle().c_str()) ); - f.Write( ssprintf("%s
\n
" ); } - f.PutLine( "\n
" ); // // Print steps tables // + f.PutLine( "

Difficulty Table

top
\n" ); for( int g=0; gReloadMetrics(); TEXTUREMAN->ReloadAll(); + + // HACK: Also save bookkeeping and profile info for debugging + // so we don't have to play through a whole song to get new output. + BOOKKEEPER->WriteToDisk(); + PROFILEMAN->SaveMachineScoresToDisk(); + SCREENMAN->SystemMessage( "Reloaded metrics and textures" ); return true; } diff --git a/stepmania/src/song.h b/stepmania/src/song.h index 520c5275d5..e21bab8fd8 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -243,6 +243,7 @@ public: bool SongCompleteForStyle( const StyleDef *st ) const; bool SongHasNotesType( StepsType nt ) const; bool SongHasNotesTypeAndDifficulty( StepsType nt, Difficulty dc ) const; + const vector& GetAllSteps() const { return m_apNotes; } void GetSteps( vector& arrayAddTo, StepsType nt, Difficulty dc = DIFFICULTY_INVALID, int iMeterLow = -1, int iMeterHigh = -1, CString sDescription = "", bool bIncludeAutoGen = true ) const; Steps* GetStepsByDifficulty( StepsType nt, Difficulty dc, bool bIncludeAutoGen = true ) const; Steps* GetStepsByMeter( StepsType nt, int iMeterLow, int iMeterHigh, bool bIncludeAutoGen = true ) const;