use LuaHelpers::FromStack to generalize metrics
This commit is contained in:
@@ -891,79 +891,52 @@ RString ThemeManager::GetMetricRaw( const IniFile &ini, const RString &sClassNam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void GetAndConvertMetric( const RString &sClassName, const RString &sValueName, T &out )
|
||||||
|
{
|
||||||
|
Lua *L = LUA->Get();
|
||||||
|
|
||||||
|
THEME->PushMetric( L, sClassName, sValueName );
|
||||||
|
LuaHelpers::FromStack( L, out, -1 );
|
||||||
|
lua_pop( L, 1 );
|
||||||
|
|
||||||
|
LUA->Release(L);
|
||||||
|
}
|
||||||
|
|
||||||
/* Get a string metric. */
|
/* Get a string metric. */
|
||||||
RString ThemeManager::GetMetric( const RString &sClassName, const RString &sValueName )
|
RString ThemeManager::GetMetric( const RString &sClassName, const RString &sValueName )
|
||||||
{
|
{
|
||||||
RString sValue = GetMetricRaw( g_pLoadedThemeData->iniMetrics, sClassName, sValueName);
|
|
||||||
|
|
||||||
RString sRet;
|
RString sRet;
|
||||||
LuaHelpers::RunExpressionS( sValue, sRet );
|
GetAndConvertMetric( sClassName, sValueName, sRet );
|
||||||
return sRet;
|
return sRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ThemeManager::GetMetricI( const RString &sClassName, const RString &sValueName )
|
int ThemeManager::GetMetricI( const RString &sClassName, const RString &sValueName )
|
||||||
{
|
{
|
||||||
RString sValue = GetMetricRaw( g_pLoadedThemeData->iniMetrics, sClassName, sValueName );
|
int iRet = 0;
|
||||||
|
GetAndConvertMetric( sClassName, sValueName, iRet );
|
||||||
LuaHelpers::PrepareExpression( sValue );
|
return iRet;
|
||||||
|
|
||||||
return LuaHelpers::RunExpressionI( sValue );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float ThemeManager::GetMetricF( const RString &sClassName, const RString &sValueName )
|
float ThemeManager::GetMetricF( const RString &sClassName, const RString &sValueName )
|
||||||
{
|
{
|
||||||
RString sValue = GetMetricRaw( g_pLoadedThemeData->iniMetrics, sClassName, sValueName );
|
float fRet = 0;
|
||||||
|
GetAndConvertMetric( sClassName, sValueName, fRet );
|
||||||
LuaHelpers::PrepareExpression( sValue );
|
return fRet;
|
||||||
|
|
||||||
return LuaHelpers::RunExpressionF( sValue );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// #include "LuaManager.h"
|
|
||||||
bool ThemeManager::GetMetricB( const RString &sClassName, const RString &sValueName )
|
bool ThemeManager::GetMetricB( const RString &sClassName, const RString &sValueName )
|
||||||
{
|
{
|
||||||
RString sValue = GetMetricRaw( g_pLoadedThemeData->iniMetrics, sClassName, sValueName );
|
bool bRet = 0;
|
||||||
|
GetAndConvertMetric( sClassName, sValueName, bRet );
|
||||||
if( sValue.Left(1) == "0" || sValue.Left(1) == "1" )
|
return bRet;
|
||||||
RageException::Throw( "Theme metric %s::%s: boolean value \"%s\" should be true or false",
|
|
||||||
sClassName.c_str(), sValueName.c_str(), sValue.c_str() );
|
|
||||||
|
|
||||||
LuaHelpers::PrepareExpression( sValue );
|
|
||||||
|
|
||||||
return LuaHelpers::RunExpressionB( sValue );
|
|
||||||
}
|
|
||||||
|
|
||||||
static RageColor RunExpressionC( const RString &sExpr )
|
|
||||||
{
|
|
||||||
Lua *L = LUA->Get();
|
|
||||||
|
|
||||||
LuaReference val;
|
|
||||||
if( !val.SetFromExpression(sExpr) )
|
|
||||||
{
|
|
||||||
LUA->Release( L );
|
|
||||||
return RageColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
val.PushSelf( L );
|
|
||||||
|
|
||||||
if( lua_type(L, -1) != LUA_TTABLE )
|
|
||||||
RageException::Throw( "Color expression: \"%s\" did not return a table", sExpr.c_str() );
|
|
||||||
|
|
||||||
RageColor result;
|
|
||||||
result.FromStack( L, -1 );
|
|
||||||
lua_pop( L, 1 );
|
|
||||||
|
|
||||||
LUA->Release(L);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RageColor ThemeManager::GetMetricC( const RString &sClassName, const RString &sValueName )
|
RageColor ThemeManager::GetMetricC( const RString &sClassName, const RString &sValueName )
|
||||||
{
|
{
|
||||||
RString sValue = GetMetricRaw( g_pLoadedThemeData->iniMetrics, sClassName, sValueName );
|
RageColor ret;
|
||||||
|
GetAndConvertMetric( sClassName, sValueName, ret );
|
||||||
LuaHelpers::PrepareExpression( sValue );
|
return ret;
|
||||||
|
|
||||||
return RunExpressionC( sValue );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaReference ThemeManager::GetMetricR( const RString &sClassName, const RString &sValueName )
|
LuaReference ThemeManager::GetMetricR( const RString &sClassName, const RString &sValueName )
|
||||||
|
|||||||
Reference in New Issue
Block a user