From 5fd0d235c4b2732acca9e90cab220285f3bed966 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 24 Apr 2005 00:07:12 +0000 Subject: [PATCH] add FindCode helper --- stepmania/src/UnlockManager.cpp | 26 ++++++++++++++++++++++++++ stepmania/src/UnlockManager.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/stepmania/src/UnlockManager.cpp b/stepmania/src/UnlockManager.cpp index 9644ace101..48a3374b83 100644 --- a/stepmania/src/UnlockManager.cpp +++ b/stepmania/src/UnlockManager.cpp @@ -48,6 +48,30 @@ void UnlockManager::UnlockSong( const Song *song ) UnlockCode( p->m_iCode ); } +int UnlockManager::FindCode( const CString &sName ) const +{ + const UnlockEntry *pEntry = NULL; + + const Song *pSong = SONGMAN->FindSong( sName ); + if( pSong != NULL ) + pEntry = FindSong( pSong ); + + const Course *pCourse = SONGMAN->FindCourse( sName ); + if( pCourse != NULL ) + pEntry = FindCourse( pCourse ); + + if( pEntry == NULL ) + pEntry = FindModifier( sName ); + + if( pEntry == NULL ) + { + LOG->Warn( "Couldn't find locked entry \"%s\"", sName.c_str() ); + return -1; + } + + return pEntry->m_iCode; +} + bool UnlockManager::CourseIsLocked( const Course *course ) const { if( !PREFSMAN->m_bUseUnlockSystem ) @@ -407,11 +431,13 @@ class LunaUnlockManager: public Luna public: LunaUnlockManager() { LUA->Register( Register ); } + static int FindCode( T* p, lua_State *L ) { CString sName = SArg(1); lua_pushnumber(L, p->FindCode(sName)); return 1; } static int UnlockCode( T* p, lua_State *L ) { int iCode = IArg(1); p->UnlockCode(iCode); return 0; } static int PreferUnlockCode( T* p, lua_State *L ) { int iCode = IArg(1); p->PreferUnlockCode(iCode); return 0; } static void Register(lua_State *L) { + ADD_METHOD( FindCode ) ADD_METHOD( UnlockCode ) ADD_METHOD( PreferUnlockCode ) Luna::Register( L ); diff --git a/stepmania/src/UnlockManager.h b/stepmania/src/UnlockManager.h index cbe8f20176..ba5f11fdec 100644 --- a/stepmania/src/UnlockManager.h +++ b/stepmania/src/UnlockManager.h @@ -81,6 +81,9 @@ public: // Unlocks a song. void UnlockSong( const Song *song ); + // Return the associated code. + int FindCode( const CString &sName ) const; + // All locked songs are stored here vector m_UnlockEntries;