From 81080ce9ce16b72db05e1ce7815dc7d9889ab4f6 Mon Sep 17 00:00:00 2001 From: sigatrev Date: Wed, 13 Aug 2014 22:04:54 -0500 Subject: [PATCH] Add SetCurrentPlayMode and SetCurrentStyle methods because there needs to be a way other than using antiquated GameCommands --- Docs/Luadoc/Lua.xml | 2 + Docs/Luadoc/LuaDocumentation.xml | 6 +++ src/GameState.cpp | 93 ++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/Docs/Luadoc/Lua.xml b/Docs/Luadoc/Lua.xml index a06025a9f1..f5bb8a550e 100644 --- a/Docs/Luadoc/Lua.xml +++ b/Docs/Luadoc/Lua.xml @@ -837,8 +837,10 @@ + + diff --git a/Docs/Luadoc/LuaDocumentation.xml b/Docs/Luadoc/LuaDocumentation.xml index 0f9b57048b..c5e6a5ddda 100644 --- a/Docs/Luadoc/LuaDocumentation.xml +++ b/Docs/Luadoc/LuaDocumentation.xml @@ -2556,12 +2556,18 @@ save yourself some time, copy this for undocumented things: Sets the current Course to course. + + Sets the current PlayMode to pm. + Sets the current Song to song. Sets Player pn's current Steps to steps. + + Sets current Style to the provided style. Either a style object or a style string can be provided. If current steps for either player are not valid in the new style, they will be cleared. + Sets the current Trail to trail. diff --git a/src/GameState.cpp b/src/GameState.cpp index 3dbf40f8aa..fd2c05eb0d 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -2643,6 +2643,97 @@ public: DEFINE_METHOD( HaveProfileToLoad, HaveProfileToLoad() ) DEFINE_METHOD( HaveProfileToSave, HaveProfileToSave() ) + static bool AreStyleAndPlayModeCompatible( T* p, lua_State* L, const Style *style, PlayMode pm ) + { + if( pm != PLAY_MODE_BATTLE && pm != PLAY_MODE_RAVE ) + { + return true; + } + + // Do not allow styles with StepsTypes with shared sides or that are one player only with Battle or Rave. + if( style->m_StyleType != StyleType_TwoPlayersSharedSides ) + { + vector vpStyles; + GAMEMAN->GetCompatibleStyles( p->m_pCurGame, 2, vpStyles ); + FOREACH_CONST( const Style*, vpStyles, s ) + { + if( (*s)->m_StepsType == style->m_StepsType ) + { + return true; + } + } + } + luaL_error( L, "Style %s is incompatible with PlayMode %s", + style->m_szName, PlayModeToString( pm ).c_str() ); + return false; + } + + static void ClearIncompatibleStepsAndTrails( T *p, lua_State* L ) + { + const Style *style = p->m_pCurStyle; + FOREACH_HumanPlayer( pn ) + { + if( p->m_pCurSteps[pn] && ( !style || style->m_StepsType != p->m_pCurSteps[pn]->m_StepsType ) ) + { + p->m_pCurSteps[pn].Set( NULL ); + } + if( p->m_pCurTrail[pn] && ( !style || style->m_StepsType != p->m_pCurTrail[pn]->m_StepsType ) ) + { + p->m_pCurTrail[pn].Set( NULL ); + } + } + } + + static int SetCurrentStyle( T* p, lua_State *L ) + { + const Style* pStyle = NULL; + if( lua_isstring(L,1) ) + { + RString style = SArg(1); + pStyle = GAMEMAN->GameAndStringToStyle( GAMESTATE->m_pCurGame, style ); + if( !pStyle ) + { + luaL_error( L, "SetCurrentStyle: %s is not a valid style.", style.c_str() ); + } + } + else + { + pStyle = Luna