Skip to content

Commit

Permalink
Add FilterByStepKeys to the MusicWheel
Browse files Browse the repository at this point in the history
The function works by passing a vector with hashes of stepcharts by parameter
  • Loading branch information
caiohsr14 committed Apr 1, 2018
1 parent e64f811 commit 9ee6ac9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
49 changes: 43 additions & 6 deletions src/MusicWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void MusicWheel::ReloadSongList(bool searching, RString findme)
SCREENMAN->PostMessageToTopScreen(SM_SongChanged, 0);

// when searching, automatically land on the first search result available -mina & dadbearcop
if (findme != "")
if (findme != "" || !hashList.empty())
{
if (groupnamesearchmatch != "") {
SelectSection(groupnamesearchmatch);
Expand Down Expand Up @@ -394,7 +394,7 @@ void MusicWheel::GetSongList( vector<Song*> &arraySongs, SortOrder so )
}
}
}
bool contains(std::string container, std::string findme) {
bool contains(string container, string findme) {
std::transform(begin(container), end(container), begin(container), ::tolower);
return container.find(findme) != string::npos;
}
Expand All @@ -407,9 +407,9 @@ void MusicWheel::FilterBySearch(vector<Song*>& inv, RString findme) {
size_t artist = findme.find("artist=");
size_t author = findme.find("author=");
size_t title = findme.find("title=");
std::string findartist = "";
std::string findauthor = "";
std::string findtitle = "";
string findartist = "";
string findauthor = "";
string findtitle = "";

if (artist != findme.npos || author != findme.npos || title != findme.npos) {
super_search = true;
Expand Down Expand Up @@ -493,6 +493,27 @@ void MusicWheel::FilterBySearch(vector<Song*>& inv, RString findme) {
}
}

void MusicWheel::SetHashList(const vector<string> &newHashList) { hashList = newHashList; }

void MusicWheel::FilterByStepKeys(vector<Song*>& inv) {
vector<Song*> tmp;
std::function<bool(Song*)> check;
check = [this](Song* x) {
FOREACH(string, hashList, hash)
if (x->HasChartByHash(*hash)) {
return true;
}
return false;
};
for (Song* x : inv) {
if (check(x))
tmp.emplace_back(x);
}
if (tmp.size() > 0) {
inv.swap(tmp);
}
}

bool MusicWheel::SearchGroupNames(RString& findme) {
const vector<RString>& grps = SONGMAN->GetSongGroupNames();
for (size_t i = 0; i < grps.size(); ++i) {
Expand Down Expand Up @@ -599,7 +620,7 @@ void MusicWheel::FilterBySkillsets(vector<Song*>& inv) {
inv.swap(tmp);
}

void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelItemDatas, SortOrder so, bool searching, RString findme )
void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelItemDatas, SortOrder so, bool searching, RString findme)
{

map<RString,Commands> commanDZ;
Expand Down Expand Up @@ -634,6 +655,9 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelIt
if (searching)
FilterBySearch(arraySongs, findme);

if (!hashList.empty())
FilterByStepKeys(arraySongs);

if (FILTERMAN->AnyActiveFilter())
FilterBySkillsets(arraySongs);

Expand Down Expand Up @@ -1548,6 +1572,18 @@ class LunaMusicWheel : public Luna<MusicWheel>
return 1;
}

static int FilterByStepKeys(T* p, lua_State *L)
{
luaL_checktype(L, 1, LUA_TTABLE);
lua_pushvalue(L, 1);
vector<string> newHashList;
LuaHelpers::ReadArrayFromTable(newHashList, L);
lua_pop(L, 1);
p->SetHashList(newHashList);
p->ReloadSongList(false, "");
return 1;
}

LunaMusicWheel()
{
ADD_METHOD(ChangeSort);
Expand All @@ -1558,6 +1594,7 @@ class LunaMusicWheel : public Luna<MusicWheel>
ADD_METHOD(ReloadSongList);
ADD_METHOD(Move);
ADD_METHOD(MoveAndCheckType);
ADD_METHOD(FilterByStepKeys);
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/MusicWheel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,20 @@ class MusicWheel : public WheelBase
const MusicWheelItemData *GetCurWheelItemData( int i ) { return (const MusicWheelItemData *) m_CurWheelItemData[i]; }

virtual void ReloadSongList(bool searching, RString findme);
void SetHashList( const vector<string> &newHashList );

// Lua
void PushSelf( lua_State *L ) override;

protected:
MusicWheelItem *MakeItem() override;

vector<string> hashList;
void GetSongList( vector<Song*> &arraySongs, SortOrder so );
bool SelectSongOrCourse();
bool SelectModeMenuItem();

void FilterByStepKeys(vector<Song*>& inv);
void FilterBySearch(vector<Song*>& inv, RString findme);
bool SearchGroupNames(RString & findme);
void FilterBySkillsets(vector<Song*>& inv);
Expand Down Expand Up @@ -111,7 +114,7 @@ class MusicWheel : public WheelBase
vector<MusicWheelItemData *> m__WheelItemDatas[NUM_SortOrder];
vector<MusicWheelItemData *> m__UnFilteredWheelItemDatas[NUM_SortOrder];

void BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelItems, SortOrder so, bool searching, RString findme );
void BuildWheelItemDatas( vector<MusicWheelItemData *> &arrayWheelItems, SortOrder so, bool searching, RString findme);
void FilterWheelItemDatas(vector<MusicWheelItemData*>& aUnFilteredDatas, vector<MusicWheelItemData*>& aFilteredData, SortOrder so);
void SelectSongAfterSearch();
RString prevSongTitle;
Expand Down

0 comments on commit 9ee6ac9

Please sign in to comment.