push song searching into a function
This commit is contained in:
+61
-49
@@ -51,7 +51,66 @@ Course::Course()
|
||||
}
|
||||
}
|
||||
|
||||
void Course::LoadFromCRSFile( CString sPath, vector<Song*> &apSongs )
|
||||
/*
|
||||
* 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 sSongDir)
|
||||
{
|
||||
const vector<Song*> &apSongs = SONGMAN->GetAllSongs();
|
||||
|
||||
CStringArray split_SongDir;
|
||||
sSongDir.Replace("\\", "/");
|
||||
split( sSongDir, "/", split_SongDir, true );
|
||||
|
||||
if( split_SongDir.size() > 2 )
|
||||
{
|
||||
LOG->Warn( "Course file \"%s\" path \"%s\" should contain "
|
||||
"at most one backslash; ignored.",
|
||||
m_sPath.GetString(), sSongDir.GetString());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// foreach song
|
||||
for( unsigned i = 0; i < apSongs.size(); i++ )
|
||||
{
|
||||
CString dir = apSongs[i]->GetSongDir();
|
||||
dir.Replace("\\", "/");
|
||||
CStringArray splitted; /* splat! */
|
||||
split( dir, "/", splitted, true );
|
||||
bool matches = true;
|
||||
|
||||
int split_no = splitted.size()-1;
|
||||
int SongDir_no = split_SongDir.size()-1;
|
||||
|
||||
while( split_no >= 0 && SongDir_no >= 0 ) {
|
||||
if( stricmp(splitted[split_no--], split_SongDir[SongDir_no--] ) )
|
||||
matches=false;
|
||||
}
|
||||
|
||||
if(matches)
|
||||
return apSongs[i];
|
||||
}
|
||||
|
||||
LOG->Trace( "Course \"%s\": couldn't match song \"%s\"",
|
||||
m_sPath.GetString(), sSongDir.GetString());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Course::LoadFromCRSFile( CString sPath )
|
||||
{
|
||||
m_sPath = sPath; // save path
|
||||
|
||||
@@ -105,55 +164,8 @@ void Course::LoadFromCRSFile( CString sPath, vector<Song*> &apSongs )
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 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 *pSong = FindSong(sSongDir);
|
||||
|
||||
CStringArray split_SongDir;
|
||||
sSongDir.Replace("\\", "/");
|
||||
split( sSongDir, "/", split_SongDir, true );
|
||||
|
||||
if( split_SongDir.size() > 2 )
|
||||
{
|
||||
LOG->Warn( "Course file \"%s\" path \"%s\" should contain "
|
||||
"at most one backslash; ignored.",
|
||||
(const char *) sPath, (const char *) sSongDir);
|
||||
continue;
|
||||
}
|
||||
|
||||
Song *pSong = NULL;
|
||||
// foreach song
|
||||
for( unsigned i = 0; pSong == NULL && i < apSongs.size(); i++ )
|
||||
{
|
||||
CString dir = apSongs[i]->GetSongDir();
|
||||
dir.Replace("\\", "/");
|
||||
CStringArray splitted;
|
||||
split( dir, "/", splitted, true );
|
||||
bool matches = true;
|
||||
|
||||
int split_no = splitted.size()-1;
|
||||
int SongDir_no = split_SongDir.size()-1;
|
||||
|
||||
while( split_no >= 0 && SongDir_no >= 0 ) {
|
||||
if( stricmp(splitted[split_no--], split_SongDir[SongDir_no--] ) )
|
||||
matches=false;
|
||||
}
|
||||
|
||||
if(matches)
|
||||
pSong = apSongs[i];
|
||||
}
|
||||
if( pSong == NULL ) // we didn't find the Song
|
||||
continue; // skip this song
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
void GetSongOptions( SongOptions* pSO_out) const;
|
||||
int GetNumStages() const;
|
||||
|
||||
void LoadFromCRSFile( CString sPath, vector<Song*> &apSongs );
|
||||
void LoadFromCRSFile( CString sPath );
|
||||
void CreateEndlessCourseFromGroupAndDifficulty( CString sGroupName, Difficulty dc, vector<Song*> &apSongsInGroup );
|
||||
void AddStage( Song* pSong, CString sDescription, CString sModifiers );
|
||||
|
||||
@@ -77,6 +77,7 @@ public:
|
||||
|
||||
private:
|
||||
void Shuffle();
|
||||
Song *FindSong(CString sSongDir);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -44,6 +44,10 @@ RageColor g_ExtraColor;
|
||||
|
||||
SongManager::SongManager( LoadingWindow *ld )
|
||||
{
|
||||
/* We initialize things that assume they can get at SONGMAN; we only
|
||||
* init one of these, so hook us up to it immediately. */
|
||||
SONGMAN = this;
|
||||
|
||||
g_vGroupColors.clear();
|
||||
for( int i=0; i<NUM_GROUP_COLORS; i++ )
|
||||
g_vGroupColors.push_back( GROUP_COLOR(i) );
|
||||
@@ -427,7 +431,7 @@ void SongManager::InitCoursesFromDisk()
|
||||
for( unsigned i=0; i<saCourseFiles.size(); i++ )
|
||||
{
|
||||
Course* pCourse = new Course;
|
||||
pCourse->LoadFromCRSFile( saCourseFiles[i], m_pSongs );
|
||||
pCourse->LoadFromCRSFile( saCourseFiles[i] );
|
||||
if( pCourse->GetNumStages() > 0 )
|
||||
m_pCourses.push_back( pCourse );
|
||||
else
|
||||
@@ -549,7 +553,7 @@ bool SongManager::GetExtraStageInfoFromCourse( bool bExtra2, CString sPreferredG
|
||||
}
|
||||
|
||||
Course course;
|
||||
course.LoadFromCRSFile( sCoursePath, m_pSongs );
|
||||
course.LoadFromCRSFile( sCoursePath );
|
||||
if( course.GetNumStages() <= 0 ) return false;
|
||||
|
||||
pSongOut = course.GetSong(0);
|
||||
|
||||
Reference in New Issue
Block a user