diff --git a/src/BackgroundUtil.cpp b/src/BackgroundUtil.cpp index 6644d1593d..d101be23e1 100644 --- a/src/BackgroundUtil.cpp +++ b/src/BackgroundUtil.cpp @@ -68,6 +68,25 @@ RString BackgroundChange::GetTextDescription() const return s; } +RString BackgroundChange::ToString() const +{ + /* TODO: Technically we need to double-escape the filename + * (because it might contain '=') and then unescape the value + * returned by the MsdFile. */ + return ssprintf("%.3f=%s=%.3f=%d=%d=%d=%s=%s=%s=%s=%s", + this->m_fStartBeat, + SmEscape(this->m_def.m_sFile1).c_str(), + this->m_fRate, + this->m_sTransition == SBT_CrossFade, // backward compat + this->m_def.m_sEffect == SBE_StretchRewind, // backward compat + this->m_def.m_sEffect != SBE_StretchNoLoop, // backward compat + this->m_def.m_sEffect.c_str(), + this->m_def.m_sFile2.c_str(), + this->m_sTransition.c_str(), + SmEscape(RageColor::NormalizeColorString(this->m_def.m_sColor1)).c_str(), + SmEscape(RageColor::NormalizeColorString(this->m_def.m_sColor2)).c_str()); +} + const RString BACKGROUND_EFFECTS_DIR = "BackgroundEffects/"; const RString BACKGROUND_TRANSITIONS_DIR = "BackgroundTransitions/"; diff --git a/src/BackgroundUtil.h b/src/BackgroundUtil.h index 80d36b8a92..c4907b590c 100644 --- a/src/BackgroundUtil.h +++ b/src/BackgroundUtil.h @@ -64,6 +64,11 @@ struct BackgroundChange RString m_sTransition; RString GetTextDescription() const; + + /** + * @brief Get the string representation of the change. + * @return the string representation. */ + RString ToString() const; }; /** @brief Shared background-related routines. */ namespace BackgroundUtil diff --git a/src/NotesWriterSM.cpp b/src/NotesWriterSM.cpp index 05863f9af0..4be321e651 100644 --- a/src/NotesWriterSM.cpp +++ b/src/NotesWriterSM.cpp @@ -19,31 +19,6 @@ ThemeMetric USE_CREDIT ( "NotesWriterSM", "DescriptionUsesCreditField" ); -/** - * @brief Turn the BackgroundChange into a string. - * @param bgc the BackgroundChange in question. - * @return the converted string. */ -static RString BackgroundChangeToString( const BackgroundChange &bgc ) -{ - // TODO: Technically we need to double-escape the filename (because it might - // contain '=') and then unescape the value returned by the MsdFile. - RString s = ssprintf( - "%.3f=%s=%.3f=%d=%d=%d=%s=%s=%s=%s=%s", - bgc.m_fStartBeat, - SmEscape(bgc.m_def.m_sFile1).c_str(), - bgc.m_fRate, - bgc.m_sTransition == SBT_CrossFade, // backward compat - bgc.m_def.m_sEffect == SBE_StretchRewind, // backward compat - bgc.m_def.m_sEffect != SBE_StretchNoLoop, // backward compat - bgc.m_def.m_sEffect.c_str(), - bgc.m_def.m_sFile2.c_str(), - bgc.m_sTransition.c_str(), - SmEscape(RageColor::NormalizeColorString(bgc.m_def.m_sColor1)).c_str(), - SmEscape(RageColor::NormalizeColorString(bgc.m_def.m_sColor2)).c_str() - ); - return s; -} - /** * @brief Write out the common tags for .SM files. * @param f the file in question. @@ -155,7 +130,7 @@ static void WriteGlobalTags( RageFile &f, Song &out ) f.Write( ssprintf("#BGCHANGES%d:", b+1) ); FOREACH_CONST( BackgroundChange, out.GetBackgroundChanges(b), bgc ) - f.PutLine( BackgroundChangeToString(*bgc)+"," ); + f.PutLine( (*bgc).ToString() +"," ); /* If there's an animation plan at all, add a dummy "-nosongbg-" tag to indicate that * this file doesn't want a song BG entry added at the end. See SMLoader::TidyUpData. @@ -171,7 +146,7 @@ static void WriteGlobalTags( RageFile &f, Song &out ) f.Write( "#FGCHANGES:" ); FOREACH_CONST( BackgroundChange, out.GetForegroundChanges(), bgc ) { - f.PutLine( BackgroundChangeToString(*bgc)+"," ); + f.PutLine( (*bgc).ToString() +"," ); } f.PutLine( ";" ); } diff --git a/src/NotesWriterSSC.cpp b/src/NotesWriterSSC.cpp index 8d9434e10f..8ca8140231 100644 --- a/src/NotesWriterSSC.cpp +++ b/src/NotesWriterSSC.cpp @@ -16,31 +16,6 @@ #include "Song.h" #include "Steps.h" -/** - * @brief Turn the BackgroundChange into a string. - * @param bgc the BackgroundChange in question. - * @return the converted string. */ -static RString BackgroundChangeToString( const BackgroundChange &bgc ) -{ - // TODO: Technically we need to double-escape the filename (because it might contain '=') and then - // unescape the value returned by the MsdFile. - RString s = ssprintf( - "%.3f=%s=%.3f=%d=%d=%d=%s=%s=%s=%s=%s", - bgc.m_fStartBeat, - SmEscape(bgc.m_def.m_sFile1).c_str(), - bgc.m_fRate, - bgc.m_sTransition == SBT_CrossFade, // backward compat - bgc.m_def.m_sEffect == SBE_StretchRewind, // backward compat - bgc.m_def.m_sEffect != SBE_StretchNoLoop, // backward compat - bgc.m_def.m_sEffect.c_str(), - bgc.m_def.m_sFile2.c_str(), - bgc.m_sTransition.c_str(), - SmEscape(RageColor::NormalizeColorString(bgc.m_def.m_sColor1)).c_str(), - SmEscape(RageColor::NormalizeColorString(bgc.m_def.m_sColor2)).c_str() - ); - return s; -} - /** * @brief Turn a vector of lines into a single line joined by newline characters. * @param lines the list of lines to join. @@ -292,7 +267,7 @@ static void WriteGlobalTags( RageFile &f, const Song &out ) f.Write( ssprintf("#BGCHANGES%d:", b+1) ); FOREACH_CONST( BackgroundChange, out.GetBackgroundChanges(b), bgc ) - f.PutLine( BackgroundChangeToString(*bgc)+"," ); + f.PutLine( (*bgc).ToString() +"," ); /* If there's an animation plan at all, add a dummy "-nosongbg-" tag to * indicate that this file doesn't want a song BG entry added at the end. @@ -308,7 +283,7 @@ static void WriteGlobalTags( RageFile &f, const Song &out ) f.Write( "#FGCHANGES:" ); FOREACH_CONST( BackgroundChange, out.GetForegroundChanges(), bgc ) { - f.PutLine( BackgroundChangeToString(*bgc)+"," ); + f.PutLine( (*bgc).ToString() +"," ); } f.PutLine( ";" ); }