Skip to content

Commit

Permalink
store scoregoal percents as 0.xxxx rather than xx.xx
Browse files Browse the repository at this point in the history
add vacuity checks for goals that have been achieved when set
store scorekey for the highscore that achieved the scoregoal
  • Loading branch information
MinaciousGrace committed May 3, 2017
1 parent 2db2e79 commit 44ec91e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 12 deletions.
71 changes: 61 additions & 10 deletions src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2182,11 +2182,24 @@ XNode* Profile::SaveEttScoresCreateNode() const
pChartKey->AppendChild(pScores);

// Chart entries may contain more than just scores, write out any scoregoals associated with this key
// maybe these should be contained separately like the favorites? not sure, there are advantages to both
// also this lol, don't write any vacuous goals when saving -mina
if (goalmap.count(ck)) {
XNode* pGoals = new XNode("GoalTracker");
FOREACH_CONST(ScoreGoal, goalmap.at(ck), sg)
pGoals->AppendChild(sg->CreateNode());
pChartKey->AppendChild(pGoals);
bool anygoalstosave = false;
FOREACH_CONST(ScoreGoal, goalmap.at(ck), sg) {
if (sg->vacuous) {
anygoalstosave = true;
break;
}
}

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

pNode->AppendChild(pChartKey);
Expand Down Expand Up @@ -2374,8 +2387,11 @@ XNode* ScoreGoal::CreateNode() const {
pNode->AppendChild("Priority", priority);
pNode->AppendChild("Achieved", achieved);
pNode->AppendChild("TimeAssigned", timeassigned.GetString());
if(achieved)
if (achieved) {
pNode->AppendChild("TimeAchieved", timeachieved.GetString());
pNode->AppendChild("ScoreKey", scorekey);
}

pNode->AppendChild("Comment", comment);

return pNode;
Expand All @@ -2388,11 +2404,16 @@ void ScoreGoal::LoadFromNode(const XNode *pNode) {

pNode->GetChildValue("Rate", rate);
pNode->GetChildValue("Percent", percent);
if (percent > 1.f) // goddamnit why didnt i think this through originally
percent /= 100.f;
pNode->GetChildValue("Priority", priority);
pNode->GetChildValue("Achieved", achieved);
pNode->GetChildValue("TimeAssigned", s); timeassigned.FromString(s);
if(achieved)
if (achieved) {
pNode->GetChildValue("TimeAchieved", s); timeachieved.FromString(s);
pNode->GetChildValue("ScoreKey", s); scorekey;
}

pNode->GetChildValue("Comment", comment);
}

Expand All @@ -2401,6 +2422,15 @@ HighScore* ScoreGoal::GetPBUpTo() {
return scores.GetChartPBUpTo(chartkey, rate);
}

void ScoreGoal::CheckVacuity() {
auto& scores = PROFILEMAN->GetProfile(PLAYER_1)->pscores;
HighScore* pb = scores.GetChartPBAt(chartkey, rate);

if (pb && pb->GetWifeScore() >= percent)
vacuous = true;
else vacuous = false;
}

// aaa too lazy to write comparators rn -mina
ScoreGoal& Profile::GetLowestGoalForRate(RString ck, float rate) {
auto& sgv = goalmap[ck];
Expand All @@ -2425,10 +2455,10 @@ void Profile::SetAnyAchievedGoals(RString ck, float rate, const HighScore& pscor
auto& sgv = goalmap[ck];
for (size_t i = 0; i < sgv.size(); ++i) {
ScoreGoal& tmp = sgv[i];
// should probably adhere to the established process of storing scores percents as 0.xx to avoid this kind of confusion -mina
if (lround(tmp.rate * 1000.f) == lround(rate * 1000.f) && !tmp.achieved &&tmp.percent < pscore.GetWifeScore() * 100.f) {
if (lround(tmp.rate * 10000.f) == lround(rate * 10000.f) && !tmp.achieved &&tmp.percent < pscore.GetWifeScore()) {
tmp.achieved = true;
tmp.timeachieved = pscore.GetDateTime();
tmp.scorekey = pscore.GetScoreKey();
}
}
}
Expand Down Expand Up @@ -3361,8 +3391,9 @@ class LunaScoreGoal : public Luna<ScoreGoal>
static int SetRate(T* p, lua_State *L) {
if (!p->achieved) {
float newrate = FArg(1);
CLAMP(newrate, 0.7f, 2.0f);
CLAMP(newrate, 0.7f, 3.0f);
p->rate = newrate;
p->CheckVacuity();
}

return 1;
Expand All @@ -3371,8 +3402,9 @@ class LunaScoreGoal : public Luna<ScoreGoal>
static int SetPercent(T* p, lua_State *L) {
if (!p->achieved) {
float newpercent = FArg(1);
CLAMP(newpercent, 80.f, 100.f);
CLAMP(newpercent, .8f, 1.f);
p->percent = newpercent;
p->CheckVacuity();
}
return 1;
}
Expand Down Expand Up @@ -3402,6 +3434,23 @@ class LunaScoreGoal : public Luna<ScoreGoal>
return 1;
}

static int IsVacuous(T* p, lua_State *L) {
if (p->achieved)
lua_pushboolean(L, false);

p->CheckVacuity(); // might be redundant
lua_pushboolean(L, p->vacuous);
return 1;
}

static int AchievedBy(T* p, lua_State *L) {
if (p->achieved)
lua_pushstring(L, p->scorekey);
else
lua_pushnil(L);
return 1;
}

LunaScoreGoal()
{
ADD_METHOD( GetRate );
Expand All @@ -3418,6 +3467,8 @@ class LunaScoreGoal : public Luna<ScoreGoal>
ADD_METHOD( SetComment );
ADD_METHOD( Delete );
ADD_METHOD( GetPBUpTo );
ADD_METHOD( IsVacuous );
ADD_METHOD( AchievedBy );
}
};
LUA_REGISTER_CLASS(ScoreGoal)
Expand Down
14 changes: 12 additions & 2 deletions src/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,29 @@ class ScoreGoal
{
public:
float rate = 1.f;
float percent = 93.f;
float percent = .93f;
int priority = 1;
bool achieved = 0;
bool achieved = false;
DateTime timeassigned;
DateTime timeachieved;
RString comment = "";
RString chartkey = "";

// which specific score was this goal achieved by, reminder to consider
// what happens when individual score deletion is possibly added -mina
RString scorekey = "";

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

HighScore* GetPBUpTo();

// If the scoregoal has already been completed prior to being assigned, flag it as a vacuous goal
void CheckVacuity();

// Vacuous goals will remain in memory for the session but not be written during save -mina
bool vacuous = false;

void PushSelf(lua_State *L);
};

Expand Down

0 comments on commit 44ec91e

Please sign in to comment.