From dd60d360937e492651a0eeb3cfd5450f819a7d8a Mon Sep 17 00:00:00 2001 From: Crash Cringle <30600688+CrashCringle12@users.noreply.github.com> Date: Sun, 2 Mar 2025 12:28:21 -0500 Subject: [PATCH] Implement changes from feedback --- src/Group.cpp | 155 +++++++++++++---------------------------- src/MusicWheelItem.cpp | 6 +- src/SongManager.cpp | 107 +++++++++++++++++++++------- src/SongManager.h | 12 ++-- src/SongUtil.cpp | 2 - 5 files changed, 138 insertions(+), 144 deletions(-) diff --git a/src/Group.cpp b/src/Group.cpp index 37291a63d0..4bfd031a95 100644 --- a/src/Group.cpp +++ b/src/Group.cpp @@ -37,7 +37,7 @@ Group::Group() { } Group::~Group() { - SONGMAN->GetGroupGroupMap().clear(); + SONGMAN->GetGroupGroupMap().erase(m_sGroupName); } Group::Group(const RString& sDir, const RString& sGroupDirName) { @@ -48,124 +48,65 @@ Group::Group(const RString& sDir, const RString& sGroupDirName) { RString sSeries = ""; RString sBannerPath = ""; float fOffset = PREFSMAN->m_fMachineSyncBias; - + m_iVersion = INI_VERSION; + if (FILEMAN->DoesFileExist(sPackIniPath)) { IniFile ini; ini.ReadFile(sPackIniPath); - ini.GetValue("Group", "DisplayTitle", sDisplayTitle); - Trim(sDisplayTitle); - if (sDisplayTitle.empty()) { - sDisplayTitle = Basename(sGroupDirName); - } - ini.GetValue("Group", "Banner", sBannerPath); - ini.GetValue("Group", "SortTitle", sSortTitle); - Trim(sSortTitle); - if (sSortTitle.empty()) { - sSortTitle = sDisplayTitle; - } - ini.GetValue("Group", "TranslitTitle", sTranslitTitle); - Trim(sTranslitTitle); - if (sTranslitTitle.empty()) { - sTranslitTitle = sDisplayTitle; - } - ini.GetValue("Group", "Series", sSeries); - RString sValue = ""; - - ini.GetValue("Group", "SyncOffset", sValue); - Trim(sValue); - if (!sValue.empty()) { - if (sValue.CompareNoCase("null") == 0) { - fOffset = 0.0f; - } else if (sValue.CompareNoCase("itg") == 0) { - fOffset = -0.009f; - } else { - fOffset = StringToFloat(sValue); - } - } - ini.GetValue("Group", "Year", m_iYearReleased); - + RString sVersion = ""; ini.GetValue("Group", "Version", sVersion); Trim(sVersion); + + // Only read the Pack.ini if the version is set + // Otherwise log a warning and skip reading the if (!sVersion.empty()) { + m_bHasPackIni = true; m_iVersion = StringToInt(sVersion); - } else { - // If the version is not set, set it to the current version - // and write it to the file. - m_iVersion = INI_VERSION; - ini.SetValue("Group", "Version", INI_VERSION); - if( !ini.WriteFile(sPackIniPath)) { - RString sError = ssprintf( "Error writing pack.ini ", sPackIniPath.c_str(), ini.GetError().c_str() ); - Dialog::OK( sError ); + + ini.GetValue("Group", "DisplayTitle", sDisplayTitle); + Trim(sDisplayTitle); + if (sDisplayTitle.empty()) { + sDisplayTitle = Basename(sGroupDirName); + } + ini.GetValue("Group", "Banner", sBannerPath); + if (sBannerPath.empty()) { + m_sBannerPath = sBannerPath; } - } - } else { - m_bHasPackIni = false; - m_iVersion = INI_VERSION; - fOffset = PREFSMAN->m_fMachineSyncBias; + ini.GetValue("Group", "SortTitle", sSortTitle); + Trim(sSortTitle); + if (sSortTitle.empty()) { + sSortTitle = sDisplayTitle; + } + + ini.GetValue("Group", "TranslitTitle", sTranslitTitle); + Trim(sTranslitTitle); + if (sTranslitTitle.empty()) { + sTranslitTitle = sDisplayTitle; + } + + ini.GetValue("Group", "Series", sSeries); + + RString sValue = ""; + ini.GetValue("Group", "SyncOffset", sValue); + Trim(sValue); + if (!sValue.empty()) { + if (sValue.CompareNoCase("null") == 0) { + fOffset = 0.0f; + } else if (sValue.CompareNoCase("itg") == 0) { + fOffset = -0.009f; + } else { + LOG->Warn("Group::Group: Invalid SyncOffset value: %s in Pack.ini. Valid values are NULL and ITG. Defaulting to NULL.", sValue.c_str()); + } + } + + ini.GetValue("Group", "Year", m_iYearReleased); + } else { + LOG->Warn("Group::Group: Pack.ini version not set. Using default values."); + } } - - // Look for a group banner in this group folder - std::vector arrayGroupBanners; - - // First check if there is a banner provided in pack.ini - if(!sBannerPath.empty()) - { - GetDirListing(sDir + sGroupDirName + "/" + sBannerPath, arrayGroupBanners); - } - GetDirListing(sDir + sGroupDirName + "/*.png", arrayGroupBanners); - GetDirListing(sDir + sGroupDirName + "/*.jpg", arrayGroupBanners); - GetDirListing(sDir + sGroupDirName + "/*.jpeg", arrayGroupBanners); - GetDirListing(sDir + sGroupDirName + "/*.gif", arrayGroupBanners); - GetDirListing(sDir + sGroupDirName + "/*.bmp", arrayGroupBanners); - - if(!arrayGroupBanners.empty()) { - m_sBannerPath = sDir + sGroupDirName + "/" + arrayGroupBanners[0] ; - } - else - { - // Look for a group banner in the parent folder - GetDirListing(sDir + sGroupDirName + ".png", arrayGroupBanners); - GetDirListing(sDir + sGroupDirName + ".jpg", arrayGroupBanners); - GetDirListing(sDir + sGroupDirName + ".jpeg", arrayGroupBanners); - GetDirListing(sDir + sGroupDirName + ".gif", arrayGroupBanners); - GetDirListing(sDir + sGroupDirName + ".bmp", arrayGroupBanners); - if(!arrayGroupBanners.empty()) - m_sBannerPath = sDir + arrayGroupBanners[0]; - } - - /* Other group graphics are a bit trickier, and usually don't exist. - * A themer has a few options, namely checking the aspect ratio and - * operating on it. -aj - * TODO: Once the files are implemented in Song, bring the extensions - * from there into here. -aj */ - // Group background - - //vector arrayGroupBackgrounds; - //GetDirListing(sDir + sGroupDirName + "/*-bg.png", arrayGroupBanners); - //GetDirListing(sDir + sGroupDirName + "/*-bg.jpg", arrayGroupBanners); - //GetDirListing(sDir + sGroupDirName + "/*-bg.jpeg", arrayGroupBanners); - //GetDirListing(sDir + sGroupDirName + "/*-bg.gif", arrayGroupBanners); - //GetDirListing(sDir + sGroupDirName + "/*-bg.bmp", arrayGroupBanners); - /* - RString sBackgroundPath; - if(!arrayGroupBackgrounds.empty()) - sBackgroundPath = sDir + sGroupDirName + "/" + arrayGroupBackgrounds[0]; - else - { - // Look for a group background in the parent folder - GetDirListing(sDir + sGroupDirName + "-bg.png", arrayGroupBackgrounds); - GetDirListing(sDir + sGroupDirName + "-bg.jpg", arrayGroupBackgrounds); - GetDirListing(sDir + sGroupDirName + "-bg.jpeg", arrayGroupBackgrounds); - GetDirListing(sDir + sGroupDirName + "-bg.gif", arrayGroupBackgrounds); - GetDirListing(sDir + sGroupDirName + "-bg.bmp", arrayGroupBackgrounds); - if(!arrayGroupBackgrounds.empty()) - sBackgroundPath = sDir + arrayGroupBackgrounds[0]; - } - */ - m_sDisplayTitle = sDisplayTitle; m_sSortTitle = sSortTitle; m_sTranslitTitle = sTranslitTitle; diff --git a/src/MusicWheelItem.cpp b/src/MusicWheelItem.cpp index ed18c5bad1..615847d1dd 100644 --- a/src/MusicWheelItem.cpp +++ b/src/MusicWheelItem.cpp @@ -231,8 +231,10 @@ void MusicWheelItem::LoadFromWheelItemData( const WheelItemBaseData *pData, int sTranslitName = SONGMAN->ShortenGroupName(pWID->m_pGroup->GetTranslitTitle()); } else { - sDisplayName = SONGMAN->ShortenGroupName("[" + pWID->m_pGroup->GetSeries() +"] " + pWID->m_pGroup->GetDisplayTitle()); - sTranslitName = SONGMAN->ShortenGroupName("[" + pWID->m_pGroup->GetSeries() +"] " + pWID->m_pGroup->GetTranslitTitle()); + sDisplayName = SONGMAN->ShortenGroupName(pWID->m_sText); + sTranslitName = SONGMAN->ShortenGroupName(pWID->m_pGroup->GetTranslitTitle()); + // sDisplayName = SONGMAN->ShortenGroupName("[" + pWID->m_pGroup->GetSeries() +"] " + pWID->m_pGroup->GetDisplayTitle()); + // sTranslitName = SONGMAN->ShortenGroupName("[" + pWID->m_pGroup->GetSeries() +"] " + pWID->m_pGroup->GetTranslitTitle()); } } if( GAMESTATE->sExpandedSectionName == pWID->m_sText ) diff --git a/src/SongManager.cpp b/src/SongManager.cpp index 95b60c853a..cb1a7610ed 100644 --- a/src/SongManager.cpp +++ b/src/SongManager.cpp @@ -279,22 +279,77 @@ void SongManager::AddGroup( RString sDir, RString sGroupDirName, Group* group ) if( j != m_sSongGroupNames.size() ) return; // the group is already added - m_sSongGroupNames.push_back( sGroupDirName ); - // add to the group list - if( group ) - { - m_pGroups.push_back( group ); - } + RString sBannerPath; + + // Look for a group banner in this group folder + std::vector arrayGroupBanners; - if (m_mapGroupsByName.find(sGroupDirName) == m_mapGroupsByName.end()) + // First check if there is a banner provided in pack.ini + if(!group->GetBannerPath().empty()) { - m_mapGroupsByName[sGroupDirName] = group; + GetDirListing(sDir + sGroupDirName + "/" + group->GetBannerPath(), arrayGroupBanners); + } + GetDirListing( sDir+sGroupDirName+"/*.png", arrayGroupBanners ); + GetDirListing( sDir+sGroupDirName+"/*.jpg", arrayGroupBanners ); + GetDirListing( sDir+sGroupDirName+"/*.jpeg", arrayGroupBanners ); + GetDirListing( sDir+sGroupDirName+"/*.gif", arrayGroupBanners ); + GetDirListing( sDir+sGroupDirName+"/*.bmp", arrayGroupBanners ); + + if( !arrayGroupBanners.empty() ) + sBannerPath = sDir+sGroupDirName+"/"+arrayGroupBanners[0] ; + else + { + // Look for a group banner in the parent folder + GetDirListing( sDir+sGroupDirName+".png", arrayGroupBanners ); + GetDirListing( sDir+sGroupDirName+".jpg", arrayGroupBanners ); + GetDirListing( sDir+sGroupDirName+".jpeg", arrayGroupBanners ); + GetDirListing( sDir+sGroupDirName+".gif", arrayGroupBanners ); + GetDirListing( sDir+sGroupDirName+".bmp", arrayGroupBanners ); + if( !arrayGroupBanners.empty() ) + sBannerPath = sDir+arrayGroupBanners[0]; + } + + /* Other group graphics are a bit trickier, and usually don't exist. + * A themer has a few options, namely checking the aspect ratio and + * operating on it. -aj + * TODO: Once the files are implemented in Song, bring the extensions + * from there into here. -aj */ + // Group background + + //vector arrayGroupBackgrounds; + //GetDirListing(sDir + sGroupDirName + "/*-bg.png", arrayGroupBanners); + //GetDirListing(sDir + sGroupDirName + "/*-bg.jpg", arrayGroupBanners); + //GetDirListing(sDir + sGroupDirName + "/*-bg.jpeg", arrayGroupBanners); + //GetDirListing(sDir + sGroupDirName + "/*-bg.gif", arrayGroupBanners); + //GetDirListing(sDir + sGroupDirName + "/*-bg.bmp", arrayGroupBanners); + /* + RString sBackgroundPath; + if(!arrayGroupBackgrounds.empty()) + sBackgroundPath = sDir + sGroupDirName + "/" + arrayGroupBackgrounds[0]; + else + { + // Look for a group background in the parent folder + GetDirListing(sDir + sGroupDirName + "-bg.png", arrayGroupBackgrounds); + GetDirListing(sDir + sGroupDirName + "-bg.jpg", arrayGroupBackgrounds); + GetDirListing(sDir + sGroupDirName + "-bg.jpeg", arrayGroupBackgrounds); + GetDirListing(sDir + sGroupDirName + "-bg.gif", arrayGroupBackgrounds); + GetDirListing(sDir + sGroupDirName + "-bg.bmp", arrayGroupBackgrounds); + if(!arrayGroupBackgrounds.empty()) + sBackgroundPath = sDir + arrayGroupBackgrounds[0]; + } + */ + m_sSongGroupBannerPaths.push_back( sBannerPath ); + m_sSongGroupNames.push_back( sGroupDirName ); + + if (m_mapNameToGroup.find(sGroupDirName) == m_mapNameToGroup.end()) + { + m_mapNameToGroup[sGroupDirName] = group; } // Add the group to its series if the group has one and if the series exists if( group->GetSeries() != "" ) { - std::vector& series = m_mapSeries[group->GetSeries()]; + std::vector& series = m_mapSeriesToGroup[group->GetSeries()]; if( std::find(series.begin(), series.end(), group) == series.end() ) series.push_back(group); } @@ -415,7 +470,7 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio continue; } // Apply Group Offset if applicable - if( group->GetSyncOffset() != 0 ) + if( group->GetSyncOffset() != 0.0f ) { pNewSong->m_SongTiming.m_fBeat0GroupOffsetInSeconds = group->GetSyncOffset(); const std::vector& vpSteps = pNewSong->GetAllSteps(); @@ -444,7 +499,7 @@ void SongManager::LoadSongDir( RString sDir, LoadingWindow *ld, bool onlyAdditio AddGroup(sDir, sGroupDirName, group); // Cache and load the group banner. (and background if it has one -aj) - IMAGECACHE->CacheImage( "Banner", group->GetBannerPath() ); + IMAGECACHE->CacheImage( "Banner", GetSongGroupBannerPath(sGroupDirName) ); // Load the group sym links (if any) LoadGroupSymLinks(sDir, sGroupDirName); @@ -527,7 +582,6 @@ void SongManager::PreloadSongImages() void SongManager::FreeSongs() { m_sSongGroupNames.clear(); - m_mapGroupsByName.clear(); m_mapSongsByDifficulty.clear(); m_mapPreferredSectionToSongs.clear(); @@ -537,13 +591,15 @@ void SongManager::FreeSongs() { RageUtil::SafeDelete( song ); } - // Loop through all groups and delete them. - for (Group *group : m_pGroups) { - RageUtil::SafeDelete(group); - } + // Loop through all groups in the mapand delete them. + for (auto it = m_mapNameToGroup.begin(); it != m_mapNameToGroup.end(); ++it) + { + Group* group = it->second; + RageUtil::SafeDelete( group ); + } m_pSongs.clear(); - m_pGroups.clear(); + m_mapNameToGroup.clear(); m_SongsByDir.clear(); // also free the songs that have been deleted from disk @@ -583,13 +639,13 @@ bool SongManager::IsGroupNeverCached(const RString& group) const RString SongManager::GetSongGroupBannerPath( RString sSongGroup ) const { - Group* group = GetGroupFromName(sSongGroup); - if(group == nullptr) + for( unsigned i = 0; i < m_sSongGroupNames.size(); ++i ) { - LOG->Warn("Requested banner for song group '%s' that doesn't exist", sSongGroup.c_str()); - return RString(); + if( sSongGroup == m_sSongGroupNames[i] ) + return m_sSongGroupBannerPaths[i]; } - return group->GetBannerPath(); + + return RString(); } /* RString SongManager::GetSongGroupBackgroundPath( RString sSongGroup ) const @@ -622,9 +678,6 @@ bool SongManager::HasPackIni(RString sSongGroup) const return group->HasPackIni(); } LOG->Warn("Requested pack.ini for song group '%s' that doesn't exist", sSongGroup.c_str()); - #ifdef DEBUG - ASSERT_M( 0, ssprintf("requested pack.ini for song group '%s' that doesn't exist",sSongGroup.c_str()) ); - #endif return false; } @@ -871,8 +924,8 @@ Group* SongManager::GetGroup( const Song* pSong ) const Group* SongManager::GetGroupFromName( const RString& sGroupName ) const { - auto iter = m_mapGroupsByName.find( sGroupName ); - if( iter != m_mapGroupsByName.end() ) + auto iter = m_mapNameToGroup.find( sGroupName ); + if( iter != m_mapNameToGroup.end() ) return iter->second; return nullptr; } diff --git a/src/SongManager.h b/src/SongManager.h index 775a74b884..14368bbb25 100644 --- a/src/SongManager.h +++ b/src/SongManager.h @@ -147,8 +147,8 @@ public: void GetPreferredSortSongs( std::vector &AddTo ) const; std::map> GetPreferredSortSongsMap() const { return m_mapPreferredSectionToSongs;}; RString SongToPreferredSortSectionName( const Song *pSong ) const; - std::map GetGroupGroupMap() const { return m_mapGroupsByName;}; - std::map> GetSeriesGroupMap() const { return m_mapSeries;}; + std::map GetGroupGroupMap() const { return m_mapNameToGroup;}; + std::map> GetSeriesGroupMap() const { return m_mapSeriesToGroup;}; Group* GetGroupFromName( const RString &sGroupName ) const; Group* GetGroup( const Song *pSong ) const; std::vector GetPreferredSortSectionNames() const; @@ -223,8 +223,7 @@ protected: void AddSongToList(Song* new_song); /** @brief All of the songs that can be played. */ std::vector m_pSongs; - /** @brief All of the groups available */ - std::vector m_pGroups; + std::map m_SongsByDir; std::set m_GroupsToNeverCache; @@ -248,10 +247,11 @@ protected: std::map> m_mapPreferredSectionToSongs; std::vector m_vPreferredSongSort; std::vector m_sSongGroupNames; + std::vector m_sSongGroupBannerPaths; // each song group may have a banner associated with it //vector m_sSongGroupBackgroundPaths; // each song group may have a background associated with it (very rarely) - std::map m_mapGroupsByName; - std::map> m_mapSeries; + std::map m_mapNameToGroup; + std::map> m_mapSeriesToGroup; struct Comp { bool operator()(const RString& s, const RString &t) const { return CompareRStringsAsc(s,t); } }; typedef std::vector SongPointerVector; diff --git a/src/SongUtil.cpp b/src/SongUtil.cpp index 22fc5a1c9f..00a896efff 100644 --- a/src/SongUtil.cpp +++ b/src/SongUtil.cpp @@ -597,8 +597,6 @@ int SongUtil::CompareSongPointersByGroup(const Song *pSong1, const Song *pSong2) { // Check if the sort title exists if( SONGMAN->GetGroup(pSong1)->GetSortTitle().empty() || SONGMAN->GetGroup(pSong2)->GetSortTitle().empty() ) { - // LOG the DEETS - LOG->Warn("SongUtil::CompareSongPointersByGroup: Song %s or %s has an empty group name. Using group name instead.", pSong1->m_sSongName.c_str(), pSong2->m_sSongName.c_str()); return pSong1->m_sGroupName < pSong2->m_sGroupName; } else { return SONGMAN->GetGroup(pSong1)->GetSortTitle() < SONGMAN->GetGroup(pSong2)->GetSortTitle();