From 1b16ab4ee65ed8baa6fa3b7c6ad2fc1c67e6b03b Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 24 Feb 2005 22:34:54 +0000 Subject: [PATCH] add UnlockManager::PreferUnlockCode --- stepmania/src/UnlockManager.cpp | 19 +++++++++++++++++++ stepmania/src/UnlockManager.h | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/stepmania/src/UnlockManager.cpp b/stepmania/src/UnlockManager.cpp index 3d78a9dd3b..799665c9aa 100644 --- a/stepmania/src/UnlockManager.cpp +++ b/stepmania/src/UnlockManager.cpp @@ -380,6 +380,23 @@ void UnlockManager::UnlockCode( int num ) PROFILEMAN->GetMachineProfile()->m_UnlockedSongs.insert( num ); } +void UnlockManager::PreferUnlockCode( int iCode ) +{ + LOG->Trace( "look for %i", iCode ); + for( unsigned i = 0; i < m_SongEntries.size(); ++i ) + { + UnlockEntry &pEntry = m_SongEntries[i]; + if( pEntry.m_iCode != iCode ) + continue; + LOG->Trace( "found %i, %p", iCode, pEntry.m_pSong ); + + if( pEntry.m_pSong != NULL ) + GAMESTATE->m_pPreferredSong = pEntry.m_pSong; + if( pEntry.m_pCourse != NULL ) + GAMESTATE->m_pPreferredCourse = pEntry.m_pCourse; + } +} + int UnlockManager::GetNumUnlocks() const { return m_SongEntries.size(); @@ -394,10 +411,12 @@ public: LunaUnlockManager() { LUA->Register( Register ); } 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( UnlockCode ) + ADD_METHOD( PreferUnlockCode ) Luna::Register( L ); // Add global singleton if constructed already. If it's not constructed yet, diff --git a/stepmania/src/UnlockManager.h b/stepmania/src/UnlockManager.h index 3686402034..937ff19e42 100644 --- a/stepmania/src/UnlockManager.h +++ b/stepmania/src/UnlockManager.h @@ -71,6 +71,12 @@ public: // Unlock an entry by code. void UnlockCode( int num ); + /* + * If a code is associated with at least one song or course, set the preferred song + * and/or course in GAMESTATE to them. + */ + void PreferUnlockCode( int iCode ); + // Unlocks a song. void UnlockSong( const Song *song );