From 4d31f3b4c168978c58499747119a814e7059a50c Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 16 Feb 2005 00:16:14 +0000 Subject: [PATCH] evaluate TargetNumber as a Lua expression --- stepmania/src/BGAnimationLayer.cpp | 5 +++-- stepmania/src/Command.cpp | 2 +- stepmania/src/LuaManager.cpp | 17 ++++++++++++++++- stepmania/src/LuaManager.h | 3 ++- stepmania/src/ProfileManager.cpp | 2 +- stepmania/src/RollingNumbers.cpp | 7 +++++-- stepmania/src/ThemeManager.cpp | 2 +- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/stepmania/src/BGAnimationLayer.cpp b/stepmania/src/BGAnimationLayer.cpp index 491050e4c0..ff157eb96d 100644 --- a/stepmania/src/BGAnimationLayer.cpp +++ b/stepmania/src/BGAnimationLayer.cpp @@ -376,7 +376,7 @@ void BGAnimationLayer::LoadFromNode( const CString& sDir, const XNode* pNode ) CString expr; if( pNode->GetAttrValue("Cond",expr) || pNode->GetAttrValue("Condition",expr) ) { - if( !LUA->RunExpressionB( expr ) ) + if( !LUA->RunExpressionB(expr) ) return; } } @@ -672,7 +672,8 @@ bool BGAnimationLayer::EarlyAbortDraw() if( m_sDrawCond.empty() ) return false; - if( !LUA->RunExpressionB( m_sDrawCond ) ) + // TODO: Is it ok to evaluate this every frame? + if( !LUA->RunExpressionB(m_sDrawCond) ) return true; return false; diff --git a/stepmania/src/Command.cpp b/stepmania/src/Command.cpp index f34db8e84b..6374053795 100644 --- a/stepmania/src/Command.cpp +++ b/stepmania/src/Command.cpp @@ -34,7 +34,7 @@ Command::Arg Command::GetArg( unsigned index ) const Command::Arg::operator CString () { CString sValue = s; - LUA->RunAtExpression( sValue ); + LUA->RunAtExpressionS( sValue ); return sValue; } diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 9a48a0bf6b..91a8852ef6 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -364,7 +364,7 @@ bool LuaManager::RunExpressionS( const CString &str, CString &sOut ) return true; } -bool LuaManager::RunAtExpression( CString &sStr ) +bool LuaManager::RunAtExpressionS( CString &sStr ) { if( sStr.size() == 0 || sStr[0] != '@' ) return false; @@ -378,6 +378,21 @@ bool LuaManager::RunAtExpression( CString &sStr ) return true; } +float LuaManager::RunAtExpressionF( const CString &_sStr ) +{ + if( _sStr.size() == 0 || _sStr[0] != '@' ) + return 0; + + CString sStr = _sStr; + + /* Erase "@". */ + sStr.erase( 0, 1 ); + + CString sOut; + RunExpressionS( sStr, sOut ); + return atof( sOut ); +} + void LuaManager::Fail( const CString &err ) { lua_pushstring( L, err ); diff --git a/stepmania/src/LuaManager.h b/stepmania/src/LuaManager.h index ef3a35639d..918ad7abb9 100644 --- a/stepmania/src/LuaManager.h +++ b/stepmania/src/LuaManager.h @@ -30,7 +30,8 @@ public: bool RunExpressionS( const CString &str, CString &sOut ); /* If sStr begins with @, evaluate the rest as an expression and store the result over sStr. */ - bool RunAtExpression( CString &sStr ); + bool RunAtExpressionS( CString &sStr ); + float RunAtExpressionF( const CString &sStr ); void Fail( const CString &err ); diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index ddba54345a..22e84b7923 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -550,7 +550,7 @@ public: Luna::Register( L ); // Add global singleton if constructed already. If it's not constructed yet, - // then we'll register it later when we reload the theme just before + // then we'll register it later when we reinit Lua just before // initializing the display. if( PROFILEMAN ) { diff --git a/stepmania/src/RollingNumbers.cpp b/stepmania/src/RollingNumbers.cpp index 950360711c..8e52c0fd00 100644 --- a/stepmania/src/RollingNumbers.cpp +++ b/stepmania/src/RollingNumbers.cpp @@ -26,9 +26,12 @@ void RollingNumbers::LoadFromNode( const CString& sDir, const XNode* pNode ) pNode->GetAttrValue( "Format", m_sFormat ); pNode->GetAttrValue( "ApproachSeconds", m_fApproachSeconds ); - float fTargetNumber; - if( pNode->GetAttrValue( "TargetNumber", fTargetNumber ) ) + CString sTargetNumber; + if( pNode->GetAttrValue( "TargetNumber", sTargetNumber ) ) + { + float fTargetNumber = LUA->RunExpressionF(sTargetNumber); SetTargetNumber( fTargetNumber ); + } UpdateText(); } diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index af29e02085..c95f4cc12a 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -677,7 +677,7 @@ 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( LUA->RunAtExpression( sText ) ) + if( LUA->RunAtExpressionS( sText ) ) return; // "::" means newline since you can't use line breaks in an ini file.