Refactored code for writing #SONG entries in CourseWriterCRS

Added method for writing #SONGSELECT entries
Added new boolean flag bUseSongSelect to CourseEntry
Added new function StringToSongSort()
Renamed "LIVES" to "GAINLIVES"
This commit is contained in:
Michael Votaw
2023-12-01 12:44:51 -06:00
committed by teejusb
parent be87de401a
commit 84553d4a50
5 changed files with 214 additions and 87 deletions
+200 -83
View File
@@ -100,99 +100,216 @@ bool CourseWriterCRS::Write( const Course &course, RageFileBasic &f, bool bSavin
for( unsigned i=0; i<course.m_vEntries.size(); i++ )
{
const CourseEntry& entry = course.m_vEntries[i];
for( unsigned j = 0; j < entry.attacks.size(); ++j )
if( entry.bUseSongSelect )
{
if( j == 0 )
f.PutLine( "#MODS:" );
const Attack &a = entry.attacks[j];
f.Write( ssprintf( " TIME=%.2f:LEN=%.2f:MODS=%s",
a.fStartSecond, a.fSecsRemaining, a.sModifiers.c_str() ) );
if( j+1 < entry.attacks.size() )
f.Write( ":" );
else
f.Write( ";" );
f.PutLine( "" );
}
if( entry.fGainSeconds > 0 )
f.PutLine( ssprintf("#GAINSECONDS:%f;", entry.fGainSeconds) );
if( entry.songSort == SongSort_MostPlays && entry.iChooseIndex != -1 )
{
f.Write( ssprintf( "#SONG:BEST%d", entry.iChooseIndex+1 ) );
}
else if( entry.songSort == SongSort_FewestPlays && entry.iChooseIndex != -1 )
{
f.Write( ssprintf( "#SONG:WORST%d", entry.iChooseIndex+1 ) );
}
else if( entry.songSort == SongSort_TopGrades && entry.iChooseIndex != -1 )
{
f.Write( ssprintf( "#SONG:GRADEBEST%d", entry.iChooseIndex + 1 ) );
}
else if( entry.songSort == SongSort_LowestGrades && entry.iChooseIndex != -1 )
{
f.Write( ssprintf( "#SONG:GRADEWORST%d", entry.iChooseIndex + 1 ) );
}
else if( entry.songID.ToSong() )
{
Song *pSong = entry.songID.ToSong();
const RString &sSong = Basename( pSong->GetSongDir() );
f.Write( "#SONG:" );
if( entry.songCriteria.m_vsGroupNames.size() > 0 )
f.Write( entry.songCriteria.m_vsGroupNames[0] + '/' );
f.Write( sSong );
}
else if( entry.songCriteria.m_vsGroupNames.size() > 0 )
{
f.Write( ssprintf( "#SONG:%s/*", entry.songCriteria.m_vsGroupNames[0].c_str() ) );
WriteSongSelectCourseEntry(entry, f);
}
else
{
f.Write( "#SONG:*" );
WriteCourseEntry(entry, f);
}
f.Write( ":" );
if( entry.stepsCriteria.m_difficulty != Difficulty_Invalid )
f.Write( DifficultyToString(entry.stepsCriteria.m_difficulty) );
else if( entry.stepsCriteria.m_iLowMeter != -1 && entry.stepsCriteria.m_iHighMeter != -1 )
f.Write( ssprintf( "%d..%d", entry.stepsCriteria.m_iLowMeter, entry.stepsCriteria.m_iHighMeter ) );
f.Write( ":" );
RString sModifiers = entry.sModifiers;
if( entry.bSecret )
{
if( sModifiers != "" )
sModifiers += ",";
sModifiers += entry.bSecret? "noshowcourse":"showcourse";
}
if( entry.bNoDifficult )
{
if( sModifiers != "" )
sModifiers += ",";
sModifiers += "nodifficult";
}
if( entry.iGainLives > -1 )
{
if( !sModifiers.empty() )
sModifiers += ',';
sModifiers += ssprintf( "award%d", entry.iGainLives );
}
f.Write( sModifiers );
f.PutLine( ";" );
}
return true;
}
bool CourseWriterCRS::WriteCourseEntry( const CourseEntry &entry, RageFileBasic &f )
{
for( unsigned j = 0; j < entry.attacks.size(); ++j )
{
if( j == 0 )
f.PutLine( "#MODS:" );
const Attack &a = entry.attacks[j];
f.Write( ssprintf( " TIME=%.2f:LEN=%.2f:MODS=%s",
a.fStartSecond, a.fSecsRemaining, a.sModifiers.c_str() ) );
if( j+1 < entry.attacks.size() )
f.Write( ":" );
else
f.Write( ";" );
f.PutLine( "" );
}
if( entry.fGainSeconds > 0 )
f.PutLine( ssprintf("#GAINSECONDS:%f;", entry.fGainSeconds) );
if( entry.songSort == SongSort_MostPlays && entry.iChooseIndex != -1 )
{
f.Write( ssprintf( "#SONG:BEST%d", entry.iChooseIndex+1 ) );
}
else if( entry.songSort == SongSort_FewestPlays && entry.iChooseIndex != -1 )
{
f.Write( ssprintf( "#SONG:WORST%d", entry.iChooseIndex+1 ) );
}
else if( entry.songSort == SongSort_TopGrades && entry.iChooseIndex != -1 )
{
f.Write( ssprintf( "#SONG:GRADEBEST%d", entry.iChooseIndex + 1 ) );
}
else if( entry.songSort == SongSort_LowestGrades && entry.iChooseIndex != -1 )
{
f.Write( ssprintf( "#SONG:GRADEWORST%d", entry.iChooseIndex + 1 ) );
}
else if( entry.songID.ToSong() )
{
Song *pSong = entry.songID.ToSong();
const RString &sSong = Basename( pSong->GetSongDir() );
f.Write( "#SONG:" );
if( entry.songCriteria.m_vsGroupNames.size() > 0 )
f.Write( entry.songCriteria.m_vsGroupNames[0] + '/' );
f.Write( sSong );
}
else if( entry.songCriteria.m_vsGroupNames.size() > 0 )
{
f.Write( ssprintf( "#SONG:%s/*", entry.songCriteria.m_vsGroupNames[0].c_str() ) );
}
else
{
f.Write( "#SONG:*" );
}
f.Write( ":" );
if( entry.stepsCriteria.m_difficulty != Difficulty_Invalid )
f.Write( DifficultyToString(entry.stepsCriteria.m_difficulty) );
else if( entry.stepsCriteria.m_iLowMeter != -1 && entry.stepsCriteria.m_iHighMeter != -1 )
f.Write( ssprintf( "%d..%d", entry.stepsCriteria.m_iLowMeter, entry.stepsCriteria.m_iHighMeter ) );
f.Write( ":" );
RString sModifiers = entry.sModifiers;
if( entry.bSecret )
{
if( sModifiers != "" )
sModifiers += ",";
sModifiers += entry.bSecret? "noshowcourse":"showcourse";
}
if( entry.bNoDifficult )
{
if( sModifiers != "" )
sModifiers += ",";
sModifiers += "nodifficult";
}
if( entry.iGainLives > -1 )
{
if( !sModifiers.empty() )
sModifiers += ',';
sModifiers += ssprintf( "award%d", entry.iGainLives );
}
f.Write( sModifiers );
f.PutLine( ";" );
return true;
}
bool CourseWriterCRS::WriteSongSelectCourseEntry( const CourseEntry &entry, RageFileBasic &f )
{
for( unsigned j = 0; j < entry.attacks.size(); ++j )
{
if( j == 0 )
f.PutLine( "#MODS:" );
const Attack &a = entry.attacks[j];
f.Write( ssprintf( " TIME=%.2f:LEN=%.2f:MODS=%s",
a.fStartSecond, a.fSecsRemaining, a.sModifiers.c_str() ) );
if( j+1 < entry.attacks.size() )
f.Write( ":" );
else
f.Write( ";" );
f.PutLine( "" );
}
std::vector<RString> songSelectParams;
if( entry.songCriteria.m_vsSongNames.size() > 0 )
{
RString songNames = join(",", entry.songCriteria.m_vsSongNames);
songSelectParams.push_back(ssprintf("TITLE=%s", songNames.c_str()));
}
if( entry.songCriteria.m_vsGroupNames.size() > 0)
{
RString groupNames = join(",", entry.songCriteria.m_vsGroupNames);
songSelectParams.push_back(ssprintf("GROUP=%s", groupNames.c_str()));
}
if( entry.songCriteria.m_vsArtistNames.size() > 0)
{
RString artistNames = join(",", entry.songCriteria.m_vsArtistNames);
songSelectParams.push_back(ssprintf("ARTIST=%s", artistNames.c_str()));
}
if( entry.songCriteria.m_bUseSongAllowedList &&
entry.songCriteria.m_vsSongGenreAllowedList.size() > 0)
{
RString genreNames = join(",", entry.songCriteria.m_vsSongGenreAllowedList);
songSelectParams.push_back(ssprintf("GENRE=%s", genreNames.c_str()));
}
if( entry.stepsCriteria.m_vDifficulties.size() > 0 )
{
std::vector<RString> difficulties;
for (unsigned d = 0; d < entry.stepsCriteria.m_vDifficulties.size(); d++)
{
Difficulty diff = entry.stepsCriteria.m_vDifficulties[d];
if( diff != Difficulty_Invalid)
{
difficulties.push_back(DifficultyToString(diff));
}
}
songSelectParams.push_back("DIFFICULTY=" + join(",", difficulties));
}
if( entry.songSort != SongSort_Randomize && entry.iChooseIndex > -1)
{
RString songSort = SongSortToString(entry.songSort);
songSelectParams.push_back(ssprintf("SORT=%s=%d", songSort.c_str(), entry.iChooseIndex+1));
}
if(entry.songCriteria.m_fMinDurationSeconds > 0
&& entry.songCriteria.m_fMaxDurationSeconds > 0 )
{
songSelectParams.push_back(ssprintf("DURATION=%d..%d", (int)entry.songCriteria.m_fMinDurationSeconds, (int)entry.songCriteria.m_fMaxDurationSeconds));
}
if(entry.songCriteria.m_fMinBPM > 0 && entry.songCriteria.m_fMaxBPM > 0 )
{
songSelectParams.push_back(ssprintf("BPMRANGE=%f..%f", entry.songCriteria.m_fMinBPM, entry.songCriteria.m_fMaxBPM));
}
if(entry.stepsCriteria.m_iLowMeter > 0 && entry.stepsCriteria.m_iHighMeter > 0 )
{
songSelectParams.push_back(ssprintf("METER=%d..%d", entry.stepsCriteria.m_iLowMeter, entry.stepsCriteria.m_iHighMeter));
}
if( entry.iGainLives > 0 )
{
songSelectParams.push_back(ssprintf("GAINLIVES=%d", entry.iGainLives));
}
if(entry.fGainSeconds > 0 )
{
songSelectParams.push_back(ssprintf("GAINSECONDS=%f", entry.fGainSeconds));
}
std::vector<RString> mods;
split(entry.sModifiers, ",", mods);
if (entry.bSecret)
{
mods.push_back("noshowcourse");
}
else
{
mods.push_back("showcourse");
}
if( entry.bNoDifficult )
{
mods.push_back("nodifficult");
}
songSelectParams.push_back("MODS=" + join(",", mods));
RString songSelect = join(":", songSelectParams);
f.PutLine(ssprintf("#SONGSELECT:%s;", songSelect.c_str()));
return true;
}
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard