From e00b7f36160b9bd04c4c9f94f98e843e034fb81b Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 14:01:55 -0400 Subject: [PATCH] [notesloader] Some refactoring done. --- src/NotesLoaderSM.cpp | 23 +++++++++++++++++++---- src/NotesLoaderSM.h | 29 +++++++++++++++++++++++++++-- src/NotesLoaderSMA.cpp | 33 ++------------------------------- src/NotesLoaderSMA.h | 12 +----------- src/NotesLoaderSSC.cpp | 10 +++++++--- 5 files changed, 56 insertions(+), 51 deletions(-) diff --git a/src/NotesLoaderSM.cpp b/src/NotesLoaderSM.cpp index f18c556056..68a0f7d089 100644 --- a/src/NotesLoaderSM.cpp +++ b/src/NotesLoaderSM.cpp @@ -16,7 +16,22 @@ /** @brief The maximum file size for edits. */ const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60KB -void SMLoader::LoadFromSMTokens( +float SMLoader::RowToBeat( RString line, const int rowsPerBeat ) +{ + RString backup = line; + Trim(line, "r"); + Trim(line, "R"); + if( backup != line ) + { + return StringToFloat( line ) / rowsPerBeat; + } + else + { + return StringToFloat( line ); + } +} + +void SMLoader::LoadFromTokens( RString sStepsType, RString sDescription, RString sDifficulty, @@ -34,7 +49,7 @@ void SMLoader::LoadFromSMTokens( Trim( sDifficulty ); Trim( sNoteData ); - // LOG->Trace( "Steps::LoadFromSMTokens()" ); + // LOG->Trace( "Steps::LoadFromTokens()" ); // insert stepstype hacks from GameManager.cpp here? -aj out.m_StepsType = GAMEMAN->StringToStepsType( sStepsType ); @@ -719,7 +734,7 @@ bool SMLoader::LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache } Steps* pNewNotes = out.CreateSteps(); - LoadFromSMTokens( + LoadFromTokens( sParams[1], sParams[2], sParams[3], @@ -853,7 +868,7 @@ bool SMLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath return true; Steps* pNewNotes = pSong->CreateSteps(); - LoadFromSMTokens( + LoadFromTokens( sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6], *pNewNotes); diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index 0d947ea28a..3c635a2fb8 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -19,8 +19,6 @@ const float FAST_BPM_WARP = 9999999.f; struct SMLoader { virtual ~SMLoader() {} - void LoadFromSMTokens( RString sStepsType, RString sDescription, RString sDifficulty, - RString sMeter, RString sRadarValues, RString sNoteData, Steps &out ); bool LoadFromDir( const RString &sPath, Song &out ); void TidyUpData( Song &song, bool bFromCache ); @@ -43,6 +41,33 @@ struct SMLoader const RString &sPath, const RString &sParam ); void ProcessAttacks( Song &out, MsdFile::value_t sParams ); void ProcessInstrumentTracks( Song &out, const RString &sParam ); + + /** + * @brief Convert a row value to the proper beat value. + * + * This is primarily used for assistance with converting SMA files. + * @param line The line that contains the value. + * @param rowsPerBeat the number of rows per beat according to the original file. + * @return the converted beat value. */ + float RowToBeat(RString line, const int rowsPerBeat); + +protected: + /** + * @brief Process the different tokens we have available to get NoteData. + * @param stepsType The current StepsType. + * @param description The description of the chart. + * @param difficulty The difficulty (in words) of the chart. + * @param meter the difficulty (in numbers) of the chart. + * @param radarValues the calculated radar values. + * @param noteData the note data itself. + * @param out the Steps getting the data. */ + virtual void LoadFromTokens(RString sStepsType, + RString sDescription, + RString sDifficulty, + RString sMeter, + RString sRadarValues, + RString sNoteData, + Steps &out); }; #endif diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp index c902b1f103..069724542a 100644 --- a/src/NotesLoaderSMA.cpp +++ b/src/NotesLoaderSMA.cpp @@ -39,19 +39,6 @@ bool SMALoader::LoadFromDir( const RString &sPath, Song &out ) return LoadFromSMAFile( sPath + aFileNames[0], out ); } -float SMALoader::RowToBeat( RString sLine, const int iRowsPerBeat ) -{ - if( sLine.find("R") || sLine.find("r") ) - { - sLine = sLine.Left(sLine.size()-1); - return StringToFloat( sLine ) / iRowsPerBeat; - } - else - { - return StringToFloat( sLine ); - } -} - bool SMALoader::ProcessBPMs( TimingData &out, const int iRowsPerBeat, const RString sParam ) { vector arrayBPMChangeExpressions; @@ -391,22 +378,6 @@ void SMALoader::ProcessFakes( TimingData &out, const int iRowsPerBeat, const RSt } } - -void SMALoader::LoadFromSMATokens( - RString sStepsType, - RString sDescription, - RString sDifficulty, - RString sMeter, - RString sRadarValues, - RString sNoteData, - Steps &out -) -{ - SMLoader::LoadFromSMTokens( sStepsType, sDescription, - sDifficulty, sMeter, sRadarValues, - sNoteData, out ); -} - void SMALoader::TidyUpData( Song &song, bool bFromCache ) { SMLoader::TidyUpData( song, bFromCache ); @@ -706,7 +677,7 @@ bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out ) continue; } - LoadFromSMATokens( + LoadFromTokens( sParams[1], sParams[2], sParams[3], @@ -815,7 +786,7 @@ bool SMALoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePat return true; Steps* pNewNotes = pSong->CreateSteps(); - LoadFromSMATokens( + LoadFromTokens( sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6], *pNewNotes); diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index fec87e8fce..31026f5089 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -22,15 +22,7 @@ enum SMALoadingStates /** @brief Reads a Song from a .SMA file. */ struct SMALoader : public SMLoader -{ - void LoadFromSMATokens( RString sStepsType, - RString sDescription, - RString sDifficulty, - RString sMeter, - RString sRadarValues, - RString sNoteData, - Steps &out ); - +{ bool LoadFromDir( const RString &sPath, Song &out ); void TidyUpData( Song &song, bool bFromCache ); @@ -50,8 +42,6 @@ struct SMALoader : public SMLoader void ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam ); void ProcessSpeeds( TimingData &out, const int iRowsPerBeat, const RString sParam ); void ProcessFakes( TimingData &out, const int iRowsPerBeat, const RString sParam ); - - float RowToBeat( RString sLine, const int iRowsPerBeat ); }; #endif diff --git a/src/NotesLoaderSSC.cpp b/src/NotesLoaderSSC.cpp index b9180850ae..54c7e208b5 100644 --- a/src/NotesLoaderSSC.cpp +++ b/src/NotesLoaderSSC.cpp @@ -872,9 +872,13 @@ bool SSCLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePat else { pNewNotes = pSong->CreateSteps(); - SMLoader::LoadFromSMTokens( - sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6], - *pNewNotes); + LoadFromTokens(sParams[1], + sParams[2], + sParams[3], + sParams[4], + sParams[5], + sParams[6], + *pNewNotes); } pNewNotes->SetLoadedFromProfile( slot );