Skip to content

Commit

Permalink
add replay write function
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Jan 20, 2017
1 parent 930e2f7 commit c348b88
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
34 changes: 33 additions & 1 deletion src/HighScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
#include "Foreach.h"
#include "RadarValues.h"
#include <algorithm>
#include <fstream>
#include <sstream>
#include "CryptManager.h"
#include "ProfileManager.h"

ThemeMetric<RString> EMPTY_NAME("HighScore","EmptyName");

struct HighScoreImpl
{
RString sName; // name that shows in the machine's ranking screen
RString sHistoricChartKey;
RString ScoreKey;
float SSRCalcVersion;
Grade grade;
unsigned int iScore;
Expand Down Expand Up @@ -46,6 +51,8 @@ struct HighScoreImpl
XNode *CreateNode() const;
void LoadFromNode( const XNode *pNode );

void WriteReplayFile();

float RescoreToWifeTS(float ts);

RString OffsetsToString(vector<float> v) const;
Expand Down Expand Up @@ -165,6 +172,7 @@ HighScoreImpl::HighScoreImpl()
{
sName = "";
sHistoricChartKey = "";
ScoreKey = "";
SSRCalcVersion = 0.f;
grade = Grade_NoData;
iScore = 0;
Expand Down Expand Up @@ -200,6 +208,7 @@ XNode *HighScoreImpl::CreateNode() const
// TRICKY: Don't write "name to fill in" markers.
pNode->AppendChild( "Name", IsRankingToFillIn(sName) ? RString("") : sName );
pNode->AppendChild( "HistoricChartKey", sHistoricChartKey);
pNode->AppendChild(" ScoreKey", ScoreKey);
pNode->AppendChild( "SSRCalcVersion", SSRCalcVersion);
pNode->AppendChild( "Grade", GradeToString(grade) );
pNode->AppendChild( "Score", iScore );
Expand Down Expand Up @@ -277,6 +286,8 @@ void HighScoreImpl::LoadFromNode(const XNode *pNode)
}
}
pNode->GetChildValue( "DateTime", s ); dateTime.FromString( s );
ScoreKey = "S" + BinaryToHex(CryptManager::GetSHA1ForString(dateTime.GetString()));

pNode->GetChildValue( "PlayerGuid", sPlayerGuid );
pNode->GetChildValue( "MachineGuid", sMachineGuid );
pNode->GetChildValue( "ProductID", iProductID );
Expand Down Expand Up @@ -305,11 +316,32 @@ void HighScoreImpl::LoadFromNode(const XNode *pNode)
// special test case stuff - mina
//if (vOffsetVector.size() > 1 && fWifeScore == 0.f)
// fWifeScore = RescoreToWifeTS(fJudgeScale);

if (vNoteRowVector.size() + vOffsetVector.size() > 2 && (vNoteRowVector.size() == vOffsetVector.size() ))
WriteReplayFile();
// Validate input.
grade = clamp( grade, Grade_Tier01, Grade_Failed );
}

void HighScoreImpl::WriteReplayFile() {
RString append;
//open file
RString profiledir = PROFILEMAN->currentlyloadingprofile;
ofstream fileStream(profiledir + "ReplayData/" + ScoreKey, ios::binary);
//check file
if (!fileStream)
LOG->Warn("Failed to create replay file");

unsigned int idx = vNoteRowVector.size() - 1;
//loop for writing both vectors side by side
for (unsigned int i = 0; i < idx; i++) {
append = to_string(vNoteRowVector[i]) + " " + to_string(vOffsetVector[i]) + "\n";
fileStream.write(append.c_str(), append.size());
}
append = to_string(vNoteRowVector[idx]) + " " + to_string(vOffsetVector[idx]);
fileStream.write(append.c_str(), append.size());
fileStream.close();
}

REGISTER_CLASS_TRAITS( HighScoreImpl, new HighScoreImpl(*pCopy) )

HighScore::HighScore()
Expand Down
5 changes: 4 additions & 1 deletion src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const RString EDIT_STEPS_SUBDIR = "Edits/";
const RString EDIT_COURSES_SUBDIR = "EditCourses/";
//const RString UPLOAD_SUBDIR = "Upload/";
const RString RIVAL_SUBDIR = "Rivals/";
const RString REPLAY_SUBDIR = "ReplayData/";

ThemeMetric<bool> SHOW_COIN_DATA( "Profile", "ShowCoinData" );
static Preference<bool> g_bProfileDataCompress( "ProfileDataCompress", false );
Expand Down Expand Up @@ -1134,9 +1135,10 @@ void Profile::HandleStatsPrefixChange(RString dir, bool require_signature)
SaveAllToDir(dir, require_signature);
}
}

ProfileLoadResult Profile::LoadAllFromDir( const RString &sDir, bool bRequireSignature )
{
FILEMAN->CreateDir(sDir + REPLAY_SUBDIR);
LOG->Trace( "Profile::LoadAllFromDir( %s )", sDir.c_str() );

ASSERT( sDir.Right(1) == "/" );
Expand Down Expand Up @@ -1332,6 +1334,7 @@ bool Profile::SaveAllToDir( const RString &sDir, bool bSignData ) const
FILEMAN->CreateDir( sDir + EDIT_COURSES_SUBDIR );
FILEMAN->CreateDir( sDir + SCREENSHOTS_SUBDIR );
FILEMAN->CreateDir( sDir + RIVAL_SUBDIR );
FILEMAN->CreateDir( sDir + REPLAY_SUBDIR);

/* Get the theme's custom save function:
* [Profile]
Expand Down
1 change: 1 addition & 0 deletions src/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extern const RString DONT_SHARE_SIG;

extern const RString PUBLIC_KEY_FILE;
extern const RString SCREENSHOTS_SUBDIR;
extern const RString REPLAY_SUBDIR;
extern const RString EDIT_STEPS_SUBDIR;
extern const RString EDIT_COURSES_SUBDIR;
extern const RString LASTGOOD_SUBDIR;
Expand Down
1 change: 1 addition & 0 deletions src/ProfileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ void ProfileManager::RefreshLocalProfilesFromDisk()
add_category_to_global_list(categorized_profiles[ProfileType_Test]);
FOREACH(DirAndProfile, g_vLocalProfile, curr)
{
currentlyloadingprofile = curr->sDir.substr(1);
curr->profile.LoadAllFromDir(curr->sDir, PREFSMAN->m_bSignProfileData);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ProfileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class ProfileManager
static Preference<bool> m_bProfileStepEdits;
static Preference<bool> m_bProfileCourseEdits;
static Preference1D<RString> m_sDefaultLocalProfileID;
RString currentlyloadingprofile;

private:
ProfileLoadResult LoadProfile( PlayerNumber pn, const RString &sProfileDir, bool bIsMemCard );
Expand Down

0 comments on commit c348b88

Please sign in to comment.