Skip to content

Commit

Permalink
add sort skillset sorting function in c++
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Jan 14, 2017
1 parent e2f3162 commit 42296ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,16 @@ float Steps::GetMSD(float x, int i) const {
return lerp(prop, stuffnthings[idx][i], stuffnthings[idx + 1][i]);
}

map<float, Skillset> Steps::SortSkillsetsAtRate(float x, bool includeoverall) {
int idx = static_cast<int>(x * 10) - 7;
map<float, Skillset> why;
SDiffs tmp = stuffnthings[idx];
FOREACH_ENUM(Skillset, ss)
if(ss != Skill_Overall || includeoverall)
why.emplace(tmp[ss], ss);
return why;
}

RString Steps::GenerateChartKey(NoteData& nd, TimingData *td)
{
RString k = "";
Expand Down Expand Up @@ -852,20 +862,41 @@ class LunaSteps: public Luna<Steps>
return 1;
}

static int GetChartKey(T* p, lua_State *L)
{
static int GetChartKey(T* p, lua_State *L) {
lua_pushstring(L, p->GetChartKey());
return 1;
}

static int GetMSD(T* p, lua_State *L)
{
static int GetMSD(T* p, lua_State *L) {
float rate = FArg(1);
int index = IArg(2)-1;
CLAMP(rate, 0.7f, 2.f);
lua_pushnumber(L, p->GetMSD(rate, index));
return 1;
}
// ok really is this how i have to do this - mina
static int GetRelevantSkillsetsByMSDRank(T* p, lua_State *L) {
auto sortedskillsets = p->SortSkillsetsAtRate(FArg(1), false);
int rank = IArg(2);
int i = NUM_Skillset - 1; // exclude Overall from this... need to handle overall better - mina
Skillset o;
float rval = 0.f;
float highval = 0.f;
FOREACHM(float, Skillset, sortedskillsets, thingy) {
if (i == rank) {
rval = thingy->first;
o = thingy->second;
}
if (i == 1)
highval = thingy->first;
--i;
}
if(rval > highval * 0.9f)
lua_pushstring(L, SkillsetToString(o) );
else
lua_pushstring(L, "");
return 1;
}

LunaSteps()
{
Expand Down Expand Up @@ -895,6 +926,7 @@ class LunaSteps: public Luna<Steps>
ADD_METHOD( IsDisplayBpmRandom );
ADD_METHOD( PredictMeter );
ADD_METHOD( GetDisplayBPMType );
ADD_METHOD( GetRelevantSkillsetsByMSDRank );
}
};

Expand Down
1 change: 1 addition & 0 deletions src/Steps.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class Steps
void SetChartKey(const RString &k) { ChartKey = k; }
void SetAllMSD(const MinaSD &msd) { stuffnthings = msd; }
MinaSD GetAllMSD() const { return stuffnthings; }
map<float, Skillset> SortSkillsetsAtRate(float x, bool includeoverall);

// prolly needs an enum or something idk - mina
float GetMSD(float x, int i) const;
Expand Down

0 comments on commit 42296ef

Please sign in to comment.