[notesloader] Simplify.
This commit is contained in:
+14
-13
@@ -94,11 +94,6 @@ void SMLoader::LoadFromTokens(
|
|||||||
out.TidyUpData();
|
out.TidyUpData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SMLoader::GetApplicableFiles( const RString &sPath, vector<RString> &out )
|
|
||||||
{
|
|
||||||
GetDirListing( sPath + RString("*.sm"), out );
|
|
||||||
}
|
|
||||||
|
|
||||||
void SMLoader::ProcessBGChanges( Song &out, const RString &sValueName, const RString &sPath, const RString &sParam )
|
void SMLoader::ProcessBGChanges( Song &out, const RString &sValueName, const RString &sPath, const RString &sParam )
|
||||||
{
|
{
|
||||||
BackgroundLayer iLayer = BACKGROUND_LAYER_1;
|
BackgroundLayer iLayer = BACKGROUND_LAYER_1;
|
||||||
@@ -357,10 +352,10 @@ void SMLoader::ProcessDelays( TimingData &out, const RString line, const int row
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SMLoader::ProcessTimeSignatures( TimingData &out, const RString sParam )
|
void SMLoader::ProcessTimeSignatures( TimingData &out, const RString line, const int rowsPerBeat )
|
||||||
{
|
{
|
||||||
vector<RString> vs1;
|
vector<RString> vs1;
|
||||||
split( sParam, ",", vs1 );
|
split( line, ",", vs1 );
|
||||||
|
|
||||||
FOREACH_CONST( RString, vs1, s1 )
|
FOREACH_CONST( RString, vs1, s1 )
|
||||||
{
|
{
|
||||||
@@ -373,9 +368,9 @@ void SMLoader::ProcessTimeSignatures( TimingData &out, const RString sParam )
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float fBeat = StringToFloat( vs2[0] );
|
const float fBeat = RowToBeat( vs2[0], rowsPerBeat );
|
||||||
|
|
||||||
TimeSignatureSegment seg( BeatToNoteRow( fBeat ), StringToInt( vs2[1] ), StringToInt( vs2[2] ));
|
TimeSignatureSegment seg( fBeat, StringToInt( vs2[1] ), StringToInt( vs2[2] ));
|
||||||
|
|
||||||
if( fBeat < 0 )
|
if( fBeat < 0 )
|
||||||
{
|
{
|
||||||
@@ -399,10 +394,10 @@ void SMLoader::ProcessTimeSignatures( TimingData &out, const RString sParam )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SMLoader::ProcessTickcounts( TimingData &out, const RString sParam )
|
void SMLoader::ProcessTickcounts( TimingData &out, const RString line, const int rowsPerBeat )
|
||||||
{
|
{
|
||||||
vector<RString> arrayTickcountExpressions;
|
vector<RString> arrayTickcountExpressions;
|
||||||
split( sParam, ",", arrayTickcountExpressions );
|
split( line, ",", arrayTickcountExpressions );
|
||||||
|
|
||||||
for( unsigned f=0; f<arrayTickcountExpressions.size(); f++ )
|
for( unsigned f=0; f<arrayTickcountExpressions.size(); f++ )
|
||||||
{
|
{
|
||||||
@@ -416,14 +411,15 @@ void SMLoader::ProcessTickcounts( TimingData &out, const RString sParam )
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float fTickcountBeat = StringToFloat( arrayTickcountValues[0] );
|
const float fTickcountBeat = RowToBeat( arrayTickcountValues[0], rowsPerBeat );
|
||||||
int iTicks = clamp(atoi( arrayTickcountValues[1] ), 0, ROWS_PER_BEAT);
|
int iTicks = clamp(atoi( arrayTickcountValues[1] ), 0, ROWS_PER_BEAT);
|
||||||
|
|
||||||
TickcountSegment new_seg( BeatToNoteRow(fTickcountBeat), iTicks );
|
TickcountSegment new_seg( fTickcountBeat, iTicks );
|
||||||
out.AddTickcountSegment( new_seg );
|
out.AddTickcountSegment( new_seg );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SMLoader::LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression )
|
bool SMLoader::LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression )
|
||||||
{
|
{
|
||||||
vector<RString> aBGChangeValues;
|
vector<RString> aBGChangeValues;
|
||||||
@@ -896,6 +892,11 @@ bool SMLoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SMLoader::GetApplicableFiles( const RString &sPath, vector<RString> &out )
|
||||||
|
{
|
||||||
|
GetDirListing( sPath + RString("*.sm"), out );
|
||||||
|
}
|
||||||
|
|
||||||
void SMLoader::TidyUpData( Song &song, bool bFromCache )
|
void SMLoader::TidyUpData( Song &song, bool bFromCache )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
|||||||
+21
-7
@@ -21,13 +21,13 @@ struct SMLoader
|
|||||||
virtual ~SMLoader() {}
|
virtual ~SMLoader() {}
|
||||||
|
|
||||||
bool LoadFromDir( const RString &sPath, Song &out );
|
bool LoadFromDir( const RString &sPath, Song &out );
|
||||||
void TidyUpData( Song &song, bool bFromCache );
|
virtual void TidyUpData( Song &song, bool bFromCache );
|
||||||
|
|
||||||
bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false );
|
bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false );
|
||||||
void GetApplicableFiles( const RString &sPath, vector<RString> &out );
|
void GetApplicableFiles( const RString &sPath, vector<RString> &out );
|
||||||
bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
|
virtual bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
|
||||||
bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot );
|
virtual bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot );
|
||||||
bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
|
virtual bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
|
||||||
virtual bool LoadFromBGChangesString(BackgroundChange &change,
|
virtual bool LoadFromBGChangesString(BackgroundChange &change,
|
||||||
const RString &sBGChangeExpression );
|
const RString &sBGChangeExpression );
|
||||||
|
|
||||||
@@ -49,15 +49,29 @@ struct SMLoader
|
|||||||
const RString line,
|
const RString line,
|
||||||
const int rowsPerBeat = -1);
|
const int rowsPerBeat = -1);
|
||||||
/**
|
/**
|
||||||
* @brief Process the Stop Segments from the string.
|
* @brief Process the Delay Segments from the string.
|
||||||
* @param out the TimingData being modified.
|
* @param out the TimingData being modified.
|
||||||
* @param line the string in question.
|
* @param line the string in question.
|
||||||
* @param rowsPerBeat the number of rows per beat for this purpose. */
|
* @param rowsPerBeat the number of rows per beat for this purpose. */
|
||||||
void ProcessDelays(TimingData & out,
|
void ProcessDelays(TimingData & out,
|
||||||
const RString line,
|
const RString line,
|
||||||
const int rowsPerBeat = -1);
|
const int rowsPerBeat = -1);
|
||||||
void ProcessTimeSignatures( TimingData & out, const RString line );
|
/**
|
||||||
void ProcessTickcounts( TimingData & out, const RString line );
|
* @brief Process the Time Signature Segments from the string.
|
||||||
|
* @param out the TimingData being modified.
|
||||||
|
* @param line the string in question.
|
||||||
|
* @param rowsPerBeat the number of rows per beat for this purpose. */
|
||||||
|
void ProcessTimeSignatures(TimingData & out,
|
||||||
|
const RString line,
|
||||||
|
const int rowsPerBeat = -1);
|
||||||
|
/**
|
||||||
|
* @brief Process the Tickcount Segments from the string.
|
||||||
|
* @param out the TimingData being modified.
|
||||||
|
* @param line the string in question.
|
||||||
|
* @param rowsPerBeat the number of rows per beat for this purpose. */
|
||||||
|
void ProcessTickcounts(TimingData & out,
|
||||||
|
const RString line,
|
||||||
|
const int rowsPerBeat = -1);
|
||||||
void ProcessBGChanges( Song &out, const RString &sValueName,
|
void ProcessBGChanges( Song &out, const RString &sValueName,
|
||||||
const RString &sPath, const RString &sParam );
|
const RString &sPath, const RString &sParam );
|
||||||
void ProcessAttacks( Song &out, MsdFile::value_t sParams );
|
void ProcessAttacks( Song &out, MsdFile::value_t sParams );
|
||||||
|
|||||||
+1
-147
@@ -19,12 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60 KB
|
const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60 KB
|
||||||
|
|
||||||
bool SMALoader::LoadFromBGChangesString( BackgroundChange &change,
|
|
||||||
const RString &sBGChangeExpression )
|
|
||||||
{
|
|
||||||
return SMLoader::LoadFromBGChangesString(change, sBGChangeExpression);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SMALoader::LoadFromDir( const RString &sPath, Song &out )
|
bool SMALoader::LoadFromDir( const RString &sPath, Song &out )
|
||||||
{
|
{
|
||||||
vector<RString> aFileNames;
|
vector<RString> aFileNames;
|
||||||
@@ -39,31 +33,6 @@ bool SMALoader::LoadFromDir( const RString &sPath, Song &out )
|
|||||||
return LoadFromSMAFile( sPath + aFileNames[0], out );
|
return LoadFromSMAFile( sPath + aFileNames[0], out );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SMALoader::ProcessTickcounts( TimingData &out, const int iRowsPerBeat, const RString sParam )
|
|
||||||
{
|
|
||||||
vector<RString> arrayTickcountExpressions;
|
|
||||||
split( sParam, ",", arrayTickcountExpressions );
|
|
||||||
|
|
||||||
for( unsigned f=0; f<arrayTickcountExpressions.size(); f++ )
|
|
||||||
{
|
|
||||||
vector<RString> arrayTickcountValues;
|
|
||||||
split( arrayTickcountExpressions[f], "=", arrayTickcountValues );
|
|
||||||
if( arrayTickcountValues.size() != 2 )
|
|
||||||
{
|
|
||||||
// XXX: Hard to tell which file caused this.
|
|
||||||
LOG->UserLog( "Song file", "(UNKNOWN)", "has an invalid #TICKCOUNTS value \"%s\" (must have exactly one '='), ignored.",
|
|
||||||
arrayTickcountExpressions[f].c_str() );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float fTickcountBeat = RowToBeat( arrayTickcountValues[0], iRowsPerBeat );
|
|
||||||
int iTicks = clamp(atoi( arrayTickcountValues[1] ), 0, ROWS_PER_BEAT);
|
|
||||||
|
|
||||||
TickcountSegment new_seg( BeatToNoteRow(fTickcountBeat), iTicks );
|
|
||||||
out.AddTickcountSegment( new_seg );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SMALoader::ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam )
|
void SMALoader::ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam )
|
||||||
{
|
{
|
||||||
vector<RString> arrayMultiplierExpressions;
|
vector<RString> arrayMultiplierExpressions;
|
||||||
@@ -207,11 +176,6 @@ void SMALoader::ProcessFakes( TimingData &out, const int iRowsPerBeat, const RSt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SMALoader::TidyUpData( Song &song, bool bFromCache )
|
|
||||||
{
|
|
||||||
SMLoader::TidyUpData( song, bFromCache );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out )
|
bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out )
|
||||||
{
|
{
|
||||||
LOG->Trace( "Song::LoadFromSMAFile(%s)", sPath.c_str() );
|
LOG->Trace( "Song::LoadFromSMAFile(%s)", sPath.c_str() );
|
||||||
@@ -456,7 +420,7 @@ bool SMALoader::LoadFromSMAFile( const RString &sPath, Song &out )
|
|||||||
{
|
{
|
||||||
TimingData &timing = (state == SMA_GETTING_STEP_INFO
|
TimingData &timing = (state == SMA_GETTING_STEP_INFO
|
||||||
? pNewNotes->m_Timing : out.m_SongTiming);
|
? pNewNotes->m_Timing : out.m_SongTiming);
|
||||||
ProcessTickcounts( timing, iRowsPerBeat, sParams[1] );
|
ProcessTickcounts( timing, sParams[1], iRowsPerBeat );
|
||||||
}
|
}
|
||||||
|
|
||||||
else if( sValueName=="SPEED" )
|
else if( sValueName=="SPEED" )
|
||||||
@@ -532,116 +496,6 @@ void SMALoader::GetApplicableFiles( const RString &sPath, vector<RString> &out )
|
|||||||
GetDirListing( sPath + RString("*.sma"), out );
|
GetDirListing( sPath + RString("*.sma"), out );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SMALoader::LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong )
|
|
||||||
{
|
|
||||||
LOG->Trace( "SMALoader::LoadEditFromFile(%s)", sEditFilePath.c_str() );
|
|
||||||
|
|
||||||
int iBytes = FILEMAN->GetFileSizeInBytes( sEditFilePath );
|
|
||||||
if( iBytes > MAX_EDIT_STEPS_SIZE_BYTES )
|
|
||||||
{
|
|
||||||
LOG->UserLog( "Edit file", sEditFilePath, "is unreasonably large. It won't be loaded." );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
MsdFile msd;
|
|
||||||
if( !msd.ReadFile( sEditFilePath, true ) ) // unescape
|
|
||||||
{
|
|
||||||
LOG->UserLog( "Edit file", sEditFilePath, "couldn't be opened: %s", msd.GetError().c_str() );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return LoadEditFromMsd( msd, sEditFilePath, slot, bAddStepsToSong );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SMALoader::LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot )
|
|
||||||
{
|
|
||||||
MsdFile msd;
|
|
||||||
msd.ReadFromString( sBuffer, true ); // unescape
|
|
||||||
return LoadEditFromMsd( msd, sEditFilePath, slot, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SMALoader::LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong )
|
|
||||||
{
|
|
||||||
Song* pSong = NULL;
|
|
||||||
|
|
||||||
for( unsigned i=0; i<msd.GetNumValues(); i++ )
|
|
||||||
{
|
|
||||||
int iNumParams = msd.GetNumParams(i);
|
|
||||||
const MsdFile::value_t &sParams = msd.GetValue(i);
|
|
||||||
RString sValueName = sParams[0];
|
|
||||||
sValueName.MakeUpper();
|
|
||||||
|
|
||||||
// handle the data
|
|
||||||
if( sValueName=="SONG" )
|
|
||||||
{
|
|
||||||
if( pSong )
|
|
||||||
{
|
|
||||||
LOG->UserLog( "Edit file", sEditFilePath, "has more than one #SONG tag." );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
RString sSongFullTitle = sParams[1];
|
|
||||||
sSongFullTitle.Replace( '\\', '/' );
|
|
||||||
|
|
||||||
pSong = SONGMAN->FindSong( sSongFullTitle );
|
|
||||||
if( pSong == NULL )
|
|
||||||
{
|
|
||||||
LOG->UserLog( "Edit file", sEditFilePath, "requires a song \"%s\" that isn't present.", sSongFullTitle.c_str() );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( pSong->GetNumStepsLoadedFromProfile(slot) >= MAX_EDITS_PER_SONG_PER_PROFILE )
|
|
||||||
{
|
|
||||||
LOG->UserLog( "Song file", sSongFullTitle, "already has the maximum number of edits allowed for ProfileSlotP%d.", slot+1 );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if( sValueName=="NOTES" )
|
|
||||||
{
|
|
||||||
if( pSong == NULL )
|
|
||||||
{
|
|
||||||
LOG->UserLog( "Edit file", sEditFilePath, "doesn't have a #SONG tag preceeding the first #NOTES tag." );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( iNumParams < 7 )
|
|
||||||
{
|
|
||||||
LOG->UserLog( "Edit file", sEditFilePath, "has %d fields in a #NOTES tag, but should have at least 7.", iNumParams );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !bAddStepsToSong )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
Steps* pNewNotes = pSong->CreateSteps();
|
|
||||||
LoadFromTokens(
|
|
||||||
sParams[1], sParams[2], sParams[3], sParams[4], sParams[5], sParams[6],
|
|
||||||
*pNewNotes);
|
|
||||||
|
|
||||||
pNewNotes->SetLoadedFromProfile( slot );
|
|
||||||
pNewNotes->SetDifficulty( Difficulty_Edit );
|
|
||||||
pNewNotes->SetFilename( sEditFilePath );
|
|
||||||
|
|
||||||
if( pSong->IsEditAlreadyLoaded(pNewNotes) )
|
|
||||||
{
|
|
||||||
LOG->UserLog( "Edit file", sEditFilePath, "is a duplicate of another edit that was already loaded." );
|
|
||||||
SAFE_DELETE( pNewNotes );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pSong->AddSteps( pNewNotes );
|
|
||||||
return true; // Only allow one Steps per edit file!
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG->UserLog( "Edit file", sEditFilePath, "has an unexpected value \"%s\".", sValueName.c_str() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* @author Aldo Fregoso, Jason Felds (c) 2009-2011
|
* @author Aldo Fregoso, Jason Felds (c) 2009-2011
|
||||||
|
|||||||
@@ -24,18 +24,11 @@ enum SMALoadingStates
|
|||||||
struct SMALoader : public SMLoader
|
struct SMALoader : public SMLoader
|
||||||
{
|
{
|
||||||
bool LoadFromDir( const RString &sPath, Song &out );
|
bool LoadFromDir( const RString &sPath, Song &out );
|
||||||
void TidyUpData( Song &song, bool bFromCache );
|
|
||||||
|
|
||||||
bool LoadFromSMAFile( const RString &sPath, Song &out );
|
bool LoadFromSMAFile( const RString &sPath, Song &out );
|
||||||
void GetApplicableFiles( const RString &sPath, vector<RString> &out );
|
void GetApplicableFiles( const RString &sPath, vector<RString> &out );
|
||||||
|
|
||||||
bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
|
|
||||||
bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot );
|
|
||||||
bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong );
|
|
||||||
bool LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression );
|
|
||||||
|
|
||||||
void ProcessBeatsPerMeasure( TimingData &out, const RString sParam );
|
void ProcessBeatsPerMeasure( TimingData &out, const RString sParam );
|
||||||
void ProcessTickcounts( TimingData &out, const int iRowsPerBeat, const RString sParam );
|
|
||||||
void ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam );
|
void ProcessMultipliers( TimingData &out, const int iRowsPerBeat, const RString sParam );
|
||||||
void ProcessSpeeds( 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 );
|
void ProcessFakes( TimingData &out, const int iRowsPerBeat, const RString sParam );
|
||||||
|
|||||||
Reference in New Issue
Block a user