Skip to content

Commit

Permalink
move calctest stuff to songman and kill some rstring use in profile load
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed May 8, 2020
1 parent a0dbd85 commit 6403754
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 144 deletions.
7 changes: 3 additions & 4 deletions src/Etterna/Models/Misc/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
#include <set>

#include <unordered_map>
using std::string;

class XNode;
struct lua_State;
struct Playlist;

// Current file versions
extern const RString ETT_XML;
extern const string ETT_XML;

/**
* @brief The filename where one can edit their personal profile data.
Expand All @@ -44,7 +45,7 @@ extern const RString EDITABLE_INI;
* to their own profile for use in the game unless they also have the "don't
* share" file. DontShare contains a piece of information that we can
* construct using STATS_XML but the user can't construct using STATS_XML. */
extern const RString DONT_SHARE_SIG;
extern const string DONT_SHARE_SIG;

extern const RString PUBLIC_KEY_FILE;
extern const RString SCREENSHOTS_SUBDIR;
Expand Down Expand Up @@ -197,8 +198,6 @@ class Profile
// Profile Playlists
map<string, Playlist> allplaylists;

map<Skillset, CalcTestList> calctestlists;

// Editable data
RString m_sDisplayName;
// Dont edit this. Should be unique (Is it?)
Expand Down
116 changes: 28 additions & 88 deletions src/Etterna/Models/Misc/XMLProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
#include "Etterna/Singletons/SongManager.h"
#include "Etterna/Models/StepsAndStyles/Steps.h"

const RString ETT_XML = "Etterna.xml";
const RString ETT_XML_GZ = "Etterna.xml.gz";
using std::string;

const string ETT_XML = "Etterna.xml";
const string ETT_XML_GZ = "Etterna.xml.gz";
/** @brief The filename containing the signature for ETT_XML's signature. */
const RString DONT_SHARE_SIG = "DontShare.sig";
const string DONT_SHARE_SIG = "DontShare.sig";
static Preference<bool> g_bProfileDataCompress("ProfileDataCompress", false);

// Loading and saving
Expand Down Expand Up @@ -75,12 +77,11 @@ static Preference<bool> g_bProfileDataCompress("ProfileDataCompress", false);
}

ProfileLoadResult
XMLProfile::LoadEttFromDir(RString dir)
XMLProfile::LoadEttFromDir(string dir)
{
dir += PROFILEMAN->GetStatsPrefix();
profiledir = dir;
profiledir = dir + PROFILEMAN->GetStatsPrefix();
loadingProfile->IsEtternaProfile = true;
RString fn = dir + ETT_XML;
string fn = profiledir.append(ETT_XML);

int iError;
unique_ptr<RageFileBasic> pFile(FILEMAN->Open(fn, RageFile::READ, iError));
Expand All @@ -101,15 +102,16 @@ XMLProfile::LoadEttFromDir(RString dir)
}

bool
XMLProfile::SaveEttXmlToDir(RString sDir, const Profile* profile) const
XMLProfile::SaveEttXmlToDir(string sDir, const Profile* profile) const
{
LOG->Trace("Saving Etterna Profile to: %s", sDir.c_str());
unique_ptr<XNode> xml(SaveEttXmlCreateNode(profile));
sDir += PROFILEMAN->GetStatsPrefix();
string pDir = sDir + PROFILEMAN->GetStatsPrefix();
// Save Etterna.xml
RString fn = sDir + ETT_XML;
string fn = pDir.append(ETT_XML);
string fngz = pDir.append(ETT_XML_GZ);
{
RString sError;
string sError;
RageFile f;
if (!f.Open(fn, RageFile::WRITE)) {
LuaHelpers::ReportScriptErrorFmt("Couldn't open %s for writing: %s",
Expand All @@ -129,19 +131,18 @@ XMLProfile::SaveEttXmlToDir(RString sDir, const Profile* profile) const

/* After successfully saving ETT_XML_GZ, remove any stray
* ETT_XML. */
if (FILEMAN->IsAFile(sDir + ETT_XML))
FILEMAN->Remove(sDir + ETT_XML);
if (FILEMAN->IsAFile(fn))
FILEMAN->Remove(fn);
} else {
if (!XmlFileUtil::SaveToFile(xml.get(), f, "", false))
return false;

/* After successfully saving ETT_XML, remove any stray
* ETT_XML_GZ. */
if (FILEMAN->IsAFile(sDir + ETT_XML_GZ))
FILEMAN->Remove(sDir + ETT_XML_GZ);
if (FILEMAN->IsAFile(fngz))
FILEMAN->Remove(fngz);
}
}

return true;
}

Expand Down Expand Up @@ -207,57 +208,6 @@ XMLProfile::SavePlaylistsCreateNode(const Profile* profile) const
return playlists;
}

