From f8694fe463ec1fd50f9c902186047bf153883854 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Fri, 11 Feb 2011 01:50:23 -0500 Subject: [PATCH] Add utility methods for step's #CREDIT tag. --- src/SongUtil.cpp | 45 +++++++++++++++++++++++++++++++++++++++++---- src/SongUtil.h | 10 +++++++--- src/StepsUtil.cpp | 4 ++-- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/SongUtil.cpp b/src/SongUtil.cpp index b206cf1fd2..11b102ddcd 100644 --- a/src/SongUtil.cpp +++ b/src/SongUtil.cpp @@ -97,7 +97,8 @@ void SongUtil::GetSteps( Difficulty dc, int iMeterLow, int iMeterHigh, - const RString &sDescription, + const RString &sDescription, + const RString &sCredit, bool bIncludeAutoGen, unsigned uHash, int iMaxToGet @@ -119,6 +120,8 @@ void SongUtil::GetSteps( continue; if( sDescription.size() && sDescription != pSteps->GetDescription() ) continue; + if( sCredit.size() && sCredit != pSteps->GetCredit() ) + continue; if( uHash != 0 && uHash != pSteps->GetHash() ) continue; if( !bIncludeAutoGen && pSteps->IsAutogen() ) @@ -141,13 +144,14 @@ Steps* SongUtil::GetOneSteps( Difficulty dc, int iMeterLow, int iMeterHigh, - const RString &sDescription, + const RString &sDescription, + const RString &sCredit, unsigned uHash, bool bIncludeAutoGen ) { vector vpSteps; - GetSteps( pSong, vpSteps, st, dc, iMeterLow, iMeterHigh, sDescription, bIncludeAutoGen, uHash, 1 ); // get max 1 + GetSteps( pSong, vpSteps, st, dc, iMeterLow, iMeterHigh, sDescription, sCredit, bIncludeAutoGen, uHash, 1 ); // get max 1 if( vpSteps.empty() ) return NULL; else @@ -193,13 +197,23 @@ Steps* SongUtil::GetStepsByMeter( const Song *pSong, StepsType st, int iMeterLow Steps* SongUtil::GetStepsByDescription( const Song *pSong, StepsType st, RString sDescription ) { vector vNotes; - GetSteps( pSong, vNotes, st, Difficulty_Invalid, -1, -1, sDescription ); + GetSteps( pSong, vNotes, st, Difficulty_Invalid, -1, -1, sDescription, "" ); if( vNotes.size() == 0 ) return NULL; else return vNotes[0]; } +Steps* SongUtil::GetStepsByCredit( const Song *pSong, StepsType st, RString sCredit ) +{ + vector vNotes; + GetSteps(pSong, vNotes, st, Difficulty_Invalid, -1, -1, "", sCredit ); + if( vNotes.size() == 0 ) + return NULL; + else + return vNotes[0]; +} + Steps* SongUtil::GetClosestNotes( const Song *pSong, StepsType st, Difficulty dc, bool bIgnoreLocked ) { @@ -803,6 +817,29 @@ bool SongUtil::ValidateCurrentStepsDescription( const RString &sAnswer, RString return true; } +static LocalizedString AUTHOR_NAME_CANNOT_CONTAIN( "SongUtil", "The step author's name cannot contain any of the following characters: %s" ); + +bool SongUtil::ValidateCurrentStepsCredit( const RString &sAnswer, RString &sErrorOut ) +{ + if( sAnswer.empty() ) + return true; + + Steps *pSteps = GAMESTATE->m_pCurSteps[PLAYER_1]; + // If unchanged: + if( pSteps->GetCredit() == sAnswer ) + return true; + + // Borrow from EditDescription testing. Perhaps this should be abstracted? -Wolfman2000 + static const RString sInvalidChars = "\\/:*?\"<>|"; + if( strpbrk(sAnswer, sInvalidChars) != NULL ) + { + sErrorOut = ssprintf( AUTHOR_NAME_CANNOT_CONTAIN.GetValue(), sInvalidChars.c_str() ); + return false; + } + + return true; +} + void SongUtil::GetAllSongGenres( vector &vsOut ) { set genres; diff --git a/src/SongUtil.h b/src/SongUtil.h index 7dabb69e88..be42f8a7c9 100644 --- a/src/SongUtil.h +++ b/src/SongUtil.h @@ -70,7 +70,8 @@ namespace SongUtil Difficulty dc = Difficulty_Invalid, int iMeterLow = -1, int iMeterHigh = -1, - const RString &sDescription = "", + const RString &sDescription = "", + const RString &sCredit = "", bool bIncludeAutoGen = true, unsigned uHash = 0, int iMaxToGet = -1 @@ -81,15 +82,17 @@ namespace SongUtil Difficulty dc = Difficulty_Invalid, int iMeterLow = -1, int iMeterHigh = -1, - const RString &sDescription = "", + const RString &sDescription = "", + const RString &sCredit = "", unsigned uHash = 0, bool bIncludeAutoGen = true ); Steps* GetStepsByDifficulty( const Song *pSong, StepsType st, Difficulty dc, bool bIncludeAutoGen = true ); Steps* GetStepsByMeter( const Song *pSong, StepsType st, int iMeterLow, int iMeterHigh ); Steps* GetStepsByDescription( const Song *pSong, StepsType st, RString sDescription ); + Steps* GetStepsByCredit( const Song *pSong, StepsType st, RString sCredit ); Steps* GetClosestNotes( const Song *pSong, StepsType st, Difficulty dc, bool bIgnoreLocked=false ); - + void AdjustDuplicateSteps( Song *pSong ); // part of TidyUpData void DeleteDuplicateSteps( Song *pSong, vector &vSteps ); @@ -115,6 +118,7 @@ namespace SongUtil RString MakeUniqueEditDescription( const Song* pSong, StepsType st, const RString &sPreferredDescription ); bool ValidateCurrentEditStepsDescription( const RString &sAnswer, RString &sErrorOut ); bool ValidateCurrentStepsDescription( const RString &sAnswer, RString &sErrorOut ); + bool ValidateCurrentStepsCredit( const RString &sAnswer, RString &sErrorOut ); void GetAllSongGenres( vector &vsOut ); void FilterSongs( const SongCriteria &sc, const vector &in, vector &out ); diff --git a/src/StepsUtil.cpp b/src/StepsUtil.cpp index 30dee5b56c..f2f4afd9f5 100644 --- a/src/StepsUtil.cpp +++ b/src/StepsUtil.cpp @@ -258,11 +258,11 @@ Steps *StepsID::ToSteps( const Song *p, bool bAllowNull ) const Steps *pRet = NULL; if( dc == Difficulty_Edit ) { - pRet = SongUtil::GetOneSteps( p, st, dc, -1, -1, sDescription, uHash, true ); + pRet = SongUtil::GetOneSteps( p, st, dc, -1, -1, sDescription, "", uHash, true ); } else { - pRet = SongUtil::GetOneSteps( p, st, dc, -1, -1, "", 0, true ); + pRet = SongUtil::GetOneSteps( p, st, dc, -1, -1, "", "", 0, true ); } if( !bAllowNull && pRet == NULL )