Skip to content

Commit 6a47206

Browse files
add separate save functions for goals/playlists/favorites and start using strings in profile
1 parent 061f780 commit 6a47206

File tree

4 files changed

+76
-34
lines changed

4 files changed

+76
-34
lines changed

src/Profile.cpp

+48-21
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,9 @@ XNode *Profile::SaveEttXmlCreateNode() const
10791079
{
10801080
XNode *xml = new XNode("Stats");
10811081
xml->AppendChild(SaveEttGeneralDataCreateNode());
1082+
xml->AppendChild(SaveFavoritesCreateNode());
1083+
xml->AppendChild(SavePlaylistsCreateNode());
1084+
xml->AppendChild(SaveScoreGoalsCreateNode());
10821085
xml->AppendChild(SaveEttScoresCreateNode());
10831086
return xml;
10841087
}
@@ -1248,7 +1251,7 @@ XNode* Profile::SaveGeneralDataCreateNode() const
12481251

12491252
{
12501253
XNode* pFavorites = pGeneralDataNode->AppendChild("Favorites");
1251-
FOREACH_CONST(RString, FavoritedCharts, it)
1254+
FOREACH_CONST(string, FavoritedCharts, it)
12521255
pFavorites->AppendChild(*it);
12531256
}
12541257

@@ -1342,6 +1345,37 @@ XNode* Profile::SaveGeneralDataCreateNode() const
13421345
return pGeneralDataNode;
13431346
}
13441347

1348+
XNode* Profile::SaveFavoritesCreateNode() const {
1349+
XNode* favs = new XNode("Favorites");
1350+
FOREACH_CONST(string, FavoritedCharts, it)
1351+
favs->AppendChild(*it);
1352+
return favs;
1353+
}
1354+
1355+
XNode* GoalsForChart::CreateNode() const {
1356+
XNode* cg = new XNode("GoalsForChart");
1357+
cg->AppendAttr("Key", goals[0].chartkey);
1358+
FOREACH_CONST(ScoreGoal, goals, sg)
1359+
cg->AppendChild(sg->CreateNode());
1360+
return cg;
1361+
}
1362+
1363+
XNode* Profile::SaveScoreGoalsCreateNode() const {
1364+
XNode* goals = new XNode("ScoreGoals");
1365+
FOREACHUM_CONST(string, GoalsForChart, goalmap, i) {
1366+
const GoalsForChart& cg = i->second;
1367+
goals->AppendChild(cg.CreateNode());
1368+
}
1369+
1370+
return goals;
1371+
}
1372+
1373+
XNode* Profile::SavePlaylistsCreateNode() const {
1374+
XNode* playlists = new XNode("PlayLists");
1375+
FOREACH_CONST(string, FavoritedCharts, it)
1376+
playlists->AppendChild(*it);
1377+
return playlists;
1378+
}
13451379

13461380
XNode* Profile::SaveEttGeneralDataCreateNode() const
13471381
{
@@ -1384,12 +1418,6 @@ XNode* Profile::SaveEttGeneralDataCreateNode() const
13841418
pDefaultModifiers->AppendChild(it->first, it->second);
13851419
}
13861420

1387-
{
1388-
XNode* pFavorites = pGeneralDataNode->AppendChild("Favorites");
1389-
FOREACH_CONST(RString, FavoritedCharts, it)
1390-
pFavorites->AppendChild(*it);
1391-
}
1392-
13931421
{
13941422
XNode* pPlayerSkillsets = pGeneralDataNode->AppendChild("PlayerSkillsets");
13951423
FOREACH_ENUM(Skillset, ss)
@@ -1508,7 +1536,7 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode )
15081536
FOREACH_CONST_Child(pFavorites, ck) {
15091537
RString tmp = ck->GetName(); // handle duplicated entries caused by an oversight - mina
15101538
bool duplicated = false;
1511-
FOREACH(RString, FavoritedCharts, chartkey)
1539+
FOREACH(string, FavoritedCharts, chartkey)
15121540
if (*chartkey == tmp)
15131541
duplicated = true;
15141542
if (!duplicated)
@@ -1655,7 +1683,7 @@ XNode* Profile::SaveSongScoresCreateNode() const
16551683
return pNode;
16561684
}
16571685

