From 92f49b2f8922b82ee125e49afb9d43b20c9e32d7 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 19 Jun 2005 22:41:12 +0000 Subject: [PATCH] add character bindings to remove special cases in ScreenStage --- stepmania/src/Character.cpp | 20 ++++++++++++++++++++ stepmania/src/Character.h | 6 ++++++ stepmania/src/GameState.cpp | 11 +++++++++++ 3 files changed, 37 insertions(+) diff --git a/stepmania/src/Character.cpp b/stepmania/src/Character.cpp index e63161d9bc..ca4c06d04a 100644 --- a/stepmania/src/Character.cpp +++ b/stepmania/src/Character.cpp @@ -163,6 +163,26 @@ bool Character::Has2DElems() return false; } +// lua start +#include "LuaBinding.h" + +template +class LunaCharacter : public Luna +{ +public: + LunaCharacter() { LUA->Register( Register ); } + + static int GetStageIconPath( T* p, lua_State *L ) { lua_pushstring(L, p->GetStageIconPath() ); return 1; } + static void Register( Lua *L ) + { + ADD_METHOD( GetStageIconPath ) + Luna::Register( L ); + } +}; + +LUA_REGISTER_CLASS( Character ) +// lua end + /* * (c) 2003 Chris Danford * All rights reserved. diff --git a/stepmania/src/Character.h b/stepmania/src/Character.h index 6be4345e2f..7dc75df4cb 100644 --- a/stepmania/src/Character.h +++ b/stepmania/src/Character.h @@ -4,6 +4,8 @@ #define Character_H #include "GameConstantsAndTypes.h" +struct lua_State; +typedef lua_State Lua; class Character @@ -25,6 +27,10 @@ public: CString GetStageIconPath() const; bool Has2DElems(); + // + // Lua + // + virtual void PushSelf( Lua *L ); CString m_sCharDir; CString m_sName; diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 4ead6880fb..d19bd84c16 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -2059,6 +2059,16 @@ public: } static int GetPreferredDifficulty( T* p, lua_State *L ) { lua_pushnumber(L, p->m_PreferredDifficulty[IArg(1)] ); return 1; } static int AnyPlayerHasRankingFeats( T* p, lua_State *L ) { lua_pushboolean(L, p->AnyPlayerHasRankingFeats() ); return 1; } + static int GetCharacter( T* p, lua_State *L ) + { + Character *pCharacter = p->m_pCurCharacters[IArg(1)]; + if( pCharacter != NULL ) + pCharacter->PushSelf( L ); + else + lua_pushnil( L ); + + return 1; + } static int IsCourseMode( T* p, lua_State *L ) { lua_pushboolean(L, p->IsCourseMode() ); return 1; } static int IsDemonstration( T* p, lua_State *L ) { lua_pushboolean(L, p->m_bDemonstrationOrJukebox ); return 1; } static int GetPlayMode( T* p, lua_State *L ) { lua_pushnumber(L, p->m_PlayMode ); return 1; } @@ -2111,6 +2121,7 @@ public: ADD_METHOD( GetEditSourceSteps ) ADD_METHOD( GetPreferredDifficulty ) ADD_METHOD( AnyPlayerHasRankingFeats ) + ADD_METHOD( GetCharacter ) ADD_METHOD( IsCourseMode ) ADD_METHOD( IsDemonstration ) ADD_METHOD( GetPlayMode )