From af0ece8b118484610888b62059b3f97bb5a1c885 Mon Sep 17 00:00:00 2001 From: MinaciousGrace Date: Sat, 14 Jan 2017 10:16:18 -0500 Subject: [PATCH] handle filter logic depending on filtermode --- src/GameState.cpp | 11 ++++------- src/GameState.h | 4 ++-- src/MusicWheel.cpp | 38 ++++++++++++++++++++++++++++---------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/GameState.cpp b/src/GameState.cpp index 5b0e03bde0..204a0131a2 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -180,8 +180,6 @@ GameState::GameState() : // filter stuff - mina ZERO( SSFilterLowerBounds ); ZERO( SSFilterUpperBounds ); - MaxFilterRate = 1.f; - FilterMode = 0; // Register with Lua. { @@ -3289,15 +3287,14 @@ class LunaGameState: public Luna 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() diff --git a/src/GameState.h b/src/GameState.h index 97d3523662..77163c777a 100644 --- a/src/GameState.h +++ b/src/GameState.h @@ -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); diff --git a/src/MusicWheel.cpp b/src/MusicWheel.cpp index a87b29da68..2f531d9cb8 100644 --- a/src/MusicWheel.cpp +++ b/src/MusicWheel.cpp @@ -589,19 +589,37 @@ void MusicWheel::FilterBySearch(vector& inv, RString findme) { void MusicWheel::FilterBySkillsets(vector& inv) { vector 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(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(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(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); }