From d5cfb747097186d6a0487662a308f9990e7b91f4 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 16 Feb 2005 06:24:33 +0000 Subject: [PATCH] split GameState::ApplyGameCommand from GameState::ApplyCmdline; expose to Lua --- stepmania/src/GameState.cpp | 32 +++++++++++++++++++++++++------- stepmania/src/GameState.h | 1 + 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 20f3b8f5c2..8bfa297405 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -79,6 +79,21 @@ GameState::~GameState() 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() { /* We need to join players before we can set the style. */ @@ -95,13 +110,7 @@ void GameState::ApplyCmdline() CString sMode; for( int i = 0; GetCommandlineArgument( "mode", &sMode, i ); ++i ) { - GameCommand m; - 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(); + ApplyGameCommand( sMode ); } } @@ -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 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 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) { ADD_METHOD( IsPlayerEnabled ) ADD_METHOD( IsHumanPlayer ) ADD_METHOD( GetPlayerDisplayName ) + ADD_METHOD( ApplyGameCommand ) Luna::Register( L ); // add global singleton diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index c23e165c35..d78f9a9d4a 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -33,6 +33,7 @@ public: ~GameState(); void Reset(); void ApplyCmdline(); // called by Reset + void ApplyGameCommand( const CString &sCommand, PlayerNumber pn=PLAYER_INVALID ); void BeginGame(); // called when first player joins void JoinPlayer( PlayerNumber pn ); void PlayersFinalized(); // called after a style is chosen, which means the number of players is finalized