Creating mapping of preferred sort section name to songs.

This commit is contained in:
Crash Cringle
2024-02-25 11:12:46 -05:00
committed by teejusb
parent 6cd43782d5
commit 3fd0bd8ade
4 changed files with 40 additions and 37 deletions
@@ -0,0 +1 @@
Common fallback banner
+6 -12
View File
@@ -695,24 +695,19 @@ void MusicWheel::BuildWheelItemDatas( std::vector<MusicWheelItemData *> &arrayWh
{
if( bUseSections )
{
// Get all section names
std::vector<RString> vsSectionNames = SONGMAN->GetPreferredSortSectionNames();
for( unsigned i=0; i<vsSectionNames.size(); i++ )
// Get mappping of section names to songs
std::map<RString, std::vector<Song*>> preferredSortSongsMap = SONGMAN->GetPreferredSortSongsMap();
for (auto const& [sectionName, songs] : SONGMAN->GetPreferredSortSongsMap())
{
// Get all songs in this section
std::vector<Song*> vsSongsInSection = SONGMAN->GetPreferredSortSongsBySectionName( vsSectionNames[i] );
// todo: preferred sort section color handling? -aj
RageColor colorSection = SECTION_COLORS.GetValue(iSectionColorIndex);
iSectionColorIndex = (iSectionColorIndex+1) % NUM_SECTION_COLORS;
// Add the section item
arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Section, nullptr, vsSectionNames[i], nullptr, SONGMAN->GetSongGroupColor(vsSectionNames[i]), vsSongsInSection.size()) );
arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Section, nullptr, sectionName, nullptr, colorSection, songs.size()) );
// Add all the songs in this section
for( unsigned j=0; j<vsSongsInSection.size(); j++ )
for (auto const& song : songs)
{
arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Song, vsSongsInSection[j], vsSectionNames[i], nullptr, SONGMAN->GetSongColor(vsSongsInSection[j]), 0) );
arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Song, song, sectionName, nullptr, SONGMAN->GetSongColor(song), 0) );
}
}
}
@@ -738,7 +733,6 @@ void MusicWheel::BuildWheelItemDatas( std::vector<MusicWheelItemData *> &arrayWh
iSectionCount = j-i;
// new section, make a section item
// todo: preferred sort section color handling? -aj
RageColor colorSection = (so==SORT_GROUP) ? SONGMAN->GetSongGroupColor(pSong->m_sGroupName) : SECTION_COLORS.GetValue(iSectionColorIndex);
iSectionColorIndex = (iSectionColorIndex+1) % NUM_SECTION_COLORS;
arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Section, nullptr, sThisSection, nullptr, colorSection, iSectionCount) );
+30 -25
View File
@@ -848,14 +848,10 @@ RString SongManager::SongToPreferredSortSectionName( const Song *pSong ) const
void SongManager::GetPreferredSortSongsBySectionName( const RString &sSectionName, std::vector<Song*> &AddTo ) const
{
for (PreferredSortSection const &v : m_vPreferredSongSort)
{
if (v.sName == sSectionName)
{
AddTo.insert( AddTo.end(), v.vpSongs.begin(), v.vpSongs.end() );
return;
}
}
// Use m_mapPreferredSectionToSongs
std::map<RString, SongPointerVector>::const_iterator iter = m_mapPreferredSectionToSongs.find( sSectionName );
if( iter != m_mapPreferredSectionToSongs.end() )
AddTo.insert( AddTo.end(), iter->second.begin(), iter->second.end() );
}
std::vector<Song*> SongManager::GetPreferredSortSongsBySectionName( const RString &sSectionName ) const
@@ -868,11 +864,11 @@ std::vector<Song*> SongManager::GetPreferredSortSongsBySectionName( const RStrin
std::vector<RString> SongManager::GetPreferredSortSectionNames() const
{
std::vector<RString> sectionNames;
for (PreferredSortSection const &v : m_vPreferredSongSort)
{
sectionNames.push_back(v.sName);
}
// Use m_mapPreferredSectionToSongs
for (std::pair<RString const, SongPointerVector> const &iter : m_mapPreferredSectionToSongs)
sectionNames.push_back(iter.first);
return sectionNames;
}
void SongManager::GetPreferredSortCourses( CourseType ct, std::vector<Course*> &AddTo, bool bIncludeAutogen ) const
@@ -1635,6 +1631,7 @@ void SongManager::SetPreferredSongs(RString sPreferredSongs, bool bIsAbsolute) {
ASSERT( UNLOCKMAN != nullptr );
m_vPreferredSongSort.clear();
m_mapPreferredSectionToSongs.clear();
std::vector<RString> asLines;
RString sFile = sPreferredSongs;
if (!bIsAbsolute)
@@ -1654,6 +1651,7 @@ void SongManager::SetPreferredSongs(RString sPreferredSongs, bool bIsAbsolute) {
if( !section.vpSongs.empty() )
{
m_vPreferredSongSort.push_back( section );
m_mapPreferredSectionToSongs[section.sName] = section.vpSongs;
section = PreferredSortSection();
}
@@ -1693,6 +1691,7 @@ void SongManager::SetPreferredSongs(RString sPreferredSongs, bool bIsAbsolute) {
if( !section.vpSongs.empty() )
{
m_vPreferredSongSort.push_back( section );
m_mapPreferredSectionToSongs[section.sName] = section.vpSongs;
section = PreferredSortSection();
}
@@ -1711,25 +1710,31 @@ void SongManager::SetPreferredSongs(RString sPreferredSongs, bool bIsAbsolute) {
}
}
for (std::vector<PreferredSortSection>::iterator v = m_vPreferredSongSort.begin(); v != m_vPreferredSongSort.end(); ++v)
{
for( int i=v->vpSongs.size()-1; i>=0; i-- )
{
Song *pSong = v->vpSongs[i];
if( find(PFSection.vpSongs.begin(),PFSection.vpSongs.end(),pSong) != PFSection.vpSongs.end() )
{
v->vpSongs.erase( v->vpSongs.begin()+i );
}
}
}
// NOTE(crashcringle): This code removed the unlocks from other sections they might have been in.
// This was needed due to the previous 1:1 relationship between songs and section in order for the song to appear in the Unlocks section correctly.
// Commented out for now.
// for (std::vector<PreferredSortSection>::iterator v = m_vPreferredSongSort.begin(); v != m_vPreferredSongSort.end(); ++v)
// {
// for( int i=v->vpSongs.size()-1; i>=0; i-- )
// {
// Song *pSong = v->vpSongs[i];
// if( find(PFSection.vpSongs.begin(),PFSection.vpSongs.end(),pSong) != PFSection.vpSongs.end() )
// {
// v->vpSongs.erase( v->vpSongs.begin()+i );
// }
// }
// }
m_vPreferredSongSort.push_back( PFSection );
m_mapPreferredSectionToSongs[PFSection.sName] = PFSection.vpSongs;
}
// prune empty groups
for( int i=m_vPreferredSongSort.size()-1; i>=0; i-- )
if( m_vPreferredSongSort[i].vpSongs.empty() )
if( m_vPreferredSongSort[i].vpSongs.empty() ) {
m_vPreferredSongSort.erase( m_vPreferredSongSort.begin()+i );
m_mapPreferredSectionToSongs.erase( m_vPreferredSongSort[i].sName );
}
for (PreferredSortSection const &i : m_vPreferredSongSort)
{
+3
View File
@@ -143,6 +143,7 @@ public:
const std::vector<Song *> &GetAllSongsOfCurrentGame() const;
void GetPreferredSortSongs( std::vector<Song*> &AddTo ) const;
std::map<RString, std::vector<Song*>> GetPreferredSortSongsMap() const { return m_mapPreferredSectionToSongs;};
RString SongToPreferredSortSectionName( const Song *pSong ) const;
std::vector<RString> GetPreferredSortSectionNames() const;
std::vector<Song*> GetPreferredSortSongsBySectionName( const RString &sSectionName ) const;
@@ -229,6 +230,8 @@ protected:
RString sName;
std::vector<Song*> vpSongs;
};
/** @brief All preferred songs, keyed by section */
std::map<RString, std::vector<Song*>> m_mapPreferredSectionToSongs;
std::vector<PreferredSortSection> m_vPreferredSongSort;
std::vector<RString> m_sSongGroupNames;
std::vector<RString> m_sSongGroupBannerPaths; // each song group may have a banner associated with it