XNode*
XMLProfile::SaveCalcTestCreateNode(const Profile* profile) const
{
CHECKPOINT_M("Saving the Calc Test node.");

XNode* calctestlists = new XNode("CalcTest");
auto& pls = profile->calctestlists;
FOREACHM_CONST(Skillset, CalcTestList, pls, i)
calctestlists->AppendChild(i->second.CreateNode());
return calctestlists;
}

void
XMLProfile::LoadCalcTestNode(const XNode* pNode) const
{
CHECKPOINT_M("Loading the Calc Test node.");

FOREACH_CONST_Child(pNode, chartlist) // "For Each Skillset
{
int ssI;
chartlist->GetAttrValue("Skillset", ssI);
Skillset ss = (Skillset)ssI;
CalcTestList tl;
tl.skillset = ss;
FOREACH_CONST_Child(chartlist, uhh) // For Each Chartlist (oops)
{
FOREACH_CONST_Child(uhh, entry) // For Each Chart
{
RString key;
float target;
float rate;
entry->GetAttrValue("Key", key);
entry->GetAttrValue("Target", target);
entry->GetAttrValue("Rate", rate);
pair<float, float> pf(target, rate);
tl.filemapping[key.c_str()] = pf;
}
}
loadingProfile->calctestlists[ss] = tl;
if (SONGMAN->testChartList.count(ss)) {
for (auto c : tl.filemapping) {
// this replaces any duplicates in order of profile load
// so ... dont duplicate them i guess
// but anything that isnt duplicate is added
SONGMAN->testChartList[ss].filemapping[c.first] = c.second;
}
} else
SONGMAN->testChartList[ss] = tl;
}
}

