Extract logic to NoteDataUtil::StringInterpretsAs
This commit is contained in:
@@ -11,6 +11,17 @@
|
||||
#include "TimingData.h"
|
||||
#include <utility>
|
||||
|
||||
bool NoteDataUtil::StringInterpretsAs( const std::string& str, int integer ) {
|
||||
try
|
||||
{
|
||||
return std::stoi( str ) == integer;
|
||||
}
|
||||
catch ( const std::invalid_argument & )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove these constants that aren't time signature-aware
|
||||
static const int BEATS_PER_MEASURE = 4;
|
||||
static const int ROWS_PER_MEASURE = ROWS_PER_BEAT * BEATS_PER_MEASURE;
|
||||
|
||||
@@ -23,6 +23,11 @@ void LightTransformHelper( const NoteData &in, NoteData &out, const vector<int>
|
||||
* and makes it much easier to change NoteData internally in the future. */
|
||||
namespace NoteDataUtil
|
||||
{
|
||||
/**
|
||||
* @brief Whether a string can be interpreted as the provided signed integer
|
||||
*/
|
||||
bool StringInterpretsAs( const std::string& str, int integer );
|
||||
|
||||
NoteType GetSmallestNoteTypeForMeasure( const NoteData &nd, int iMeasureIndex );
|
||||
NoteType GetSmallestNoteTypeInRange( const NoteData &nd, int iStartIndex, int iEndIndex );
|
||||
void LoadFromSMNoteDataString( NoteData &out, const RString &sSMNoteData, bool bComposite );
|
||||
|
||||
+7
-39
@@ -3,6 +3,7 @@
|
||||
#include "BackgroundUtil.h"
|
||||
#include "GameManager.h"
|
||||
#include "MsdFile.h"
|
||||
#include "NoteDataUtil.h"
|
||||
#include "NoteTypes.h"
|
||||
#include "RageFileManager.h"
|
||||
#include "RageLog.h"
|
||||
@@ -974,58 +975,25 @@ bool SMLoader::LoadFromBGChangesVector( BackgroundChange &change, std::vector<RS
|
||||
case 6:
|
||||
// param 7 overrides this.
|
||||
// Backward compatibility:
|
||||
if( change.m_def.m_sEffect.empty() )
|
||||
if( change.m_def.m_sEffect.empty() && !NoteDataUtil::StringInterpretsAs( aBGChangeValues[5], 0 ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( std::stoi( aBGChangeValues[5] ) != 0 )
|
||||
{
|
||||
change.m_def.m_sEffect = SBE_StretchNoLoop;
|
||||
}
|
||||
}
|
||||
catch ( const std::invalid_argument & )
|
||||
{
|
||||
// Failed conversions mean it's not 0 as well
|
||||
change.m_def.m_sEffect = SBE_StretchNoLoop;
|
||||
}
|
||||
change.m_def.m_sEffect = SBE_StretchNoLoop;
|
||||
}
|
||||
// fall through
|
||||
case 5:
|
||||
// param 7 overrides this.
|
||||
// Backward compatibility:
|
||||
if( change.m_def.m_sEffect.empty() )
|
||||
if( change.m_def.m_sEffect.empty() && !NoteDataUtil::StringInterpretsAs( aBGChangeValues[4], 0 ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( std::stoi( aBGChangeValues[4] ) != 0 )
|
||||
{
|
||||
change.m_def.m_sEffect = SBE_StretchRewind;
|
||||
}
|
||||
}
|
||||
catch ( const std::invalid_argument & )
|
||||
{
|
||||
// Failed conversions mean it's not 0 as well
|
||||
change.m_def.m_sEffect = SBE_StretchRewind;
|
||||
}
|
||||
change.m_def.m_sEffect = SBE_StretchRewind;
|
||||
}
|
||||
// fall through
|
||||
case 4:
|
||||
// param 9 overrides this.
|
||||
// Backward compatibility:
|
||||
if( change.m_sTransition.empty() )
|
||||
if( change.m_sTransition.empty() && !NoteDataUtil::StringInterpretsAs( aBGChangeValues[3], 0 ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( std::stoi( aBGChangeValues[3] ) != 0 )
|
||||
{
|
||||
change.m_sTransition = SBT_CrossFade;
|
||||
}
|
||||
}
|
||||
catch ( const std::invalid_argument & )
|
||||
{
|
||||
// Failed conversions mean it's not 0 as well
|
||||
change.m_sTransition = SBT_CrossFade;
|
||||
}
|
||||
change.m_sTransition = SBT_CrossFade;
|
||||
}
|
||||
// fall through
|
||||
case 3:
|
||||
|
||||
Reference in New Issue
Block a user