From 6757ab0c8cdcef517aa131ca432326b627d5a232 Mon Sep 17 00:00:00 2001 From: Kyzentun Date: Fri, 29 Aug 2014 20:06:50 -0600 Subject: [PATCH] Added WheelItemBase:IsLoaded lua function and associated error. --- Docs/Luadoc/Lua.xml | 5 +++-- Docs/Luadoc/LuaDocumentation.xml | 8 ++++++-- src/WheelItemBase.cpp | 34 ++++++++++++++++++++++++++++---- src/WheelItemBase.h | 7 ++++--- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Docs/Luadoc/Lua.xml b/Docs/Luadoc/Lua.xml index db074c8a9e..3e9d5c4669 100644 --- a/Docs/Luadoc/Lua.xml +++ b/Docs/Luadoc/Lua.xml @@ -725,8 +725,8 @@ - - + + @@ -1770,6 +1770,7 @@ + diff --git a/Docs/Luadoc/LuaDocumentation.xml b/Docs/Luadoc/LuaDocumentation.xml index fef788ae36..b0ad156762 100644 --- a/Docs/Luadoc/LuaDocumentation.xml +++ b/Docs/Luadoc/LuaDocumentation.xml @@ -2188,10 +2188,10 @@ save yourself some time, copy this for undocumented things: Returns a table of all selectable games. - + Returns a table of all the styles for the that exist for game. - + Sets the current game to Game. The second argument is optional, and if provided will determine which theme is loaded when the game changes. If the second argument is not provided, the default theme from the preferences for the new game type will be loaded.
If only the game changes, the screen specified by the Common::AfterGameChangeScreen metric will be loaded.
@@ -4995,6 +4995,10 @@ save yourself some time, copy this for undocumented things: Returns the type of this wheel item. + + Returns whether the wheel item has been loaded yet. If this function returns false, calling any other WheelItemBase function will result in an error.
+ A specific case where this is known to happen is commands that trigger on CurrentSongChanged because the music wheel clears the current song before it finishes loading if the current song is longer than the number of stages remaining. +
diff --git a/src/WheelItemBase.cpp b/src/WheelItemBase.cpp index af80aac741..08bb71d362 100644 --- a/src/WheelItemBase.cpp +++ b/src/WheelItemBase.cpp @@ -87,11 +87,36 @@ void WheelItemBase::DrawPrimitives() class LunaWheelItemBase: public Luna { public: - DEFINE_METHOD( GetColor, GetColor() ) - DEFINE_METHOD( GetText, GetText() ) +#define IS_LOADED_CHECK \ + if(!p->IsLoaded()) \ + { \ + luaL_error(L, "Wheel item is not loaded yet. Use WheelItem:IsLoaded() to check."); \ + } + + static int GetColor(T* p, lua_State *L) + { + IS_LOADED_CHECK; + LuaHelpers::Push(L, p->GetColor()); + return 1; + } + + static int GetText(T* p, lua_State *L) + { + IS_LOADED_CHECK; + LuaHelpers::Push(L, p->GetText()); + return 1; + } - static int GetType( T* p, lua_State *L ) { - lua_pushnumber( L, p->GetType() ); + static int GetType(T* p, lua_State *L) + { + IS_LOADED_CHECK; + lua_pushnumber(L, p->GetType()); + return 1; + } + + static int IsLoaded(T* p, lua_State *L) + { + lua_pushboolean(L, p->IsLoaded()); return 1; } @@ -100,6 +125,7 @@ public: ADD_METHOD( GetColor ); ADD_METHOD( GetText ); ADD_METHOD( GetType ); + ADD_METHOD( IsLoaded ); } }; LUA_REGISTER_DERIVED_CLASS( WheelItemBase, ActorFrame ) diff --git a/src/WheelItemBase.h b/src/WheelItemBase.h index 0dc1146636..2eea82e4db 100644 --- a/src/WheelItemBase.h +++ b/src/WheelItemBase.h @@ -51,9 +51,10 @@ public: RageColor m_colorLocked; - const RString GetText(){ return m_pData->m_sText; } - const RageColor GetColor(){ return m_pData->m_color; } - WheelItemDataType GetType(){ return m_pData->m_Type; } + const RString GetText(){ ASSERT(m_pData != NULL); return m_pData->m_sText; } + const RageColor GetColor(){ ASSERT(m_pData != NULL); return m_pData->m_color; } + WheelItemDataType GetType(){ ASSERT(m_pData != NULL); return m_pData->m_Type; } + bool IsLoaded(){ return m_pData != NULL; } // Lua void PushSelf( lua_State *L );