void
XMLProfile::LoadFavoritesFromNode(const XNode* pNode)
{
Expand Down Expand Up @@ -289,7 +239,7 @@ GoalsForChart::LoadFromNode(const XNode* pNode)
doot.LoadFromNode(sg);
Add(doot);
}
RString chartkey;
string chartkey;
pNode->GetAttrValue("Key", chartkey);
for (auto& goal : goals)
goal.chartkey = chartkey;
Expand All @@ -300,7 +250,7 @@ XMLProfile::LoadScoreGoalsFromNode(const XNode* pNode)
{
CHECKPOINT_M("Loading the scoregoals node.");

RString ck;
string ck;
FOREACH_CONST_Child(pNode, chgoals)
{
chgoals->GetAttrValue("Key", ck);
Expand Down Expand Up @@ -431,18 +381,15 @@ XMLProfile::SaveEttGeneralDataCreateNode(const Profile* profile) const
}

void
XMLProfile::MoveBackupToDir(const RString& sFromDir, const RString& sToDir)
XMLProfile::MoveBackupToDir(string sFromDir, string sToDir)
{
if (FILEMAN->IsAFile(sFromDir + ETT_XML) &&
FILEMAN->IsAFile(sFromDir + ETT_XML + SIGNATURE_APPEND)) {
FILEMAN->Move(sFromDir + ETT_XML, sToDir + ETT_XML);
FILEMAN->Move(sFromDir + ETT_XML + SIGNATURE_APPEND,
sToDir + ETT_XML + SIGNATURE_APPEND);
} else if (FILEMAN->IsAFile(sFromDir + ETT_XML_GZ) &&
FILEMAN->IsAFile(sFromDir + ETT_XML_GZ + SIGNATURE_APPEND)) {
FILEMAN->Move(sFromDir + ETT_XML_GZ, sToDir + ETT_XML);
FILEMAN->Move(sFromDir + ETT_XML_GZ + SIGNATURE_APPEND,
sToDir + ETT_XML + SIGNATURE_APPEND);
string frompath = sFromDir.append(ETT_XML);
string fromsig = frompath.append(SIGNATURE_APPEND);
string topath = sToDir.append(ETT_XML);
string tosig = topath.append(SIGNATURE_APPEND);
if (FILEMAN->IsAFile(frompath) && FILEMAN->IsAFile(fromsig)) {
FILEMAN->Move(frompath, topath);
FILEMAN->Move(fromsig, tosig);
}
}

Expand All @@ -452,7 +399,7 @@ XMLProfile::LoadEttGeneralDataFromNode(const XNode* pNode)
CHECKPOINT_M("Loading the general node.");
ASSERT(pNode->GetName() == "GeneralData");

RString s;
string s;
const XNode* pTemp;

pNode->GetChildValue("DisplayName", loadingProfile->m_sDisplayName);
Expand Down Expand Up @@ -609,10 +556,6 @@ XMLProfile::LoadEttXmlFromNode(const XNode* xml)
if (play)
LoadPlaylistsFromNode(play);

const XNode* calctest = xml->GetChild("CalcTest");
if (calctest)
LoadCalcTestNode(calctest);

const XNode* scores = xml->GetChild("PlayerScores");
if (scores)
LoadEttScoresFromNode(scores);
Expand All @@ -635,9 +578,6 @@ XMLProfile::SaveEttXmlCreateNode(const Profile* profile) const
if (!profile->allplaylists.empty())
xml->AppendChild(SavePlaylistsCreateNode(profile));

if (!profile->calctestlists.empty())
xml->AppendChild(SaveCalcTestCreateNode(profile));

if (!profile->goalmap.empty())
xml->AppendChild(SaveScoreGoalsCreateNode(profile));

Expand Down
11 changes: 4 additions & 7 deletions src/Etterna/Models/Misc/XMLProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class XNode;
class XMLProfile
{
public:
static void MoveBackupToDir(const RString& sFromDir, const RString& sToDir);
static void MoveBackupToDir(std::string sFromDir, std::string sToDir);

// Etterna profile
ProfileLoadResult LoadEttFromDir(RString dir);
bool SaveEttXmlToDir(RString sDir, const Profile* profile) const;
ProfileLoadResult LoadEttFromDir(std::string dir);
bool SaveEttXmlToDir(std::string sDir, const Profile* profile) const;
void SetLoadingProfile(Profile* p) { loadingProfile = p; }

private:
Expand All @@ -41,12 +41,9 @@ class XMLProfile
XNode* SavePermaMirrorCreateNode(const Profile* profile) const;
XNode* SaveScoreGoalsCreateNode(const Profile* profile) const;
XNode* SavePlaylistsCreateNode(const Profile* profile) const;
XNode* SaveCalcTestCreateNode(const Profile* profile) const;
void LoadCalcTestNode(const XNode* pNode) const;

XNode* SaveScreenshotDataCreateNode(const Profile* profile) const;

RString profiledir;
std::string profiledir;
};

#endif
22 changes: 2 additions & 20 deletions src/Etterna/Screen/Others/ScreenSelectMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,20 +1072,11 @@ ScreenSelectMusic::HandleScreenMessage(const ScreenMessage SM)
tl.filemapping[ck] = pf;
SONGMAN->testChartList[ss] = tl;
}
if (pProfile->calctestlists.count(ss)) {
pair<float, float> pf(target, 1.f);
pProfile->calctestlists[ss].filemapping[ck] = pf;
} else {
CalcTestList tl;
tl.skillset = ss;
pair<float, float> pf(target, 1.f);
tl.filemapping[ck] = pf;
pProfile->calctestlists[ss] = tl;
}
SCREENMAN->SystemMessage(
ssprintf("added %s to %s at rate 1.0",
ck.c_str(),
SkillsetToString(ss).c_str()));
SONGMAN->SaveCalcTestXmlToDir();
float woo =
GAMESTATE->m_pCurSteps->DoATestThing(target, ss);
}
Expand All @@ -1111,21 +1102,12 @@ ScreenSelectMusic::HandleScreenMessage(const ScreenMessage SM)
tl.filemapping[ck] = pf;
SONGMAN->testChartList[ss] = tl;
}
if (pProfile->calctestlists.count(ss)) {
pair<float, float> pf(target, rate);
pProfile->calctestlists[ss].filemapping[ck] = pf;
} else {
CalcTestList tl;
tl.skillset = ss;
pair<float, float> pf(target, rate);
tl.filemapping[ck] = pf;
pProfile->calctestlists[ss] = tl;
}
SCREENMAN->SystemMessage(
ssprintf("added %s to %s at rate %f",
ck.c_str(),
SkillsetToString(ss).c_str(),
rate));
SONGMAN->SaveCalcTestXmlToDir();
float woo =
GAMESTATE->m_pCurSteps->DoATestThing(target, ss);
}
Expand Down
23 changes: 0 additions & 23 deletions src/Etterna/Singletons/ScoreManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,29 +653,6 @@ ScoreManager::RegisterScoreInProfile(HighScore* hs_, const string& profileID)
AllProfileScores[profileID].emplace_back(hs_);
}

XNode*
CalcTestList::CreateNode() const
{
XNode* pl = new XNode("CalcTestList");
pl->AppendAttr("Skillset", skillset);

XNode* cl = new XNode("Chartlist");
for (const auto p : filemapping) {
XNode* chart = new XNode("Chart");
chart->AppendAttr("Key", p.first);
chart->AppendAttr("Target", p.second.first);
chart->AppendAttr("Rate", p.second.second);
cl->AppendChild(chart);
}

if (!cl->ChildrenEmpty())
pl->AppendChild(cl);
else
delete cl;

return pl;
}

// Write scores to xml
XNode*
ScoresAtRate::CreateNode(const int& rate) const
Expand Down
Loading

0 comments on commit 6403754

Please sign in to comment.