From 42f39c7ab9bc7034b9d581a4262b73b3a5921ea9 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Wed, 8 Jun 2011 21:58:45 -0400 Subject: [PATCH] Restrict course editor to playable songs. This does not yet deal with songs with charts in multiple game types. ...at least, as far as I know. --- src/ScreenOptionsEditCourse.cpp | 2 +- src/SongUtil.cpp | 21 +++++++++++++++++++-- src/SongUtil.h | 15 ++++++++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/ScreenOptionsEditCourse.cpp b/src/ScreenOptionsEditCourse.cpp index 6f5c6aa111..020f328c1d 100644 --- a/src/ScreenOptionsEditCourse.cpp +++ b/src/ScreenOptionsEditCourse.cpp @@ -145,7 +145,7 @@ void ScreenOptionsEditCourse::Init() sc.m_Tutorial = SongCriteria::Tutorial_No; sc.m_Locked = SongCriteria::Locked_Unlocked; - SongUtil::FilterSongs( sc, SONGMAN->GetAllSongs(), m_vpSongs ); + SongUtil::FilterSongs( sc, SONGMAN->GetAllSongs(), m_vpSongs, true ); SongUtil::SortSongPointerArrayByTitle( m_vpSongs ); } diff --git a/src/SongUtil.cpp b/src/SongUtil.cpp index b188a0c108..f13576fbc0 100644 --- a/src/SongUtil.cpp +++ b/src/SongUtil.cpp @@ -871,13 +871,15 @@ void SongUtil::GetAllSongGenres( vector &vsOut ) } } -void SongUtil::FilterSongs( const SongCriteria &sc, const vector &in, vector &out ) +void SongUtil::FilterSongs( const SongCriteria &sc, const vector &in, + vector &out, bool doCareAboutGame ) { out.reserve( in.size() ); FOREACH_CONST( Song*, in, s ) { - if( sc.Matches( *s ) ) + if( sc.Matches( *s ) && (!doCareAboutGame || IsSongPlayable(*s) ) ) { + out.push_back( *s ); } } @@ -963,6 +965,21 @@ bool SongUtil::IsStepsPlayable( Song *pSong, Steps *pSteps ) return find( vpSteps.begin(), vpSteps.end(), pSteps ) != vpSteps.end(); } +bool SongUtil::IsSongPlayable( Song *s ) +{ + const vector & steps = s->GetAllSteps(); + // I'm sure there is a foreach loop, but I don't + FOREACH( Steps*, const_cast&>(steps), step ) + { + if (IsStepsPlayable(s, *step)) + { + return true; + } + } + + return false; +} + bool SongUtil::GetStepsTypeAndDifficultyFromSortOrder( SortOrder so, StepsType &stOut, Difficulty &dcOut ) { switch( so ) diff --git a/src/SongUtil.h b/src/SongUtil.h index 0c0a18043d..5432d455e3 100644 --- a/src/SongUtil.h +++ b/src/SongUtil.h @@ -163,12 +163,25 @@ namespace SongUtil bool ValidateCurrentStepsCredit( const RString &sAnswer, RString &sErrorOut ); void GetAllSongGenres( vector &vsOut ); - void FilterSongs( const SongCriteria &sc, const vector &in, vector &out ); + /** + * @brief Filter the selection of songs to only match certain criteria. + * @param sc the intended song criteria. + * @param in the starting batch of songs. + * @param out the resulting batch. + * @param doCareAboutGame a flag to see if we should only get playable steps. */ + void FilterSongs( const SongCriteria &sc, const vector &in, vector &out, + bool doCareAboutGame = false ); void GetPlayableStepsTypes( const Song *pSong, set &vOut ); void GetPlayableSteps( const Song *pSong, vector &vOut ); bool IsStepsTypePlayable( Song *pSong, StepsType st ); bool IsStepsPlayable( Song *pSong, Steps *pSteps ); + + /** + * @brief Determine if the song has any playable steps in the present game. + * @param s the current song. + * @return true if the song has playable steps, false otherwise. */ + bool IsSongPlayable( Song *s ); bool GetStepsTypeAndDifficultyFromSortOrder( SortOrder so, StepsType &st, Difficulty &dc ); }