static int ReadBytes( T* p, lua_State *L )
	{
		RString string;
		p->Read( string, IArg(1) );
		lua_pushstring( L, string );
		return 1;
	}
Beispiel #2
0
	static int PostScreenMessage( T* p, lua_State *L )
	{
		RString sMessage = SArg(1);
		ScreenMessage SM = ScreenMessageHelpers::ToScreenMessage( sMessage );
		p->PostScreenMessage( SM, IArg(2) );
		return 0;
	}
Beispiel #3
0
	static int ReadBytes( T* p, lua_State *L )
	{
		can_safely_read(p, L);
		RString string;
		p->Read( string, IArg(1) );
		lua_pushstring( L, string );
		return 1;
	}
Beispiel #4
0
	static int GetTextureCoordRect(T* p, lua_State* L)
	{
		const RectF* pRect = p->GetTextureCoordRect(IArg(1));
		lua_pushnumber(L, pRect->left);
		lua_pushnumber(L, pRect->top);
		lua_pushnumber(L, pRect->right);
		lua_pushnumber(L, pRect->bottom);
		return 4;
	}
Beispiel #5
0
	static int GetColumnDrawOrder( T* p, lua_State *L )
	{
		int iCol = IArg(1) - 1;
		if( iCol < 0 || iCol >= p->m_iColsPerPlayer*NUM_PLAYERS )
		{
			LOG->Warn( "Style:GetColumnDrawOrder(): column %i out of range( 1 to %i )", iCol+1, p->m_iColsPerPlayer*NUM_PLAYERS );
			return 0;
		}
		lua_pushnumber( L, p->m_iColumnDrawOrder[iCol]+1 );
		return 1;
	}
Beispiel #6
0
    static int GetWheelItem( T* p, lua_State *L )
    {
        int iItem = IArg(1);

        WheelItemBase *pItem = p->GetWheelItem( iItem );
        if( pItem == NULL )
            luaL_error( L, "%i out of bounds", iItem );
        pItem->PushSelf( L );

        return 1;
    }
Beispiel #7
0
	static int GetColumnInfo( T* p, lua_State *L )
	{
		PlayerNumber pn = Enum::Check<PlayerNumber>(L, 1);
		int iCol = IArg(2) - 1;
		if( iCol < 0 || iCol >= p->m_iColsPerPlayer )
		{
			LOG->Warn( "Style:GetColumnDrawOrder(): column %i out of range( 1 to %i )", iCol+1, p->m_iColsPerPlayer );
			return 0;
		}

		LuaTable ret;
		lua_pushnumber( L, p->m_ColumnInfo[pn][iCol].track+1 );
		ret.Set( L, "Track" );
		lua_pushnumber( L, p->m_ColumnInfo[pn][iCol].fXOffset );
		ret.Set( L,  "XOffset" );
		lua_pushstring( L, p->ColToButtonName(iCol) );
		ret.Set( L, "Name" );
		
		ret.PushSelf(L); 
		return 1;
	}
Beispiel #8
0
	static int Open( T* p, lua_State *L )
	{
		lua_pushboolean( L, p->Open( SArg(1), IArg(2) ) );
		return 1;
	}
Beispiel #9
0
	static int GetValue( T* p, lua_State *L ) { lua_pushnumber( L, p->m_Values.f[IArg(1)] ); return 1; }
Beispiel #10
0
	static int Seek( T* p, lua_State *L )
	{
		lua_pushinteger( L, p->Seek( IArg(1) ) );
		return 1;
	}
Beispiel #11
0
	static int SetStateProperties(T* p, lua_State* L)
	{
		// States table example:
		// {{Frame= 0, Delay= .016, {0, 0}, {.25, .25}}}
		// Each element in the States table must have a Frame and a Delay.
		// Frame is optional, defaulting to 0.
		// Delay is optional, defaulting to 0.
		// The two tables in the state are the upper left and lower right and are
		// optional.
		if(!lua_istable(L, 1))
		{
			luaL_error(L, "State properties must be in a table.");
		}
		vector<Sprite::State> new_states;
		size_t num_states= lua_objlen(L, 1);
		if(num_states == 0)
		{
			luaL_error(L, "A Sprite cannot have zero states.");
		}
		for(size_t s= 0; s < num_states; ++s)
		{
			Sprite::State new_state;
			lua_rawgeti(L, 1, s+1);
			lua_getfield(L, -1, "Frame");
			int frame_index= 0;
			if(lua_isnumber(L, -1))
			{
				frame_index= IArg(-1);
				if(frame_index < 0 || frame_index >= p->GetTexture()->GetNumFrames())
				{
					luaL_error(L, "Frame index out of range 0-%d.",
						p->GetTexture()->GetNumFrames()-1);
				}
			}
			new_state.rect= *p->GetTexture()->GetTextureCoordRect(frame_index);
			lua_pop(L, 1);
			lua_getfield(L, -1, "Delay");
			if(lua_isnumber(L, -1))
			{
				new_state.fDelay= FArg(-1);
			}
			lua_pop(L, 1);
			RectF r= new_state.rect;
			lua_rawgeti(L, -1, 1);
			if(lua_istable(L, -1))
			{
				lua_rawgeti(L, -1, 1);
				// I have no idea why the points are from 0 to 1 and make it use only
				// a portion of the state.  This is just copied from LoadFromNode.
				// -Kyz
				new_state.rect.left= SCALE(FArg(-1), 0.0f, 1.0f, r.left, r.right);
				lua_pop(L, 1);
				lua_rawgeti(L, -1, 2);
				new_state.rect.top= SCALE(FArg(-1), 0.0f, 1.0f, r.top, r.bottom);
				lua_pop(L, 1);
			}
			lua_pop(L, 1);
			lua_rawgeti(L, -1, 2);
			if(lua_istable(L, -1))
			{
				lua_rawgeti(L, -1, 1);
				// I have no idea why the points are from 0 to 1 and make it use only
				// a portion of the state.  This is just copied from LoadFromNode.
				// -Kyz
				new_state.rect.right= SCALE(FArg(-1), 0.0f, 1.0f, r.left, r.right);
				lua_pop(L, 1);
				lua_rawgeti(L, -1, 2);
				new_state.rect.bottom= SCALE(FArg(-1), 0.0f, 1.0f, r.top, r.bottom);
				lua_pop(L, 1);
			}
			lua_pop(L, 1);
			new_states.push_back(new_state);
			lua_pop(L, 1);
		}
		p->SetStateProperties(new_states);
		COMMON_RETURN_SELF;
	}
