Skip to content

Commit

Permalink
give goals the ability to delete the shit out of themselves instead o…
Browse files Browse the repository at this point in the history
…f deleting all goals attached to a key like an idiot
  • Loading branch information
MinaciousGrace committed Apr 30, 2017
1 parent de4e192 commit 09c2773
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ local function makescoregoal(i)
InitCommand=cmd(x,325;halign,0;zoomto,4,4;diffuse,byJudgment('TapNoteScore_Miss');diffusealpha,1),
MouseLeftClickMessageCommand=function(self)
if isOver(self) and update and sg then
profile:RemoveGoalsByKey(ck)
sg:Delete()
MESSAGEMAN:Broadcast("UpdateGoals")
end
end,
Expand Down
32 changes: 15 additions & 17 deletions src/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2471,7 +2471,15 @@ void Profile::SetAnyAchievedGoals(RString ck, float rate, const HighScore& pscor
if (tmp.percent < pscore.GetWifeScore() * 100.f) { // should probably adhere to the established process of storing scores percents as 0.xx to avoid this kind of confusion -mina
tmp.achieved = true;
tmp.timeachieved = pscore.GetDateTime();
}
}
}
}

void Profile::DeleteGoal(RString ck, DateTime assigned) {
auto& sgv = goalmap.at(ck);
for (size_t i = 0; i < sgv.size(); ++i) {
if (sgv[i].timeassigned == assigned)
sgv.erase(sgv.begin() + i);
}
}

Expand Down Expand Up @@ -3744,21 +3752,6 @@ class LunaProfile : public Luna<Profile>
return 1;
}

// make unshit -mina
static int RemoveGoalsByKey(T* p, lua_State *L) {
RString ck = SArg(1);
auto it = p->goalmap.find(ck);
if (it == p->goalmap.end()) {
lua_pushnil(L);
}
else {
p->goalmap.erase(ck);
SONGMAN->SetHasGoal(p->goalmap);
}

return 1;
}

static int GetAllGoals(T* p, lua_State *L) {
lua_newtable(L);
int idx = 0;
Expand Down Expand Up @@ -3864,7 +3857,6 @@ class LunaProfile : public Luna<Profile>
ADD_METHOD( GetPBWifeScoreByKey );
ADD_METHOD( ValidateAllScores );
ADD_METHOD( GetGoalByKey );
ADD_METHOD( RemoveGoalsByKey );
ADD_METHOD( GetAllGoals );
}
};
Expand Down Expand Up @@ -3920,6 +3912,11 @@ class LunaScoreGoal : public Luna<ScoreGoal>

static int SetComment(T* p, lua_State *L) { p->comment = SArg(1); return 1; }

static int Delete(T* p, lua_State *L) {
PROFILEMAN->GetProfile(PLAYER_1)->DeleteGoal(p->chartkey, p->timeassigned);
return 1;
}

LunaScoreGoal()
{
ADD_METHOD( GetRate );
Expand All @@ -3934,6 +3931,7 @@ class LunaScoreGoal : public Luna<ScoreGoal>
ADD_METHOD( SetPercent );
ADD_METHOD( SetPriority );
ADD_METHOD( SetComment );
ADD_METHOD( Delete );
}
};
LUA_REGISTER_CLASS(ScoreGoal)
Expand Down
1 change: 1 addition & 0 deletions src/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class Profile

// more future goalman stuff -mina
void CreateGoal(RString ck);
void DeleteGoal(RString ck, DateTime assigned);
map<RString, vector<ScoreGoal>> goalmap;
bool ChartkeyHasGoal(RString ck);
ScoreGoal& GetLowestGoalForRate(RString ck, float rate);
Expand Down

0 comments on commit 09c2773

Please sign in to comment.