Skip to content

Commit

Permalink
handle filter logic depending on filtermode
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Jan 14, 2017
1 parent 9686b5e commit af0ece8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
11 changes: 4 additions & 7 deletions src/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ GameState::GameState() :
// filter stuff - mina
ZERO( SSFilterLowerBounds );
ZERO( SSFilterUpperBounds );
MaxFilterRate = 1.f;
FilterMode = 0;

// Register with Lua.
{
Expand Down Expand Up @@ -3289,15 +3287,14 @@ class LunaGameState: public Luna<GameState>
return 1;
}
static int ToggleFilterMode(T* p, lua_State* L) {
if (p->FilterMode == 1)
p->FilterMode = 0;
else
p->FilterMode = 1;
p->ExclusiveFilter = !p->ExclusiveFilter;
return 1;

}
static int GetFilterMode(T* p, lua_State* L) {
lua_pushnumber(L, p->FilterMode);
lua_pushboolean(L, p->ExclusiveFilter);
return 1;

}

LunaGameState()
Expand Down
4 changes: 2 additions & 2 deletions src/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ class GameState
// todo: make a filterman or something - mina
float SSFilterLowerBounds[NUM_Skillset];
float SSFilterUpperBounds[NUM_Skillset];
float MaxFilterRate;
int FilterMode; // 0 = OR 1 = AND
float MaxFilterRate = 1.f;
bool ExclusiveFilter = false; // if true the filter system will only match songs that meet all criteria rather than all that meet any - mina
float GetSSFilter(Skillset ss, int bound);
void SetSSFilter(float v, Skillset ss, int bound);

Expand Down
38 changes: 28 additions & 10 deletions src/MusicWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,19 +589,37 @@ void MusicWheel::FilterBySearch(vector<Song*>& inv, RString findme) {

void MusicWheel::FilterBySkillsets(vector<Song*>& inv) {
vector<Song*> tmp;
for (size_t i = 0; i < inv.size(); i++) {
bool addsong = false;
FOREACH_ENUM(Skillset, ss) {
float lb = GAMESTATE->SSFilterLowerBounds[ss];
if (lb > 0.f) {
float val = inv[i]->GetHighestOfSkillsetAllSteps(static_cast<int>(ss), GAMESTATE->MaxFilterRate);
if (val > lb)
addsong = addsong || true;
if (!GAMESTATE->ExclusiveFilter) {
for (size_t i = 0; i < inv.size(); i++) {
bool addsong = false;
FOREACH_ENUM(Skillset, ss) {
float lb = GAMESTATE->SSFilterLowerBounds[ss];
if (lb > 0.f) {
float val = inv[i]->GetHighestOfSkillsetAllSteps(static_cast<int>(ss), GAMESTATE->MaxFilterRate);
if (val > lb)
addsong = addsong || true;
}
}
if (addsong)
tmp.emplace_back(inv[i]);
}
}
else {
for (size_t i = 0; i < inv.size(); i++) {
bool addsong = true;
FOREACH_ENUM(Skillset, ss) {
float lb = GAMESTATE->SSFilterLowerBounds[ss];
if (lb > 0.f) {
float val = inv[i]->GetHighestOfSkillsetAllSteps(static_cast<int>(ss), GAMESTATE->MaxFilterRate);
if (val < lb)
addsong = false;
}
}
if (addsong)
tmp.emplace_back(inv[i]);
}
if (addsong == true)
tmp.emplace_back(inv[i]);
}

inv.swap(tmp);
}

Expand Down

0 comments on commit af0ece8

Please sign in to comment.