split GameState::ApplyGameCommand from GameState::ApplyCmdline;
expose to Lua
This commit is contained in:
@@ -79,6 +79,21 @@ GameState::~GameState()
|
|||||||
SAFE_DELETE( m_pPlayerState[p] );
|
SAFE_DELETE( m_pPlayerState[p] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameState::ApplyGameCommand( const CString &sCommand, PlayerNumber pn )
|
||||||
|
{
|
||||||
|
GameCommand m;
|
||||||
|
m.Load( 0, ParseCommands(sCommand) );
|
||||||
|
|
||||||
|
CString sWhy;
|
||||||
|
if( !m.IsPlayable(&sWhy) )
|
||||||
|
RageException::Throw( "Can't apply mode \"%s\": %s", sCommand.c_str(), sWhy.c_str() );
|
||||||
|
|
||||||
|
if( pn == PLAYER_INVALID )
|
||||||
|
m.ApplyToAllPlayers();
|
||||||
|
else
|
||||||
|
m.Apply( pn );
|
||||||
|
}
|
||||||
|
|
||||||
void GameState::ApplyCmdline()
|
void GameState::ApplyCmdline()
|
||||||
{
|
{
|
||||||
/* We need to join players before we can set the style. */
|
/* We need to join players before we can set the style. */
|
||||||
@@ -95,13 +110,7 @@ void GameState::ApplyCmdline()
|
|||||||
CString sMode;
|
CString sMode;
|
||||||
for( int i = 0; GetCommandlineArgument( "mode", &sMode, i ); ++i )
|
for( int i = 0; GetCommandlineArgument( "mode", &sMode, i ); ++i )
|
||||||
{
|
{
|
||||||
GameCommand m;
|
ApplyGameCommand( sMode );
|
||||||
m.Load( 0, ParseCommands(sMode) );
|
|
||||||
CString why;
|
|
||||||
if( !m.IsPlayable(&why) )
|
|
||||||
RageException::Throw( "Can't apply mode \"%s\": %s", sMode.c_str(), why.c_str() );
|
|
||||||
|
|
||||||
m.ApplyToAllPlayers();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1881,12 +1890,21 @@ public:
|
|||||||
static int IsPlayerEnabled( T* p, lua_State *L ) { lua_pushboolean(L, p->IsPlayerEnabled((PlayerNumber)(IArg(1)-1)) ); return 1; }
|
static int IsPlayerEnabled( T* p, lua_State *L ) { lua_pushboolean(L, p->IsPlayerEnabled((PlayerNumber)(IArg(1)-1)) ); return 1; }
|
||||||
static int IsHumanPlayer( T* p, lua_State *L ) { lua_pushboolean(L, p->IsHumanPlayer((PlayerNumber)(IArg(1)-1)) ); return 1; }
|
static int IsHumanPlayer( T* p, lua_State *L ) { lua_pushboolean(L, p->IsHumanPlayer((PlayerNumber)(IArg(1)-1)) ); return 1; }
|
||||||
static int GetPlayerDisplayName( T* p, lua_State *L ) { lua_pushstring(L, p->GetPlayerDisplayName((PlayerNumber)(IArg(1)-1)) ); return 1; }
|
static int GetPlayerDisplayName( T* p, lua_State *L ) { lua_pushstring(L, p->GetPlayerDisplayName((PlayerNumber)(IArg(1)-1)) ); return 1; }
|
||||||
|
static int ApplyGameCommand( T* p, lua_State *L )
|
||||||
|
{
|
||||||
|
PlayerNumber pn = PLAYER_INVALID;
|
||||||
|
if( lua_gettop(L) >= 2 && !lua_isnil(L,2) )
|
||||||
|
pn = (PlayerNumber)(IArg(2)-1);
|
||||||
|
p->ApplyGameCommand(SArg(1),pn);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void Register(lua_State *L)
|
static void Register(lua_State *L)
|
||||||
{
|
{
|
||||||
ADD_METHOD( IsPlayerEnabled )
|
ADD_METHOD( IsPlayerEnabled )
|
||||||
ADD_METHOD( IsHumanPlayer )
|
ADD_METHOD( IsHumanPlayer )
|
||||||
ADD_METHOD( GetPlayerDisplayName )
|
ADD_METHOD( GetPlayerDisplayName )
|
||||||
|
ADD_METHOD( ApplyGameCommand )
|
||||||
Luna<T>::Register( L );
|
Luna<T>::Register( L );
|
||||||
|
|
||||||
// add global singleton
|
// add global singleton
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public:
|
|||||||
~GameState();
|
~GameState();
|
||||||
void Reset();
|
void Reset();
|
||||||
void ApplyCmdline(); // called by Reset
|
void ApplyCmdline(); // called by Reset
|
||||||
|
void ApplyGameCommand( const CString &sCommand, PlayerNumber pn=PLAYER_INVALID );
|
||||||
void BeginGame(); // called when first player joins
|
void BeginGame(); // called when first player joins
|
||||||
void JoinPlayer( PlayerNumber pn );
|
void JoinPlayer( PlayerNumber pn );
|
||||||
void PlayersFinalized(); // called after a style is chosen, which means the number of players is finalized
|
void PlayersFinalized(); // called after a style is chosen, which means the number of players is finalized
|
||||||
|
|||||||
Reference in New Issue
Block a user