Skip to content

Commit

Permalink
Implement Song::IsChartHighestDifficulty and add to filter logic
Browse files Browse the repository at this point in the history
TODO: Add Lua GUI side.
  • Loading branch information
bluebandit21 committed Aug 11, 2020
1 parent c8659eb commit a01090e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
26 changes: 18 additions & 8 deletions src/Etterna/Models/Songs/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,12 @@ Song::IsSkillsetHighestOfChart(Steps* chart, Skillset skill, float rate) const
{
return chart->IsSkillsetHighestOfChart(skill, rate);
}
bool
Song::IsChartHighestDifficulty(Steps* chart, Skillset skill, float rate) const
{
float highest = HighestMSDOfSkillset(skill, rate);
return (fabs(chart->GetMSD(rate, skill) - highest) <= 0.1F);
}

bool
Song::MatchesFilter(const float rate,
Expand Down Expand Up @@ -1717,7 +1723,6 @@ Song::MatchesFilter(const float rate,
bool
Song::ChartMatchesFilter(Steps* chart, float rate) const
{
// TODO: ADD SUPPORT FOR HighestDifficultyOnly
auto addchart = FILTERMAN->ExclusiveFilter;

/* The default behaviour of an exclusive filter is to accept
Expand All @@ -1733,14 +1738,19 @@ Song::ChartMatchesFilter(Steps* chart, float rate) const
const auto lb = FILTERMAN->SSFilterLowerBounds[ss];
const auto ub = FILTERMAN->SSFilterUpperBounds[ss];
if (lb > 0.F || ub > 0.F) { // If either bound is active, continue

if (!FILTERMAN->ExclusiveFilter) { // Non-Exclusive filter
if (FILTERMAN->HighestSkillsetsOnly) {
if (!(chart->IsSkillsetHighestOfChart(
static_cast<Skillset>(ss),
rate) &&
ss < NUM_Skillset)) { // The current skill is not
// in highest in the chart
if (FILTERMAN->HighestSkillsetsOnly && ss < NUM_Skillset) {
if (!chart->IsSkillsetHighestOfChart(
static_cast<Skillset>(ss), rate)) {
// The current skill is not the highest of the chart
continue;
}
}
if (FILTERMAN->HighestDifficultyOnly && ss < NUM_Skillset) {
if (!IsChartHighestDifficulty(
chart, static_cast<Skillset>(ss), rate)) {
// The song has a more difficult chart of the given
// skillset
continue;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Etterna/Models/Songs/Song.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ class Song
std::vector<Steps*>* vMatchingStepsOut = nullptr) const -> bool;
[[nodiscard]] auto ChartMatchesFilter(Steps* chart, float rate) const
-> bool;
[[nodiscard]] auto IsChartHighestDifficulty(Steps* chart,
Skillset skill,
float rate) const -> bool;
auto HasChartByHash(const std::string& hash) -> bool;

// For loading only:
Expand Down
10 changes: 5 additions & 5 deletions src/Etterna/Singletons/FilterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class FilterManager
void SetSSFilter(float v, Skillset ss, int bound);
void ResetSSFilters(); // reset button for filters
void ResetAllFilters();
bool HighestSkillsetsOnly =
false; // Skillset is highest of the chart's skillset
bool HighestDifficultyOnly =
false; // Chart's skillset's MSD is the highest of all the MSDS of that
// skillset for all charts for that song.
bool HighestSkillsetsOnly = false;
// Skillset is highest of the chart's skillset
bool HighestDifficultyOnly = false;
// Chart's skillset's MSD is the highest of all the MSDS of that
// skillset for all charts for that song.

auto AnyActiveFilter() -> bool;

Expand Down

0 comments on commit a01090e

Please sign in to comment.