1658-
void Profile::RemoveFromFavorites(RString ck) {
1686+
void Profile::RemoveFromFavorites(string& ck) {
16591687
for (size_t i = 0; i < FavoritedCharts.size(); ++i) {
16601688
if (FavoritedCharts[i] == ck)
16611689
FavoritedCharts.erase(FavoritedCharts.begin() + i);
@@ -1804,12 +1832,11 @@ void Profile::LoadEttScoresFromNode(const XNode* pSongScores) {
18041832
}
18051833

18061834
// more future goalman stuff
1807-
void Profile::CreateGoal(RString ck) {
1835+
void Profile::CreateGoal(string& ck) {
18081836
ScoreGoal goal;
18091837
goal.timeassigned = DateTime::GetNowDateTime();
18101838
goal.rate = GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate;
1811-
goalmap[ck].emplace_back(goal);
1812-
LOG->Trace("New goal created %i goals", goalmap[ck].size());
1839+
goalmap[ck].Add(goal);
18131840
}
18141841

18151842
XNode* ScoreGoal::CreateNode() const {
@@ -1864,8 +1891,8 @@ void ScoreGoal::CheckVacuity() {
18641891
}
18651892

18661893
// aaa too lazy to write comparators rn -mina
1867-
ScoreGoal& Profile::GetLowestGoalForRate(RString ck, float rate) {
1868-
auto& sgv = goalmap[ck];
1894+
ScoreGoal& Profile::GetLowestGoalForRate(string& ck, float rate) {
1895+
auto& sgv = goalmap[ck].Get();
18691896
float lowest = 100.f;
18701897
int lowestidx = 0;
18711898
for (size_t i = 0; i < sgv.size(); ++i) {
@@ -1880,11 +1907,11 @@ ScoreGoal& Profile::GetLowestGoalForRate(RString ck, float rate) {
18801907
return sgv[lowestidx];
18811908
}
18821909

1883-
void Profile::SetAnyAchievedGoals(RString ck, float rate, const HighScore& pscore) {
1910+
void Profile::SetAnyAchievedGoals(string& ck, float& rate, const HighScore& pscore) {
18841911
if (!HasGoal(ck))
18851912
return;
18861913

1887-
auto& sgv = goalmap[ck];
1914+
auto& sgv = goalmap[ck].Get();
18881915
for (size_t i = 0; i < sgv.size(); ++i) {
18891916
ScoreGoal& tmp = sgv[i];
18901917
if (lround(tmp.rate * 10000.f) == lround(rate * 10000.f) && !tmp.achieved &&tmp.percent < pscore.GetWifeScore()) {
@@ -1895,8 +1922,8 @@ void Profile::SetAnyAchievedGoals(RString ck, float rate, const HighScore& pscor
18951922
}
18961923
}
18971924

1898-
void Profile::DeleteGoal(RString ck, DateTime assigned) {
1899-
auto& sgv = goalmap.at(ck);
1925+
void Profile::DeleteGoal(string& ck, DateTime assigned) {
1926+
auto& sgv = goalmap.at(ck).Get();
19001927
for (size_t i = 0; i < sgv.size(); ++i) {
19011928
if (sgv[i].timeassigned == assigned)
19021929
sgv.erase(sgv.begin() + i);
@@ -2261,9 +2288,9 @@ class LunaProfile : public Luna<Profile>
22612288
static int GetAllGoals(T* p, lua_State *L) {
22622289
lua_newtable(L);
22632290
int idx = 0;
2264-
FOREACHM(RString, vector<ScoreGoal>, p->goalmap, i) {
2265-
const RString &ck = i->first;
2266-
auto &sgv = i->second;
2291+
FOREACHUM(string, GoalsForChart, p->goalmap, i) {
2292+
const string &ck = i->first;
2293+
auto &sgv = i->second.Get();
22672294
FOREACH(ScoreGoal, sgv, sg) {
22682295
ScoreGoal &tsg = *sg;
22692296
tsg.chartkey = ck;

src/Profile.h

+25-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "StyleUtil.h" // for StyleID
1414
#include "LuaReference.h"
1515

16+
#include <unordered_map>
17+
1618
class XNode;
1719
struct lua_State;
1820
class Character;
@@ -100,6 +102,15 @@ class ScoreGoal
100102
void PushSelf(lua_State *L);
101103
};
102104

105+
106+
struct GoalsForChart {
107+
public:
108+
XNode* CreateNode() const;
109+
void Add(ScoreGoal& sg) { goals.emplace_back(sg); }
110+
vector<ScoreGoal>& Get() { return goals; }
111+
vector<ScoreGoal> goals;
112+
};
113+
103114
/**
104115
* @brief Player data that persists between sessions.
105116
*
@@ -242,19 +253,23 @@ class Profile
242253
int m_iNumStagesPassedByPlayMode[NUM_PlayMode];
243254
int m_iNumStagesPassedByGrade[NUM_Grade];
244255

245-
void AddToFavorites(RString ck) { FavoritedCharts.emplace_back(ck); }
246-
void RemoveFromFavorites(RString ck);
256+
void AddToFavorites(string& ck) { FavoritedCharts.emplace_back(ck); }
257+
void RemoveFromFavorites(string& ck);
258+
vector<string> FavoritedCharts;
259+
XNode* SaveFavoritesCreateNode() const;
260+
XNode* SaveScoreGoalsCreateNode() const;
261+
XNode* SavePlaylistsCreateNode() const;
262+
void LoadFavoritesFromNode();
247263

248-
// Vector for now, we can make this more efficient later
249-
vector<RString> FavoritedCharts;
250264

251265
// more future goalman stuff -mina
252-
void CreateGoal(RString ck);
253-
void DeleteGoal(RString ck, DateTime assigned);
254-
map<RString, vector<ScoreGoal>> goalmap;
255-
bool HasGoal(RString ck) { return goalmap.count(ck) == 1; }
256-
ScoreGoal& GetLowestGoalForRate(RString ck, float rate);
257-
void SetAnyAchievedGoals(RString ck, float rate, const HighScore& pscore);
266+
void CreateGoal(string& ck);
267+
void DeleteGoal(string& ck, DateTime assigned);
268+
unordered_map<string, GoalsForChart> goalmap;
269+
270+
bool HasGoal(string& ck) { return goalmap.count(ck) == 1; }
271+
ScoreGoal& GetLowestGoalForRate(string& ck, float rate);
272+
void SetAnyAchievedGoals(string& ck, float& rate, const HighScore& pscore);
258273

259274
/* store arbitrary data for the theme within a profile */
260275
LuaTable m_UserTable;

src/SongManager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,11 @@ bool SongManager::IsGroupNeverCached(const RString& group) const
493493
return m_GroupsToNeverCache.find(group) != m_GroupsToNeverCache.end();
494494
}
495495

496-
void SongManager::SetFavoritedStatus(vector<RString>& favs) {
496+
void SongManager::SetFavoritedStatus(vector<string>& favs) {
497497
FOREACH(Song*, m_pSongs, song) {
498498
FOREACH_CONST(Steps*, (*song)->GetAllSteps(), steps) {
499499
RString sck = (*steps)->GetChartKey();
500-
FOREACH(RString, favs, ck) {
500+
FOREACH(string, favs, ck) {
501501
if (sck == *ck)
502502
(*song)->SetFavorited(true);
503503
}

src/SongManager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class SongManager
5454
void PreloadSongImages();
5555

5656
bool IsGroupNeverCached(const RString& group) const;
57-
void SetFavoritedStatus(vector<RString>& favs);
57+
void SetFavoritedStatus(vector<string>& favs);
5858
void SetHasGoal(map<RString, vector<ScoreGoal>> goalmap);
5959

6060
RString GetSongGroupBannerPath( const RString &sSongGroup ) const;

0 commit comments

Comments
 (0)