diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index 6c5416ffaa..c997e45ada 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -100,6 +100,9 @@ void Profile::InitGeneralData() m_iNumSongsPlayedByMeter[i] = 0; ZERO( m_iNumStagesPassedByPlayMode ); ZERO( m_iNumStagesPassedByGrade ); + + lua_newtable( LUA->L ); + m_SavedLuaData.SetFromStack(); } void Profile::InitSongScores() @@ -805,6 +808,7 @@ XNode* Profile::SaveGeneralDataCreateNode() const pGeneralDataNode->AppendChild( "TotalHolds", m_iTotalHolds ); pGeneralDataNode->AppendChild( "TotalMines", m_iTotalMines ); pGeneralDataNode->AppendChild( "TotalHands", m_iTotalHands ); + pGeneralDataNode->AppendChild( "Data", m_SavedLuaData.Serialize() ); // Keep declared variables in a very local scope so they aren't // accidentally used where they're not intended. There's a lot of @@ -956,6 +960,20 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode ) pNode->GetChildValue( "TotalMines", m_iTotalMines ); pNode->GetChildValue( "TotalHands", m_iTotalHands ); + { + CString sData; + if( pNode->GetChildValue( "Data", sData ) ) + { + m_SavedLuaData.LoadFromString( sData ); + if( m_SavedLuaData.GetLuaType() != LUA_TTABLE ) + { + LOG->Warn( "Profile data did not evaluate to a table" ); + lua_newtable( LUA->L ); + m_SavedLuaData.SetFromStack(); + } + } + } + { const XNode* pDefaultModifiers = pNode->GetChild("DefaultModifiers"); if( pDefaultModifiers ) @@ -1658,11 +1676,13 @@ public: static int GetGoalCalories( T* p, lua_State *L ) { lua_pushnumber(L, p->m_iGoalCalories ); return 1; } static int GetCaloriesBurnedToday( T* p, lua_State *L ) { lua_pushnumber(L, p->GetCaloriesBurnedToday() ); return 1; } + static int GetSaved( T* p, lua_State *L ) { p->m_SavedLuaData.PushSelf(L); return 1; } static void Register(lua_State *L) { ADD_METHOD( GetGoalCalories ) ADD_METHOD( GetCaloriesBurnedToday ) + ADD_METHOD( GetSaved ) Luna::Register( L ); } }; diff --git a/stepmania/src/Profile.h b/stepmania/src/Profile.h index 9b64071368..7b640bee00 100644 --- a/stepmania/src/Profile.h +++ b/stepmania/src/Profile.h @@ -14,6 +14,7 @@ #include "CourseUtil.h" // for CourseID #include "TrailUtil.h" // for TrailID #include "StyleUtil.h" // for StyleID +#include "LuaReference.h" // for LuaData struct XNode; struct lua_State; @@ -303,6 +304,7 @@ public: // Lua void PushSelf( lua_State *L ); + LuaData m_SavedLuaData; private: const HighScoresForASong *GetHighScoresForASong( const SongID& songID ) const;