From d1fb6a41eb7cf680462c78080dddf9c09ee3ddc1 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 19 Feb 2005 07:48:16 +0000 Subject: [PATCH] NotesWriterSM::GetEditFile --- stepmania/src/NotesWriterSM.cpp | 70 ++++++++++++++++++++------------- stepmania/src/NotesWriterSM.h | 3 +- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/stepmania/src/NotesWriterSM.cpp b/stepmania/src/NotesWriterSM.cpp index ac9bd31692..4921de8029 100644 --- a/stepmania/src/NotesWriterSM.cpp +++ b/stepmania/src/NotesWriterSM.cpp @@ -120,34 +120,32 @@ void NotesWriterSM::WriteGlobalTags( RageFile &f, const Song &out ) f.PutLine( ";" ); } -static void WriteLineList( RageFile &f, vector &lines, bool SkipLeadingBlankLines, bool OmitLastNewline ) +static CString JoinLineList( vector &lines ) { - for( unsigned i = 0; i < lines.size(); ++i ) - { - TrimRight( lines[i] ); - if( SkipLeadingBlankLines ) - { - if( lines.size() == 0 ) - continue; - SkipLeadingBlankLines = false; - } - f.Write( lines[i] ); + bool bSkipLeadingBlankLines = true; - if( !OmitLastNewline || i+1 < lines.size() ) - f.PutLine( "" ); /* newline */ - } + for( unsigned i = 0; i < lines.size(); ++i ) + TrimRight( lines[i] ); + + /* Skip leading blanks. */ + unsigned i = 0; + while( i < lines.size() && lines.size() == 0 ) + ++i; + + return join( "\n", lines.begin()+i, lines.end() ); } -void NotesWriterSM::WriteSMNotesTag( const Song &song, const Steps &in, RageFile &f, bool bSavingCache ) +CString NotesWriterSM::GetSMNotesTag( const Song &song, const Steps &in, bool bSavingCache ) { - f.PutLine( "" ); - f.PutLine( ssprintf( "//---------------%s - %s----------------", - GameManager::StepsTypeToString(in.m_StepsType).c_str(), in.GetDescription().c_str() ) ); - f.PutLine( song.m_vsKeysoundFile.empty() ? "#NOTES:" : "#NOTES2:" ); - f.PutLine( ssprintf( " %s:", GameManager::StepsTypeToString(in.m_StepsType).c_str() ) ); - f.PutLine( ssprintf( " %s:", in.GetDescription().c_str() ) ); - f.PutLine( ssprintf( " %s:", DifficultyToString(in.GetDifficulty()).c_str() ) ); - f.PutLine( ssprintf( " %d:", in.GetMeter() ) ); + CString sRet; + sRet += "\n"; + sRet += ssprintf( "//---------------%s - %s----------------\n", + GameManager::StepsTypeToString(in.m_StepsType).c_str(), in.GetDescription().c_str() ); + sRet += song.m_vsKeysoundFile.empty() ? "#NOTES:\n" : "#NOTES2:\n"; + sRet += ssprintf( " %s:\n", GameManager::StepsTypeToString(in.m_StepsType).c_str() ); + sRet += ssprintf( " %s:\n", in.GetDescription().c_str() ); + sRet += ssprintf( " %s:\n", DifficultyToString(in.GetDifficulty()).c_str() ); + sRet += ssprintf( " %d:\n", in.GetMeter() ); int MaxRadar = bSavingCache? NUM_RADAR_CATEGORIES:5; CStringArray asRadarValues; @@ -156,7 +154,7 @@ void NotesWriterSM::WriteSMNotesTag( const Song &song, const Steps &in, RageFile /* Don't append a newline here; it's added in NoteDataUtil::GetSMNoteDataString. * If we add it here, then every time we write unmodified data we'll add an extra * newline and they'll accumulate. */ - f.Write( ssprintf( " %s:", join(",",asRadarValues).c_str() ) ); + sRet += ssprintf( " %s:\n", join(",",asRadarValues).c_str() ); CString sNoteData; in.GetSMNoteData( sNoteData ); @@ -164,8 +162,9 @@ void NotesWriterSM::WriteSMNotesTag( const Song &song, const Steps &in, RageFile vector lines; split( sNoteData, "\n", lines, false ); - WriteLineList( f, lines, true, true ); - f.PutLine( ";" ); + sRet += JoinLineList( lines ); + sRet += ";\n"; + return sRet; } bool NotesWriterSM::Write(CString sPath, const Song &out, bool bSavingCache) @@ -215,12 +214,29 @@ bool NotesWriterSM::Write(CString sPath, const Song &out, bool bSavingCache) if( pSteps->WasLoadedFromProfile() ) continue; - WriteSMNotesTag( out, *pSteps, f, bSavingCache ); + CString sTag = GetSMNotesTag( out, *pSteps, bSavingCache ); + f.PutLine( sTag ); } return true; } +void NotesWriterSM::GetEditFile( const Song *pSong, const Steps *pSteps, CString &sOut ) +{ + sOut = ""; + CString sDir = pSong->GetSongDir(); + + LOG->Trace( "xxx dir from '%s'", sDir.c_str()); + /* "Songs/foo/bar"; strip off "Songs/". */ + vector asParts; + split( sDir, "/", asParts ); + if( asParts.size() ) + sDir = join( "/", asParts.begin()+1, asParts.end() ); + LOG->Trace( "dir to '%s'", sDir.c_str()); + sOut += ssprintf( "#SONG:%s;\n", sDir.c_str() ); + sOut += GetSMNotesTag( *pSong, *pSteps, false ); +} + /* * (c) 2001-2004 Chris Danford, Glenn Maynard * All rights reserved. diff --git a/stepmania/src/NotesWriterSM.h b/stepmania/src/NotesWriterSM.h index 57d8e6ee10..6a591abbc7 100644 --- a/stepmania/src/NotesWriterSM.h +++ b/stepmania/src/NotesWriterSM.h @@ -9,10 +9,11 @@ class RageFile; class NotesWriterSM { void WriteGlobalTags( RageFile &f, const Song &out ); - void WriteSMNotesTag( const Song &song, const Steps &in, RageFile &f, bool bSavingCache ); + static CString GetSMNotesTag( const Song &song, const Steps &in, bool bSavingCache ); public: bool Write( CString sPath, const Song &out, bool bSavingCache ); + static void GetEditFile( const Song *pSong, const Steps *pSteps, CString &sOut ); }; #endif