Beispiel #12
0
	static int setstate( T* p, lua_State *L )		{ p->SetState( IArg(1) ); COMMON_RETURN_SELF; }
Beispiel #13
0
	static int ChangeLives( T* p, lua_State *L )	{ p->ChangeLives(IArg(1)); return 0; }
Beispiel #14
0
	static int SetNumSubdivisions( T* p, lua_State *L )		{ p->SetNumSubdivisions(IArg(1)); return 0; }
Beispiel #15
0
	CString sReturn = ssprintf( "%01d:%02d.%02d", iMinsDisplay, iSecsDisplay, min(99,iLeftoverDisplay) );
	return sReturn;
}

CString SecondsToMMSSMsMsMs( float fSecs )
{
	const int iMinsDisplay = (int)fSecs/60;
	const int iSecsDisplay = (int)fSecs - iMinsDisplay*60;
	const int iLeftoverDisplay = (int) ( (fSecs - iMinsDisplay*60 - iSecsDisplay) * 1000 );
	CString sReturn = ssprintf( "%02d:%02d.%03d", iMinsDisplay, iSecsDisplay, min(999,iLeftoverDisplay) );
	return sReturn;
}

#include "LuaFunctions.h"
#include "LuaManager.h"
LuaFunction( SecondsToMMSS, SecondsToMMSS( IArg(1) ) )
LuaFunction( SecondsToHHMMSS, SecondsToHHMMSS( IArg(1) ) )

LuaFunction( SecondsToMSSMsMs, SecondsToMSSMsMs( FArg(1) ) )
LuaFunction( SecondsToMMSSMsMs, SecondsToMMSSMsMs( FArg(1) ) )
LuaFunction( SecondsToMMSSMsMsMs, SecondsToMMSSMsMsMs( FArg(1) ) )

CString PrettyPercent( float fNumerator, float fDenominator)
{
	return ssprintf("%0.2f%%",fNumerator/fDenominator*100);
}

CString Commify( int iNum ) 
{
	CString sNum = ssprintf("%d",iNum);
	CString sReturn;
Beispiel #16
0
#include "LuaManager.h"
#include "LuaFunctions.h"


static const CString DifficultyNames[] = {
	"Beginner",
	"Easy",
	"Medium",
	"Hard",
	"Challenge",
	"Edit",
};
XToString( Difficulty, NUM_DIFFICULTIES );
XToThemedString( Difficulty, NUM_DIFFICULTIES );

LuaFunction( DifficultyToThemedString, DifficultyToThemedString((Difficulty) IArg(1)) );

/* We prefer the above names; recognize a number of others, too.  (They'l
 * get normalized when written to SMs, etc.) */
Difficulty StringToDifficulty( const CString& sDC )
{
	CString s2 = sDC;
	s2.MakeLower();
	if( s2 == "beginner" )		return DIFFICULTY_BEGINNER;
	else if( s2 == "easy" )		return DIFFICULTY_EASY;
	else if( s2 == "basic" )	return DIFFICULTY_EASY;
	else if( s2 == "light" )	return DIFFICULTY_EASY;
	else if( s2 == "medium" )	return DIFFICULTY_MEDIUM;
	else if( s2 == "another" )	return DIFFICULTY_MEDIUM;
	else if( s2 == "trick" )	return DIFFICULTY_MEDIUM;
	else if( s2 == "standard" )	return DIFFICULTY_MEDIUM;
Beispiel #17
0
	static int Seek( T* p, lua_State *L )
	{
		can_safely_read(p, L);
		lua_pushinteger( L, p->Seek( IArg(1) ) );
		return 1;
	}
Beispiel #18
0
	"June",
	"July",
	"August",
	"September",
	"October",
	"November",
	"December",
};

CString MonthToString( int iMonthIndex )
{
	if( iMonthIndex < 0 || iMonthIndex >= (int) sizeof(MONTH_TO_NAME) )
		return "";
	return MONTH_TO_NAME[iMonthIndex];
}
LuaFunction( MonthToString, MonthToString( IArg(1) ) );

CString LastWeekToString( int iLastWeekIndex )
{
	switch( iLastWeekIndex )
	{
	case 0:		return "ThisWeek";	break;
	case 1:		return "LastWeek";	break;
	default:	return ssprintf("Week%02dAgo",iLastWeekIndex);	break;
	}
}

CString LastDayToDisplayString( int iLastDayIndex )
{
	CString s = LastDayToString( iLastDayIndex );
	s.Replace( "Day", "" );