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
+19
View File
@@ -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/";
+5
View File
@@ -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
+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( ";" );
}
+2 -27
View File
@@ -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( ";" );
}