save HighScore in Screenshot

This commit is contained in:
Chris Danford
2004-06-12 07:01:07 +00:00
parent 3bc4cbf9a4
commit 4fb496e4d9
7 changed files with 51 additions and 47 deletions
+24
View File
@@ -189,6 +189,30 @@ void HighScoreList::LoadFromNode( const XNode* pNode )
} }
} }
XNode* Screenshot::CreateNode() const
{
XNode* pNode = new XNode;
pNode->name = "Screenshot";
// TRICKY: Don't write "name to fill in" markers.
pNode->AppendChild( "FileName", sFileName );
pNode->AppendChild( "MD5", sMD5 );
pNode->AppendChild( highScore.CreateNode() );
return pNode;
}
void Screenshot::LoadFromNode( const XNode* pNode )
{
ASSERT( pNode->name == "Screenshot" );
pNode->GetChildValue( "FileName", sFileName );
pNode->GetChildValue( "MD5", sMD5 );
XNode* pHighScore = pNode->GetChild( "HighScore" );
if( pHighScore )
highScore.LoadFromNode( pHighScore );
}
/* /*
* (c) 2004 Chris Danford * (c) 2004 Chris Danford
* All rights reserved. * All rights reserved.
+10
View File
@@ -92,6 +92,16 @@ struct HighScoreList
void LoadFromNode( const XNode* pNode ); void LoadFromNode( const XNode* pNode );
}; };
struct Screenshot
{
CString sFileName; // no directory part - just the file name
CString sMD5; // MD5 hash of the screenshot file
HighScore highScore;
XNode* CreateNode() const;
void LoadFromNode( const XNode* pNode );
};
#endif #endif
/* /*
+6 -28
View File
@@ -1263,7 +1263,7 @@ void Profile::SaveMachinePublicKeyToDir( CString sDir ) const
FileCopy( CRYPTMAN->GetPublicKeyFileName(), sDir+PUBLIC_KEY_FILE ); FileCopy( CRYPTMAN->GetPublicKeyFileName(), sDir+PUBLIC_KEY_FILE );
} }
void Profile::AddScreenshot( Screenshot screenshot ) void Profile::AddScreenshot( const Screenshot &screenshot )
{ {
m_vScreenshots.push_back( screenshot ); m_vScreenshots.push_back( screenshot );
} }
@@ -1273,26 +1273,13 @@ void Profile::LoadScreenshotDataFromNode( const XNode* pNode )
CHECKPOINT; CHECKPOINT;
ASSERT( pNode->name == "ScreenshotData" ); ASSERT( pNode->name == "ScreenshotData" );
for( XNodes::const_iterator screenshot = pNode->childs.begin(); FOREACH_CONST( XNode*, pNode->childs, screenshot )
screenshot != pNode->childs.end();
screenshot++ )
{ {
if( (*screenshot)->name != "Screenshot" ) if( (*screenshot)->name != "Screenshot" )
WARN_AND_CONTINUE; WARN_AND_CONTINUE;
Screenshot ss; Screenshot ss;
ss.LoadFromNode( *screenshot );
if( !(*screenshot)->GetChildValue("FileName",ss.sFileName) )
WARN;
if( !(*screenshot)->GetChildValue("MD5",ss.sMD5) )
WARN;
if( !(*screenshot)->GetChildValue("Time",(int&)ss.time) ) // time_t is a signed long on Win32. Is this ok on other platforms?
WARN;
if( !(*screenshot)->GetChildValue("MachineGuid",ss.sMachineGuid) )
WARN;
m_vScreenshots.push_back( ss ); m_vScreenshots.push_back( ss );
} }
@@ -1308,16 +1295,9 @@ XNode* Profile::SaveScreenshotDataCreateNode() const
XNode* pNode = new XNode; XNode* pNode = new XNode;
pNode->name = "ScreenshotData"; pNode->name = "ScreenshotData";
for( unsigned i=0; i<m_vScreenshots.size(); i++ ) FOREACH_CONST( Screenshot, m_vScreenshots, ss )
{ {
const Screenshot &ss = m_vScreenshots[i]; XNode* pScreenshotNode = pNode->AppendChild( ss->CreateNode() );
XNode* pScreenshotNode = pNode->AppendChild( "Screenshot" );
pScreenshotNode->AppendChild( "FileName", ss.sFileName );
pScreenshotNode->AppendChild( "MD5", ss.sMD5 );
pScreenshotNode->AppendChild( "Time", (int) ss.time );
pScreenshotNode->AppendChild( "MachineGuid", ss.sMachineGuid );
} }
return pNode; return pNode;
@@ -1328,9 +1308,7 @@ void Profile::LoadCalorieDataFromNode( const XNode* pNode )
CHECKPOINT; CHECKPOINT;
ASSERT( pNode->name == "CalorieData" ); ASSERT( pNode->name == "CalorieData" );
for( XNodes::const_iterator pDay = pNode->childs.begin(); FOREACH_CONST( XNode*, pNode->childs, pDay )
pDay != pNode->childs.end();
pDay++ )
{ {
if( (*pDay)->name != "Day" ) if( (*pDay)->name != "Day" )
WARN_AND_CONTINUE; WARN_AND_CONTINUE;
+1 -8
View File
@@ -174,15 +174,8 @@ public:
// //
// Screenshot Data // Screenshot Data
// //
struct Screenshot
{
CString sFileName; // no directory part - just the file name
CString sMD5; // MD5 hash of the screenshot file
time_t time; // return value of time() when screenshot was taken
CString sMachineGuid; // where this screenshot was taken
};
vector<Screenshot> m_vScreenshots; vector<Screenshot> m_vScreenshots;
void AddScreenshot( Screenshot screenshot ); void AddScreenshot( const Screenshot &screenshot );
int GetNextScreenshotIndex() { return m_vScreenshots.size(); } int GetNextScreenshotIndex() { return m_vScreenshots.size(); }
+4 -5
View File
@@ -1138,7 +1138,7 @@ void PrintBookkeeping( RageFile &f, const Profile *pProfile, CString sTitle, vec
PRINT_CLOSE(f); PRINT_CLOSE(f);
} }
void PrintScreenshot( RageFile &f, const Profile::Screenshot &ss ) void PrintScreenshot( RageFile &f, const Screenshot &ss )
{ {
CString sImagePath = SCREENSHOTS_SUBDIR+ss.sFileName; CString sImagePath = SCREENSHOTS_SUBDIR+ss.sFileName;
CString sImgHtml = ssprintf("<a href='%s' target='_new'><img class='screenshot' src='%s' width='160' height='120'></a>", sImagePath.c_str(), sImagePath.c_str() ); CString sImgHtml = ssprintf("<a href='%s' target='_new'><img class='screenshot' src='%s' width='160' height='120'></a>", sImagePath.c_str(), sImagePath.c_str() );
@@ -1153,8 +1153,7 @@ void PrintScreenshot( RageFile &f, const Profile::Screenshot &ss )
TABLE_LINE2( "File", ss.sFileName ); TABLE_LINE2( "File", ss.sFileName );
TABLE_LINE2( "MD5", ss.sMD5 ); TABLE_LINE2( "MD5", ss.sMD5 );
TABLE_LINE2( "Time", (CString)ctime(&ss.time) ); TABLE_LINE2( "Results", HighScoreToString(ss.highScore) );
TABLE_LINE2( "Machine", ss.sMachineGuid );
END_TABLE; END_TABLE;
@@ -1172,9 +1171,9 @@ void PrintScreenshots( RageFile &f, const Profile *pProfile, CString sTitle, CSt
for( int i = (int)pProfile->m_vScreenshots.size()-1; i >= 0; i-- ) for( int i = (int)pProfile->m_vScreenshots.size()-1; i >= 0; i-- )
{ {
Profile::Screenshot ss = pProfile->m_vScreenshots[i]; Screenshot ss = pProfile->m_vScreenshots[i];
tm new_time; tm new_time;
localtime_r( &ss.time, &new_time ); localtime_r( &ss.highScore.time, &new_time );
int iYear = new_time.tm_year+1900; int iYear = new_time.tm_year+1900;
int iMonth = new_time.tm_mon+1; int iMonth = new_time.tm_mon+1;
CString sNewMonth = ssprintf("%02d/%d", iMonth, iYear ); CString sNewMonth = ssprintf("%02d/%d", iMonth, iYear );
+2 -3
View File
@@ -107,11 +107,10 @@ void ScreenAward::Input( const DeviceInput& DeviceI, const InputEventType type,
if( !sFileName.empty() ) if( !sFileName.empty() )
{ {
Profile::Screenshot screenshot; Screenshot screenshot;
screenshot.sFileName = sFileName; screenshot.sFileName = sFileName;
screenshot.sMD5 = CRYPTMAN->GetMD5( sPath ); screenshot.sMD5 = CRYPTMAN->GetMD5( sPath );
screenshot.time = time(NULL); // FIXME: save HighScore
screenshot.sMachineGuid = PROFILEMAN->GetMachineProfile()->m_sGuid;
pProfile->AddScreenshot( screenshot ); pProfile->AddScreenshot( screenshot );
} }
+4 -3
View File
@@ -1392,6 +1392,8 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t
if( GameI.IsValid() ) if( GameI.IsValid() )
{ {
PlayerNumber pn = GAMESTATE->GetCurrentStyleDef()->ControllerToPlayerNumber( GameI.controller ); PlayerNumber pn = GAMESTATE->GetCurrentStyleDef()->ControllerToPlayerNumber( GameI.controller );
HighScore &hs = m_HighScore[pn];
if( CodeDetector::EnteredCode(GameI.controller, CodeDetector::CODE_SAVE_SCREENSHOT) ) if( CodeDetector::EnteredCode(GameI.controller, CodeDetector::CODE_SAVE_SCREENSHOT) )
{ {
@@ -1406,11 +1408,10 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t
if( !sFileName.empty() ) if( !sFileName.empty() )
{ {
Profile::Screenshot screenshot; Screenshot screenshot;
screenshot.sFileName = sFileName; screenshot.sFileName = sFileName;
screenshot.sMD5 = CRYPTMAN->GetMD5( sPath ); screenshot.sMD5 = CRYPTMAN->GetMD5( sPath );
screenshot.time = time(NULL); screenshot.highScore = hs;
screenshot.sMachineGuid = PROFILEMAN->GetMachineProfile()->m_sGuid;
pProfile->AddScreenshot( screenshot ); pProfile->AddScreenshot( screenshot );
} }