Merge pull request #264 from sigatrev/SetStyleAndPlayMode
Add SetCurrentPlayMode and SetCurrentStyle methods
This commit is contained in:
@@ -837,8 +837,10 @@
|
|||||||
<Function name='SaveProfiles'/>
|
<Function name='SaveProfiles'/>
|
||||||
<Function name='SetCharacter'/>
|
<Function name='SetCharacter'/>
|
||||||
<Function name='SetCurrentCourse'/>
|
<Function name='SetCurrentCourse'/>
|
||||||
|
<Function name='SetCurrentPlayMode'/>
|
||||||
<Function name='SetCurrentSong'/>
|
<Function name='SetCurrentSong'/>
|
||||||
<Function name='SetCurrentSteps'/>
|
<Function name='SetCurrentSteps'/>
|
||||||
|
<Function name='SetCurrentStyle'/>
|
||||||
<Function name='SetCurrentTrail'/>
|
<Function name='SetCurrentTrail'/>
|
||||||
<Function name='SetFailTypeExplicitlySet'/>
|
<Function name='SetFailTypeExplicitlySet'/>
|
||||||
<Function name='SetJukeboxUsesModifiers'/>
|
<Function name='SetJukeboxUsesModifiers'/>
|
||||||
|
|||||||
@@ -2556,12 +2556,18 @@ save yourself some time, copy this for undocumented things:
|
|||||||
<Function name='SetCurrentCourse' return='void' arguments='Course course'>
|
<Function name='SetCurrentCourse' return='void' arguments='Course course'>
|
||||||
Sets the current Course to <code>course</code>.
|
Sets the current Course to <code>course</code>.
|
||||||
</Function>
|
</Function>
|
||||||
|
<Function name='SetCurrentPlayMode' return='void' arguments='PlayMode pm'>
|
||||||
|
Sets the current PlayMode to <code>pm</code>.
|
||||||
|
</Function>
|
||||||
<Function name='SetCurrentSong' return='void' arguments='Song song'>
|
<Function name='SetCurrentSong' return='void' arguments='Song song'>
|
||||||
Sets the current Song to <code>song</code>.
|
Sets the current Song to <code>song</code>.
|
||||||
</Function>
|
</Function>
|
||||||
<Function name='SetCurrentSteps' return='void' arguments='PlayerNumber pn, Steps steps'>
|
<Function name='SetCurrentSteps' return='void' arguments='PlayerNumber pn, Steps steps'>
|
||||||
Sets Player <code>pn</code>'s current Steps to <code>steps</code>.
|
Sets Player <code>pn</code>'s current Steps to <code>steps</code>.
|
||||||
</Function>
|
</Function>
|
||||||
|
<Function name='SetCurrentStyle' return='void' arguments='Style style or string sStyle'>
|
||||||
|
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.
|
||||||
|
</Function>
|
||||||
<Function name='SetCurrentTrail' return='void' arguments='Trail trail'>
|
<Function name='SetCurrentTrail' return='void' arguments='Trail trail'>
|
||||||
Sets the current Trail to <code>trail</code>.
|
Sets the current Trail to <code>trail</code>.
|
||||||
</Function>
|
</Function>
|
||||||
|
|||||||
@@ -2643,6 +2643,97 @@ public:
|
|||||||
DEFINE_METHOD( HaveProfileToLoad, HaveProfileToLoad() )
|
DEFINE_METHOD( HaveProfileToLoad, HaveProfileToLoad() )
|
||||||
DEFINE_METHOD( HaveProfileToSave, HaveProfileToSave() )
|
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<const Style*> 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<Style>::check(L,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
StyleType st = pStyle->m_StyleType;
|
||||||
|
if( p->GetNumSidesJoined() == 2 &&
|
||||||
|
( st == StyleType_OnePlayerOneSide || st == StyleType_OnePlayerTwoSides ) )
|
||||||
|
{
|
||||||
|
luaL_error( L, "Too many sides joined for style %s", pStyle->m_szName );
|
||||||
|
}
|
||||||
|
else if( p->GetNumSidesJoined() == 1 &&
|
||||||
|
( st == StyleType_TwoPlayersTwoSides || st == StyleType_TwoPlayersSharedSides ) )
|
||||||
|
{
|
||||||
|
luaL_error( L, "Too few sides joined for style %s", pStyle->m_szName );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !AreStyleAndPlayModeCompatible( p, L, pStyle, p->m_PlayMode ) )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->SetCurrentStyle( pStyle );
|
||||||
|
ClearIncompatibleStepsAndTrails( p, L );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int SetCurrentPlayMode( T* p, lua_State *L )
|
||||||
|
{
|
||||||
|
PlayMode pm = Enum::Check<PlayMode>( L, 1 );
|
||||||
|
if( AreStyleAndPlayModeCompatible( p, L, p->m_pCurStyle, pm ) )
|
||||||
|
{
|
||||||
|
p->m_PlayMode.Set( pm );
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
LunaGameState()
|
LunaGameState()
|
||||||
{
|
{
|
||||||
ADD_METHOD( IsPlayerEnabled );
|
ADD_METHOD( IsPlayerEnabled );
|
||||||
@@ -2760,6 +2851,8 @@ public:
|
|||||||
ADD_METHOD( HaveProfileToSave );
|
ADD_METHOD( HaveProfileToSave );
|
||||||
ADD_METHOD( SetFailTypeExplicitlySet );
|
ADD_METHOD( SetFailTypeExplicitlySet );
|
||||||
ADD_METHOD( StoreRankingName );
|
ADD_METHOD( StoreRankingName );
|
||||||
|
ADD_METHOD( SetCurrentStyle );
|
||||||
|
ADD_METHOD( SetCurrentPlayMode );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user