From adeb392fcff5c598a186b8c82875dbfe76633b61 Mon Sep 17 00:00:00 2001 From: Barinade Date: Sun, 12 Jul 2020 23:35:13 -0500 Subject: [PATCH] Consider filters when getting songs from songutil most of the time, when it matters --- src/Etterna/Models/Songs/SongUtil.cpp | 30 ++++++++++++++++--- src/Etterna/Models/Songs/SongUtil.h | 4 ++- .../Models/StepsAndStyles/StepsUtil.cpp | 4 +-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Etterna/Models/Songs/SongUtil.cpp b/src/Etterna/Models/Songs/SongUtil.cpp index 9f635729ae..42fca17a42 100644 --- a/src/Etterna/Models/Songs/SongUtil.cpp +++ b/src/Etterna/Models/Songs/SongUtil.cpp @@ -15,6 +15,8 @@ #include "Etterna/Models/Misc/ThemeMetric.h" #include "Etterna/FileTypes/XmlFile.h" #include "Etterna/Models/StepsAndStyles/StepsUtil.h" +#include "Etterna/Singletons/FilterManager.h" +#include "Etterna/Models/Misc/PlayerState.h" #include #include @@ -34,6 +36,7 @@ SongUtil::GetSteps(const Song* pSong, Difficulty dc, int iMeterLow, int iMeterHigh, + bool filteringSteps, const std::string& sDescription, const std::string& sCredit, bool bIncludeAutoGen, @@ -61,6 +64,22 @@ SongUtil::GetSteps(const Song* pSong, if (uHash != 0 && uHash != pSteps->GetHash()) continue; + if (FILTERMAN != nullptr && FILTERMAN->AnyActiveFilter()) { + // iterating over all rates until it just works + // explanation in MusicWheel::FilterBySkillsets + auto success = false; + for (auto currate = FILTERMAN->MaxFilterRate; + currate > FILTERMAN->m_pPlayerState->wtFFF - .01f; + currate -= 0.1f) { + if (pSteps->MatchesFilter(currate)) { + success = true; + break; + } + } + if (!success) + continue; + } + arrayAddTo.push_back(pSteps); if (iMaxToGet != -1) { @@ -77,6 +96,7 @@ SongUtil::GetOneSteps(const Song* pSong, Difficulty dc, int iMeterLow, int iMeterHigh, + bool filteringSteps, const std::string& sDescription, const std::string& sCredit, unsigned uHash, @@ -89,6 +109,7 @@ SongUtil::GetOneSteps(const Song* pSong, dc, iMeterLow, iMeterHigh, + filteringSteps, sDescription, sCredit, bIncludeAutoGen, @@ -147,7 +168,8 @@ SongUtil::GetStepsByDescription(const Song* pSong, const std::string& sDescription) { vector vNotes; - GetSteps(pSong, vNotes, st, Difficulty_Invalid, -1, -1, sDescription, ""); + GetSteps( + pSong, vNotes, st, Difficulty_Invalid, -1, -1, false, sDescription, ""); if (vNotes.empty()) return nullptr; return vNotes[0]; @@ -159,7 +181,7 @@ SongUtil::GetStepsByCredit(const Song* pSong, const std::string& sCredit) { vector vNotes; - GetSteps(pSong, vNotes, st, Difficulty_Invalid, -1, -1, "", sCredit); + GetSteps(pSong, vNotes, st, Difficulty_Invalid, -1, -1, false, "", sCredit); if (vNotes.empty()) return nullptr; return vNotes[0]; @@ -998,13 +1020,13 @@ SongUtil::GetPlayableStepsTypes(const Song* pSong, set& vOut) } void -SongUtil::GetPlayableSteps(const Song* pSong, vector& vOut) +SongUtil::GetPlayableSteps(const Song* pSong, vector& vOut, bool filteringSteps) { set vStepsType; GetPlayableStepsTypes(pSong, vStepsType); for (const auto& st : vStepsType) { - GetSteps(pSong, vOut, st); + GetSteps(pSong, vOut, st, Difficulty_Invalid, -1, -1, filteringSteps); } StepsUtil::SortNotesArrayByDifficulty(vOut); diff --git a/src/Etterna/Models/Songs/SongUtil.h b/src/Etterna/Models/Songs/SongUtil.h index 04f9f02863..b4c1786ca6 100644 --- a/src/Etterna/Models/Songs/SongUtil.h +++ b/src/Etterna/Models/Songs/SongUtil.h @@ -27,6 +27,7 @@ GetSteps(const Song* pSong, Difficulty dc = Difficulty_Invalid, int iMeterLow = -1, int iMeterHigh = -1, + bool filteringSteps = false, const std::string& sDescription = "", const std::string& sCredit = "", bool bIncludeAutoGen = true, @@ -38,6 +39,7 @@ GetOneSteps(const Song* pSong, Difficulty dc = Difficulty_Invalid, int iMeterLow = -1, int iMeterHigh = -1, + bool filteringSteps = false, const std::string& sDescription = "", const std::string& sCredit = "", unsigned uHash = 0, @@ -157,7 +159,7 @@ GetAllSongGenres(vector& vsOut); void GetPlayableStepsTypes(const Song* pSong, std::set& vOut); void -GetPlayableSteps(const Song* pSong, vector& vOut); +GetPlayableSteps(const Song* pSong, vector& vOut, bool filteringSteps = false); auto IsStepsTypePlayable(Song* pSong, StepsType st) -> bool; auto diff --git a/src/Etterna/Models/StepsAndStyles/StepsUtil.cpp b/src/Etterna/Models/StepsAndStyles/StepsUtil.cpp index cb5709be03..f170943ae4 100644 --- a/src/Etterna/Models/StepsAndStyles/StepsUtil.cpp +++ b/src/Etterna/Models/StepsAndStyles/StepsUtil.cpp @@ -196,9 +196,9 @@ StepsID::ToSteps(const Song* p, bool bAllowNull) const Steps* pRet = nullptr; if (dc == Difficulty_Edit) { pRet = SongUtil::GetOneSteps( - p, st, dc, -1, -1, sDescription, "", uHash, true); + p, st, dc, -1, -1, false, sDescription, "", uHash, true); } else { - pRet = SongUtil::GetOneSteps(p, st, dc, -1, -1, "", "", 0, true); + pRet = SongUtil::GetOneSteps(p, st, dc, -1, -1, false, "", "", 0, true); } if (!bAllowNull && pRet == nullptr)