Skip to content

Commit 26559ef

Browse files
nico-abramMinaciousGrace
authored andcommitted
Filter by length (etternagame#105)
* Length filter * Fix highest only length filtering
1 parent 5d1f844 commit 26559ef

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

Themes/Til Death/BGAnimations/ScreenSelectMusic decorations/filters.lua

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ local frameHeight = 350
1414
local offsetX = 10
1515
local offsetY = 20
1616
local activebound = 0
17-
for i=1,#ms.SkillSets do
17+
for i=1,#ms.SkillSets+1 do
1818
SSQuery[0][i] = "0"
1919
SSQuery[1][i] = "0"
2020
end
@@ -37,7 +37,7 @@ local function FilterInput(event)
3737
SSQuery[activebound][ActiveSS] = ""
3838
end
3939
SSQuery[activebound][ActiveSS] = SSQuery[activebound][ActiveSS]..numbershers[i]
40-
if #SSQuery[activebound][ActiveSS] > 2 then
40+
if (ActiveSS < #ms.SkillSets+1 and #SSQuery[activebound][ActiveSS] > 2) or #SSQuery[activebound][ActiveSS] > 3 then
4141
SSQuery[activebound][ActiveSS] = numbershers[i]
4242
end
4343
end
@@ -273,12 +273,12 @@ local function CreateFilterInputBox(i)
273273
self:addx(10):addy(175 + (i-1)*spacingY):halign(0):zoom(textzoom)
274274
end,
275275
SetCommand=function(self)
276-
self:settext( ms.SkillSets[i])
276+
self:settext( i == (#ms.SkillSets+1) and "Length" or ms.SkillSets[i])
277277
end
278278
},
279279
Def.Quad{
280280
InitCommand=function(self)
281-
self:addx(150):addy(175 + (i-1)*spacingY):zoomto(18,18):halign(1)
281+
self:addx(i == (#ms.SkillSets+1) and 159 or 150):addy(175 + (i-1)*spacingY):zoomto(i == (#ms.SkillSets+1) and 27 or 18,18):halign(1)
282282
end,
283283
MouseLeftClickMessageCommand=function(self)
284284
if isOver(self) and active then
@@ -308,7 +308,7 @@ local function CreateFilterInputBox(i)
308308
},
309309
LoadFont("Common Large")..{
310310
InitCommand=function(self)
311-
self:addx(150):addy(175 + (i-1)*spacingY):halign(1):maxwidth(40):zoom(textzoom)
311+
self:addx(i == (#ms.SkillSets+1) and 159 or 150):addy(175 + (i-1)*spacingY):halign(1):maxwidth(60):zoom(textzoom)
312312
end,
313313
SetCommand=function(self)
314314
local fval = FILTERMAN:GetSSFilter(i,0) -- lower bounds
@@ -328,7 +328,7 @@ local function CreateFilterInputBox(i)
328328
},
329329
Def.Quad{
330330
InitCommand=function(self)
331-
self:addx(175):addy(175 + (i-1)*spacingY):zoomto(18,18):halign(1)
331+
self:addx(i == (#ms.SkillSets+1) and 193 or 175):addy(175 + (i-1)*spacingY):zoomto(i == (#ms.SkillSets+1) and 27 or 18,18):halign(1)
332332
end,
333333
MouseLeftClickMessageCommand=function(self)
334334
if isOver(self) and active then
@@ -358,7 +358,7 @@ local function CreateFilterInputBox(i)
358358
},
359359
LoadFont("Common Large")..{
360360
InitCommand=function(self)
361-
self:addx(175):addy(175 + (i-1)*spacingY):halign(1):maxwidth(40):zoom(textzoom)
361+
self:addx(i == (#ms.SkillSets+1) and 193 or 175):addy(175 + (i-1)*spacingY):halign(1):maxwidth(60):zoom(textzoom)
362362
end,
363363
SetCommand=function(self)
364364
local fval = FILTERMAN:GetSSFilter(i,1) -- upper bounds
@@ -408,8 +408,7 @@ f[#f+1] = LoadFont("Common Large") .. {
408408
end
409409
}
410410

411-
for i=1,#ms.SkillSets do
411+
for i=1,(#ms.SkillSets+1) do
412412
f[#f+1] = CreateFilterInputBox(i)
413413
end
414-
415414
return f

src/FilterManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ void FilterManager::SetSSFilter(float v, Skillset ss, int bound) {
4949

5050
// reset button for filters
5151
void FilterManager::ResetSSFilters() {
52-
FOREACH_ENUM(Skillset, ss) {
52+
for (int ss = 0; ss < NUM_Skillset + 1; ss++) {
5353
SSFilterLowerBounds[ss] = 0;
5454
SSFilterUpperBounds[ss] = 0;
5555
}
5656
}
5757

5858
// tmp filter stuff - mina
5959
bool FilterManager::AnyActiveFilter() {
60-
FOREACH_ENUM(Skillset, ss) {
60+
for(int ss=0; ss < NUM_Skillset + 1; ss++) {
6161
if (SSFilterLowerBounds[ss] > 0)
6262
return true;
6363
if (SSFilterUpperBounds[ss] > 0)

src/FilterManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class FilterManager {
1111

1212
PlayerState* m_pPlayerState[NUM_PLAYERS];
1313

14-
float SSFilterLowerBounds[NUM_Skillset];
15-
float SSFilterUpperBounds[NUM_Skillset];
14+
float SSFilterLowerBounds[NUM_Skillset+1];
15+
float SSFilterUpperBounds[NUM_Skillset+1];
1616
float MaxFilterRate = 1.f;
1717
bool ExclusiveFilter = false; // if true the filter system will only match songs that meet all criteria rather than all that meet any - mina
1818
float GetSSFilter(Skillset ss, int bound);

src/MusicWheel.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ void MusicWheel::FilterBySkillsets(vector<Song*>& inv) {
514514
if (!FILTERMAN->ExclusiveFilter) {
515515
for (size_t i = 0; i < inv.size(); i++) {
516516
bool addsong = false;
517-
FOREACH_ENUM(Skillset, ss) {
517+
for (int ss = 0; ss < NUM_Skillset + 1; ss++) {
518518
float lb = FILTERMAN->SSFilterLowerBounds[ss];
519519
float ub = FILTERMAN->SSFilterUpperBounds[ss];
520520
if (lb > 0.f || ub > 0.f) { // if either bound is active, continue to evaluation
@@ -523,10 +523,15 @@ void MusicWheel::FilterBySkillsets(vector<Song*>& inv) {
523523
do {
524524
currate = currate - 0.1f;
525525
if (FILTERMAN->HighestSkillsetsOnly)
526-
if (!inv[i]->IsSkillsetHighestOfAnySteps(ss, currate))
526+
if (!inv[i]->IsSkillsetHighestOfAnySteps(static_cast<Skillset>(ss), currate) && ss < NUM_Skillset)
527527
continue;
528-
529-
float val = inv[i]->GetHighestOfSkillsetAllSteps(static_cast<int>(ss), currate);
528+
float val;
529+
if (ss < NUM_Skillset)
530+
val = inv[i]->GetHighestOfSkillsetAllSteps(ss, currate);
531+
else {
532+
TimingData* td = inv[i]->GetAllSteps()[0]->GetTimingData();
533+
val = (td->GetElapsedTimeFromBeat(inv[i]->GetLastBeat()) - td->GetElapsedTimeFromBeat(inv[i]->GetFirstBeat()));
534+
}
530535

531536
bool isrange = lb > 0.f && ub > 0.f; // both bounds are active and create an explicit range
532537
if (isrange) {
@@ -542,7 +547,6 @@ void MusicWheel::FilterBySkillsets(vector<Song*>& inv) {
542547
} while (currate > minrate);
543548
}
544549
}
545-
546550
// only add the song if it's cleared the gauntlet
547551
if (addsong)
548552
tmp.emplace_back(inv[i]);
@@ -551,7 +555,7 @@ void MusicWheel::FilterBySkillsets(vector<Song*>& inv) {
551555
else {
552556
for (size_t i = 0; i < inv.size(); i++) {
553557
bool addsong = true;
554-
FOREACH_ENUM(Skillset, ss) {
558+
for (int ss = 0; ss < NUM_Skillset + 1; ss++) {
555559
bool pineapple = true;
556560
float lb = FILTERMAN->SSFilterLowerBounds[ss];
557561
float ub = FILTERMAN->SSFilterUpperBounds[ss];
@@ -563,7 +567,13 @@ void MusicWheel::FilterBySkillsets(vector<Song*>& inv) {
563567
do {
564568
localaddsong = true;
565569
currate = currate - 0.1f;
566-
float val = inv[i]->GetHighestOfSkillsetAllSteps(static_cast<int>(ss), currate);
570+
float val;
571+
if (ss < NUM_Skillset)
572+
val = inv[i]->GetHighestOfSkillsetAllSteps(ss, currate);
573+
else {
574+
TimingData* td = inv[i]->GetAllSteps()[0]->GetTimingData();
575+
val = (td->GetElapsedTimeFromBeat(inv[i]->GetLastBeat()) - td->GetElapsedTimeFromBeat(inv[i]->GetFirstBeat()));
576+
}
567577
bool isrange = lb > 0.f && ub > 0.f;
568578
if (isrange) {
569579
if (val < lb || val > ub)
@@ -581,7 +591,6 @@ void MusicWheel::FilterBySkillsets(vector<Song*>& inv) {
581591
}
582592
addsong = addsong && pineapple;
583593
}
584-
585594
if (addsong)
586595
tmp.emplace_back(inv[i]);
587596
}

0 commit comments

Comments
 (0)