diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index df9b8bae5e..1e9d896500 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -6,10 +6,7 @@ #include "BGAnimation.h" #include "IniFile.h" #include "ThemeManager.h" -#include "RageDisplay.h" #include "RageLog.h" -#include "arch/ArchHooks/ArchHooks.h" -#include "RageFileManager.h" #include "SongCreditDisplay.h" #include "song.h" #include "GameState.h" @@ -76,13 +73,8 @@ Actor* LoadFromActorFile( const CString& sAniDir, const XNode& layer ) CString sAlttext; layer.GetAttrValue("AltText", sAlttext ); - // Keep the special treatment of text string sync'd with the same treatments - // in ThemeManager. - sText.Replace( "::", "\n" ); - sAlttext.Replace( "::", "\n" ); - - FontCharAliases::ReplaceMarkers( sText ); - FontCharAliases::ReplaceMarkers( sAlttext ); + ThemeManager::EvaluateString( sText ); + ThemeManager::EvaluateString( sAlttext ); BitmapText* pBitmapText = new BitmapText; diff --git a/stepmania/src/LuaHelpers.cpp b/stepmania/src/LuaHelpers.cpp index 280a78b3bd..8de0a771ff 100644 --- a/stepmania/src/LuaHelpers.cpp +++ b/stepmania/src/LuaHelpers.cpp @@ -241,6 +241,22 @@ float Lua::RunExpressionF( const CString &str ) return result; } +bool Lua::RunExpressionS( const CString &str, CString &sOut ) +{ + if( L == NULL ) + OpenLua(); + + if( !RunExpression( str ) ) + return false; + + ASSERT( lua_gettop(L) > 0 ); + + sOut = lua_tostring( L, -1 ); + lua_pop( L, -1 ); + + return true; +} + void Lua::Fail( lua_State *L, const CString &err ) { lua_pushstring( L, err ); diff --git a/stepmania/src/LuaHelpers.h b/stepmania/src/LuaHelpers.h index 3714b452f0..142e2a1932 100644 --- a/stepmania/src/LuaHelpers.h +++ b/stepmania/src/LuaHelpers.h @@ -7,6 +7,7 @@ namespace Lua void PrepareExpression( CString &sInOut ); // strip "//" comments and "+" bool RunExpressionB( const CString &str ); float RunExpressionF( const CString &str ); + bool RunExpressionS( const CString &str, CString &sOut ); void Fail( lua_State *L, const CString &err ); diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index 74621dc265..791a770077 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -650,16 +650,34 @@ CString ThemeManager::GetMetric( const CString &sClassName, const CString &sValu { CString sValue = GetMetricRaw(sClassName,sValueName); - // "::" means newline since you can't use line breaks in an ini file. - sValue.Replace("::","\n"); - - /* XXX: add a parameter to turn this off if there are some metrics where - * we don't want markers */ - FontCharAliases::ReplaceMarkers(sValue); + EvaluateString( sValue ); return sValue; } +void ThemeManager::EvaluateString( CString &sText ) +{ + /* If the string begins with an @, treat it as a raw Lua expression, and don't do any + * other filtering. (XXX: maybe we should still do font aliases) */ + if( sText.size() >= 1 && sText[0] == '@' ) + { + /* Erase "@". */ + sText.erase( 0, 1 ); + + CString sOut; + Lua::RunExpressionS( sText, sOut ); + LOG->Trace("ran '%s', got '%s'", sText.c_str(), sOut.c_str()); + sText = sOut; + return; + } + + // "::" means newline since you can't use line breaks in an ini file. + // XXX: this makes it impossible to put a colon at the end of a line, eg: "Color:\nRed" + sText.Replace("::","\n"); + + FontCharAliases::ReplaceMarkers( sText ); +} + int ThemeManager::GetMetricI( const CString &sClassName, const CString &sValueName ) { return atoi( GetMetricRaw(sClassName,sValueName) ); diff --git a/stepmania/src/ThemeManager.h b/stepmania/src/ThemeManager.h index a7fe499f05..0363ce5a1e 100644 --- a/stepmania/src/ThemeManager.h +++ b/stepmania/src/ThemeManager.h @@ -35,6 +35,8 @@ public: void ReloadMetrics(); void GetModifierNames( set& AddTo ); + static void EvaluateString( CString &sText ); + /* I renamed these for two reasons. The overload conflicts with the ones below: * GetPathToB( str, str ) was matching the ones below instead of these. It's also * easier to search for uses of obsolete functions if they have a different name. */