Abstract common functionality.

This commit is contained in:
Jason Felds
2011-07-17 12:54:50 -04:00
parent 4a62093491
commit 09dc94cfe8
4 changed files with 28 additions and 54 deletions
+2 -27
View File
@@ -19,31 +19,6 @@
ThemeMetric<bool> 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( ";" );
}