save last N scores in profile (for tournament score tracking)

This commit is contained in:
Chris Danford
2004-04-22 07:59:42 +00:00
parent 1090b94fc6
commit 987a83d6bd
5 changed files with 139 additions and 3 deletions
+2 -1
View File
@@ -27,7 +27,8 @@ struct HighScore
CString sMachineGuid; // where this screenshot was taken
HighScore()
HighScore() { Unset(); }
void Unset()
{
grade = GRADE_NO_DATA;
iScore = 0;
+111
View File
@@ -46,6 +46,8 @@ const int SM_390A12_COURSE_SCORES_VERSION = 8;
#define GUID_SIZE_BYTES 8
#define MAX_LAST_SCORES_TO_SAVE 100
#if defined(WIN32)
#pragma warning (disable : 4706) // assignment within conditional expression
#endif
@@ -155,6 +157,11 @@ void Profile::InitAwards()
}
}
void Profile::InitLastScores()
{
m_vLastScores.clear();
}
CString Profile::GetDisplayName() const
{
if( !m_sDisplayName.empty() )
@@ -521,6 +528,7 @@ bool Profile::LoadAllFromDir( CString sDir, bool bRequireSignature )
LOAD_NODE( ScreenshotData );
LOAD_NODE( CalorieData );
LOAD_NODE( Awards );
LOAD_NODE( LastScores );
}
return true; // FIXME? Investigate what happens if we always return true.
@@ -546,6 +554,7 @@ bool Profile::SaveAllToDir( CString sDir, bool bSignData ) const
xml.AppendChild( SaveScreenshotDataCreateNode() );
xml.AppendChild( SaveCalorieDataCreateNode() );
xml.AppendChild( SaveAwardsCreateNode() );
xml.AppendChild( SaveLastScoresCreateNode() );
bool bSaved = xml.SaveToFile(fn);
if( bSaved && bSignData )
{
@@ -1790,3 +1799,105 @@ bool Profile::HasPeakComboAward( PeakComboAward pca )
{
return m_PeakComboAwards[pca].IsSet();
}
XNode* Profile::HighScoreForASongAndSteps::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "HighScoreForASongAndSteps";
pNode->AppendChild( songID.CreateNode() );
pNode->AppendChild( stepsID.CreateNode() );
pNode->AppendChild( hs.CreateNode() );
return pNode;
}
void Profile::HighScoreForASongAndSteps::LoadFromNode( const XNode* pNode )
{
Unset();
ASSERT( pNode->name == "HighScoreForASongAndSteps" );
XNode* p;
if( p = pNode->GetChild("Song") )
songID.LoadFromNode( p );
if( p = pNode->GetChild("Steps") )
stepsID.LoadFromNode( p );
if( p = pNode->GetChild("HighScore") )
hs.LoadFromNode( p );
}
void Profile::LoadLastScoresFromNode( const XNode* pNode )
{
CHECKPOINT;
ASSERT( pNode->name == "LastScores" );
for( XNodes::const_iterator p = pNode->childs.begin();
p != pNode->childs.end();
p++ )
{
if( (*p)->name == "HighScoreForASongAndSteps" )
{
HighScoreForASongAndSteps h;
h.LoadFromNode( *p );
m_vLastScores.push_back( h );
}
else
WARN_AND_CONTINUE;
}
}
XNode* Profile::SaveLastScoresCreateNode() const
{
CHECKPOINT;
const Profile* pProfile = this;
ASSERT( pProfile );
XNode* pNode = new XNode;
pNode->name = "LastScores";
unsigned uNumToSave = min( m_vLastScores.size(), (unsigned)MAX_LAST_SCORES_TO_SAVE );
for( unsigned i=0; i<uNumToSave; i++ )
{
pNode->AppendChild( m_vLastScores[i].CreateNode() );
}
return pNode;
}
void Profile::AddLastScore( Song* pSong, Steps* pSteps, HighScore hs )
{
HighScoreForASongAndSteps h;
h.songID.FromSong( pSong );
h.stepsID.FromSteps( pSteps );
h.hs = hs;
m_vLastScores.push_back( h );
}
+22
View File
@@ -237,6 +237,24 @@ public:
bool HasPerDifficultyAward( StepsType st, Difficulty dc, PerDifficultyAward pda );
bool HasPeakComboAward( PeakComboAward pca );
//
// LastScores
//
struct HighScoreForASongAndSteps
{
StepsID stepsID;
SongID songID;
HighScore hs;
HighScoreForASongAndSteps() { Unset(); }
void Unset() { stepsID.Unset(); songID.Unset(); hs.Unset(); }
XNode* CreateNode() const;
void LoadFromNode( const XNode* pNode );
};
vector<HighScoreForASongAndSteps> m_vLastScores;
void AddLastScore( Song* pSong, Steps* pSteps, HighScore hs );
//
// Init'ing
//
@@ -250,6 +268,7 @@ public:
InitScreenshotData();
InitCalorieData();
InitAwards();
InitLastScores();
}
void InitEditableData();
void InitGeneralData();
@@ -259,6 +278,7 @@ public:
void InitScreenshotData();
void InitCalorieData();
void InitAwards();
void InitLastScores();
//
// Loading and saving
@@ -279,6 +299,7 @@ public:
void LoadScreenshotDataFromNode( const XNode* pNode );
void LoadCalorieDataFromNode( const XNode* pNode );
void LoadAwardsFromNode( const XNode* pNode );
void LoadLastScoresFromNode( const XNode* pNode );
void SaveEditableDataToDir( CString sDir ) const;
XNode* SaveGeneralDataCreateNode() const;
@@ -288,6 +309,7 @@ public:
XNode* SaveScreenshotDataCreateNode() const;
XNode* SaveCalorieDataCreateNode() const;
XNode* SaveAwardsCreateNode() const;
XNode* SaveLastScoresCreateNode() const;
void DeleteProfileDataFromDirSM390a12( CString sDir ) const;
void DeleteSongScoresFromDirSM390a12( CString sDir ) const;
+2 -1
View File
@@ -39,7 +39,8 @@ class SongID
CString sDir;
public:
SongID() { FromSong(NULL); }
SongID() { Unset(); }
void Unset() { FromSong(NULL); }
void FromSong( const Song *p );
Song *ToSong() const;
bool operator<( const SongID &other ) const
+2 -1
View File
@@ -39,7 +39,8 @@ class StepsID
CString sDescription;
public:
StepsID() { FromSteps(NULL); }
StepsID() { Unset(); }
void Unset() { FromSteps(NULL); }
void FromSteps( const Steps *p );
Steps *ToSteps( const Song *p, bool bAllowNull ) const;
bool operator<( const StepsID &other ) const