From 71b2199fb2abe0b3c351a5b27913e8b7a393325f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 22 Jul 2003 05:45:30 +0000 Subject: [PATCH] Move the rest of song searching logic into SONGMAN. --- stepmania/src/Course.cpp | 53 ++++------------------------------ stepmania/src/Course.h | 1 - stepmania/src/SongManager.cpp | 31 ++++++++++++++++++++ stepmania/src/SongManager.h | 3 +- stepmania/src/UnlockSystem.cpp | 2 +- 5 files changed, 40 insertions(+), 50 deletions(-) diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index 64775c6589..04f959e5bf 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -66,35 +66,6 @@ void Course::SetDefaultScore() } } -/* - * GetSongDir() contains a path to the song, possibly a full path, eg: - * Songs\Group\SongName or - * My Other Song Folder\Group\SongName or - * c:\Corny J-pop\Group\SongName - * - * Most course group names are "Group\SongName", so we want to - * match against the last two elements. Let's also support - * "SongName" alone, since the group is only important when it's - * potentially ambiguous. - * - * Let's *not* support "Songs\Group\SongName" in course files. - * That's probably a common error, but that would result in - * course files floating around that only work for people who put - * songs in "Songs"; we don't want that. - */ - -Song *Course::FindSong(CString sGroup, CString sSong) const -{ - Song *pSong = SONGMAN->FindSong( sGroup, sSong ); - if( pSong ) - return pSong; - - LOG->Trace( "Course file '%s' contains a song '%s%s%s' that is not present", - m_sPath.c_str(), sGroup.c_str(), sGroup.size()? "/":"", sSong.c_str()); - - return NULL; -} - PlayMode Course::GetPlayMode() const { if( IsNonstop() ) @@ -244,27 +215,15 @@ void Course::LoadFromCRSFile( CString sPath ) new_entry.type = Entry::fixed; CString sSong = sParams[1]; - sSong.Replace( "\\", "/" ); - CStringArray bits; - split( sSong, "/", bits ); - if( bits.size() == 1 ) - new_entry.pSong = FindSong( "", bits[0] ); - else if( bits.size() == 2 ) - new_entry.pSong = FindSong( bits[0], bits[1] ); - else - { - LOG->Warn( "Course file '%s' contains a fixed song entry '%s' that is invalid. " - "Song should be in the format '/'.", - m_sPath.c_str(), sSong.c_str()); - continue; // skip this #SONG - } - if( !new_entry.pSong ) + new_entry.pSong = SONGMAN->FindSong( sSong ); + + if( new_entry.pSong == NULL ) { /* XXX: We need a place to put "user warnings". This is too loud for info.txt-- * it obscures important warnings--and regular users never look there, anyway. */ - //LOG->Warn( "Course file '%s' contains a fixed song entry '%s' that does not exist. " - // "This entry will be ignored.", - // m_sPath.c_str(), sSong.c_str()); + LOG->Trace( "Course file '%s' contains a fixed song entry '%s' that does not exist. " + "This entry will be ignored.", + m_sPath.c_str(), sSong.c_str()); continue; // skip this #SONG } } diff --git a/stepmania/src/Course.h b/stepmania/src/Course.h index 4fb1d19a0d..21fb3f514b 100644 --- a/stepmania/src/Course.h +++ b/stepmania/src/Course.h @@ -122,7 +122,6 @@ public: private: - Song *FindSong(CString sGroup, CString sSong) const; void SetDefaultScore(); void GetMeterRange( int stage, int& iMeterLowOut, int& iMeterHighOut ) const; }; diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 3ed4caaaed..241d00d9a3 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -1076,6 +1076,37 @@ void SongManager::AddScores( NotesType nt, bool bPlayerEnabled[NUM_PLAYERS], } } +/* + * GetSongDir() contains a path to the song, possibly a full path, eg: + * Songs\Group\SongName or + * My Other Song Folder\Group\SongName or + * c:\Corny J-pop\Group\SongName + * + * Most course group names are "Group\SongName", so we want to + * match against the last two elements. Let's also support + * "SongName" alone, since the group is only important when it's + * potentially ambiguous. + * + * Let's *not* support "Songs\Group\SongName" in course files. + * That's probably a common error, but that would result in + * course files floating around that only work for people who put + * songs in "Songs"; we don't want that. + */ + +Song *SongManager::FindSong( CString sPath ) +{ + sPath.Replace( "\\", "/" ); + CStringArray bits; + split( sPath, "/", bits ); + + if( bits.size() == 1 ) + return FindSong( "", bits[0] ); + else if( bits.size() == 2 ) + return FindSong( bits[0], bits[1] ); + + return NULL; +} + Song *SongManager::FindSong( CString sGroup, CString sSong ) { // foreach song diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h index ef891ba9d2..83c059f130 100644 --- a/stepmania/src/SongManager.h +++ b/stepmania/src/SongManager.h @@ -67,7 +67,7 @@ public: void GetSongs( vector &AddTo, CString sGroupName, int iMaxStages = 100000 /*inf*/ ) const; void GetSongs( vector &AddTo, int iMaxStages ) const { GetSongs(AddTo,"",iMaxStages); } void GetSongs( vector &AddTo ) const { GetSongs(AddTo,"",100000 /*inf*/ ); } - Song *FindSong( CString sGroup, CString sSong ); + Song *FindSong( CString sPath ); Course *FindCourse( CString sName ); int GetNumSongs() const; int GetNumGroups() const; @@ -120,6 +120,7 @@ protected: void ReadCourseScoresFromFile( CString fn, int c ); void ReadCategoryRankingsFromFile( CString fn ); void ReadCourseRankingsFromFile( CString fn ); + Song *FindSong( CString sGroup, CString sSong ); vector m_pSongs; // all songs that can be played vector m_pBestSongs; diff --git a/stepmania/src/UnlockSystem.cpp b/stepmania/src/UnlockSystem.cpp index 2ffedddada..2c0fdef1b6 100644 --- a/stepmania/src/UnlockSystem.cpp +++ b/stepmania/src/UnlockSystem.cpp @@ -333,7 +333,7 @@ void UnlockSystem::UpdateSongs() { m_SongEntries[i].m_pSong = NULL; m_SongEntries[i].m_pCourse = NULL; - m_SongEntries[i].m_pSong = SONGMAN->FindSong( "", m_SongEntries[i].m_sSongName ); + m_SongEntries[i].m_pSong = SONGMAN->FindSong( m_SongEntries[i].m_sSongName ); if( m_SongEntries[i].m_pSong == NULL ) m_SongEntries[i].m_pCourse = SONGMAN->FindCourse( m_SongEntries[i].m_sSongName ); }