Skip to content

Commit

Permalink
rename goals to scoregoals and setup read/write to new etterna keyed …
Browse files Browse the repository at this point in the history
…profile
  • Loading branch information
MinaciousGrace committed Apr 28, 2017
1 parent ee3c6ec commit aae1e3c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 13 deletions.
62 changes: 54 additions & 8 deletions src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,17 @@ XNode* Profile::SaveEttScoresCreateNode() const
pScores->AppendChild(pRateScores);
}
pChartKey->AppendChild(pScores);

// Chart entries may contain more than just scores, write out any scoregoals associated with this key

auto it = goalmap.find(ck);
if (it != goalmap.end()) {
XNode* pGoals = new XNode("GoalTracker");
FOREACH_CONST(ScoreGoal, goalmap.at(ck), sg)
pGoals->AppendChild(sg->CreateNode());
pChartKey->AppendChild(pGoals);
}

pNode->AppendChild(pChartKey);
}

Expand Down Expand Up @@ -2325,20 +2336,56 @@ void Profile::LoadEttScoresFromNode(const XNode* pSongScores) {
hsrm.emplace(rate, hsv);
}

const XNode *pGoals = pChart->GetChild("GoalTracker");
if (pGoals) {
vector<ScoreGoal> sgv;
FOREACH_CONST_Child(pGoals, sg) {
sgv.resize(sgv.size() + 1);
sgv.back().LoadFromNode(sg);
}
goalmap.emplace(ck, sgv);
}

HighScoresByChartKey.emplace(ck, hsrm);
}
}

// more future goalman stuff
void Profile::CreateGoal(RString ck) {
Goal goal;
goal.assigned = DateTime::GetNowDateTime();
goal.chartkey = ck;
ScoreGoal goal;
goal.timeassigned = DateTime::GetNowDateTime();
//goal.rate = GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate;
goalmap[ck].emplace_back(goal);
LOG->Trace("New goal created %i goals", goalmap[ck].size());
}

XNode* ScoreGoal::CreateNode() const {
XNode* pNode = new XNode("ScoreGoal");

pNode->AppendChild("Rate", rate);
pNode->AppendChild("Percent", percent);
pNode->AppendChild("Priority", priority);
pNode->AppendChild("Achieved", achieved);
pNode->AppendChild("TimeAssigned", timeassigned.GetString());
pNode->AppendChild("TimeAchieved", "");
pNode->AppendChild("Comment", comment);

return pNode;
}

void ScoreGoal::LoadFromNode(const XNode *pNode) {
ASSERT(pNode->GetName() == "ScoreGoal");

RString s;

pNode->GetChildValue("Rate", rate);
pNode->GetChildValue("Percent", percent);
pNode->GetChildValue("Priority", priority);
pNode->GetChildValue("Achieved", achieved);
pNode->GetChildValue("TimeAssigned", s); timeassigned.FromString(s);
pNode->GetChildValue("Comment", comment);
}

/* This is really lame because for whatever reason getting the highscore object and passing them
to lua results in really weird and unpredictable errors that I can't figure out, so instead we pass
lua the keys and let the lua function get the highscore objects */
Expand Down Expand Up @@ -2394,7 +2441,6 @@ float Profile::GetWifePBByKey(RString key) {
// also finish dealing with this later - mina
void Profile::CalcPlayerRating(float& prating, float* pskillsets) const {
vector<float> demskillas[NUM_Skillset];
LOG->Trace("test");
FOREACHM_CONST(RString, HighScoreRateMap, HighScoresByChartKey, i) {
auto &hsrm = i->second;
FOREACHM_CONST(float, vector<HighScore>, hsrm, j) {
Expand All @@ -2406,7 +2452,7 @@ void Profile::CalcPlayerRating(float& prating, float* pskillsets) const {
} }
}
}
LOG->Trace("test");

// overall should probably be ignored
float skillsetsum = 0.f;
FOREACH_ENUM(Skillset, ss) {
Expand Down Expand Up @@ -3747,20 +3793,20 @@ class LunaProfile : public Luna<Profile>
};

LUA_REGISTER_CLASS( Profile )
class LunaGoal : public Luna<Goal>
class LunaScoreGoal : public Luna<ScoreGoal>
{
public:
static int GetRate(T* p, lua_State *L) {
lua_pushnumber(L, p->rate);
return 1;
}

LunaGoal()
LunaScoreGoal()
{
ADD_METHOD( GetRate );
}
};
LUA_REGISTER_CLASS(Goal)
LUA_REGISTER_CLASS(ScoreGoal)
// lua end


Expand Down
13 changes: 8 additions & 5 deletions src/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,19 @@ enum ProfileType
};

// future goalman stuff - Mina
class Goal
class ScoreGoal
{
public:
float rate = 1.f;
float percent = 93.f;
int priority = 1;
DateTime assigned;
DateTime achieved;
bool achieved = 0;
DateTime timeassigned;
DateTime timeachieved;
RString comment = "";
RString chartkey = "";

XNode* CreateNode() const;
void LoadFromNode(const XNode *pNode);

void PushSelf(lua_State *L);
};
Expand Down Expand Up @@ -274,7 +277,7 @@ class Profile

// more future goalman stuff
void CreateGoal(RString ck);
map<RString, vector<Goal>> goalmap;
map<RString, vector<ScoreGoal>> goalmap;

/* store arbitrary data for the theme within a profile */
LuaTable m_UserTable;
Expand Down

0 comments on commit aae1e3c

Please sign in to comment.