From ac767b3ce8b035fdd35d314b05597b51880f0b1e Mon Sep 17 00:00:00 2001 From: Crash Cringle <30600688+CrashCringle12@users.noreply.github.com> Date: Sat, 22 Feb 2025 19:59:26 -0500 Subject: [PATCH] Move GetGroup to SONGMAN, rename variables consistently, move "pack.ini" to constant var, flip sync bias sign --- src/Group.cpp | 50 ++++++++++++++++++++++++++------------------- src/MusicWheel.cpp | 4 ++-- src/Song.cpp | 15 ++------------ src/Song.h | 2 -- src/SongManager.cpp | 18 ++++++++++++++++ src/SongManager.h | 1 + src/SongUtil.cpp | 10 ++++----- 7 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/Group.cpp b/src/Group.cpp index 2a9018348d..e1d3a1c0b9 100644 --- a/src/Group.cpp +++ b/src/Group.cpp @@ -14,6 +14,14 @@ #include #include + +/** @brief The file that contains the group information. + * We name this Pack.ini over Group.ini to avoid conflict + * with the Waiei Group.ini-lua project still actively + * being developed. +*/ +const RString INI_FILE = "Pack.ini"; + Group::Group() { m_sDisplayTitle = ""; m_sSortTitle = ""; @@ -32,12 +40,12 @@ Group::~Group() { } Group::Group(const RString& sDir, const RString& sGroupDirName) { - RString sPackIniPath = sDir + sGroupDirName + "/pack.ini"; + RString sPackIniPath = sDir + sGroupDirName + "/" + INI_FILE; RString sDisplayTitle = sGroupDirName; - RString SortTitle = sGroupDirName; - RString TranslitTitle = ""; - RString Series = ""; - RString bannerPath = ""; + RString sSortTitle = sGroupDirName; + RString sTranslitTitle = ""; + RString sSeries = ""; + RString sBannerPath = ""; float fOffset = PREFSMAN->m_fMachineSyncBias; if (FILEMAN->DoesFileExist(sPackIniPath)) { @@ -48,18 +56,18 @@ Group::Group(const RString& sDir, const RString& sGroupDirName) { if (sDisplayTitle.empty()) { sDisplayTitle = Basename(sGroupDirName); } - ini.GetValue("Group", "Banner", bannerPath); - ini.GetValue("Group", "SortTitle", SortTitle); - Trim(SortTitle); - if (SortTitle.empty()) { - SortTitle = sDisplayTitle; + ini.GetValue("Group", "Banner", sBannerPath); + ini.GetValue("Group", "SortTitle", sSortTitle); + Trim(sSortTitle); + if (sSortTitle.empty()) { + sSortTitle = sDisplayTitle; } - ini.GetValue("Group", "TranslitTitle", TranslitTitle); - Trim(TranslitTitle); - if (TranslitTitle.empty()) { - TranslitTitle = sDisplayTitle; + ini.GetValue("Group", "TranslitTitle", sTranslitTitle); + Trim(sTranslitTitle); + if (sTranslitTitle.empty()) { + sTranslitTitle = sDisplayTitle; } - ini.GetValue("Group", "Series", Series); + ini.GetValue("Group", "Series", sSeries); RString sValue = ""; ini.GetValue("Group", "SyncOffset", sValue); @@ -68,7 +76,7 @@ Group::Group(const RString& sDir, const RString& sGroupDirName) { if (sValue.CompareNoCase("null") == 0) { fOffset = 0.0f; } else if (sValue.CompareNoCase("itg") == 0) { - fOffset = 0.009f; + fOffset = -0.009f; } else { fOffset = StringToFloat(sValue); } @@ -84,9 +92,9 @@ Group::Group(const RString& sDir, const RString& sGroupDirName) { std::vector arrayGroupBanners; // First check if there is a banner provided in pack.ini - if(!bannerPath.empty()) + if(!sBannerPath.empty()) { - GetDirListing(sDir + sGroupDirName + "/" + bannerPath, arrayGroupBanners); + GetDirListing(sDir + sGroupDirName + "/" + sBannerPath, arrayGroupBanners); } GetDirListing(sDir + sGroupDirName + "/*.png", arrayGroupBanners); GetDirListing(sDir + sGroupDirName + "/*.jpg", arrayGroupBanners); @@ -140,9 +148,9 @@ Group::Group(const RString& sDir, const RString& sGroupDirName) { */ m_sDisplayTitle = sDisplayTitle; - m_sSortTitle = SortTitle; - m_sTranslitTitle = TranslitTitle; - m_sSeries = Series; + m_sSortTitle = sSortTitle; + m_sTranslitTitle = sTranslitTitle; + m_sSeries = sSeries; m_sPath = sDir + sGroupDirName; m_sGroupName = sGroupDirName; m_fSyncOffset = fOffset; diff --git a/src/MusicWheel.cpp b/src/MusicWheel.cpp index da7d1b3a49..a960c3f4a3 100644 --- a/src/MusicWheel.cpp +++ b/src/MusicWheel.cpp @@ -755,7 +755,7 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh for( unsigned i=0; i< arraySongs.size(); i++ ) { Song* pSong = arraySongs[i]; - Group* pGroup = pSong->GetGroup(); + Group* pGroup = SONGMAN->GetGroup(pSong); if( bUseSections ) { RString sThisSection = pGroup->GetGroupName(); @@ -812,7 +812,7 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh sLastSection = sThisSection; } } - arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Song, pSong, sLastSection, nullptr, pSong->GetGroup(), SONGMAN->GetSongColor(pSong), 0) ); + arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Song, pSong, sLastSection, nullptr, SONGMAN->GetGroup(pSong), SONGMAN->GetSongColor(pSong), 0) ); } break; } diff --git a/src/Song.cpp b/src/Song.cpp index 49fdb5daa6..6fc37f60e8 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -277,10 +277,6 @@ const RString &Song::GetSongFilePath() const * into Song.h, which is heavily used. */ static std::set BlacklistedImages; -Group* Song::GetGroup() const -{ - return SONGMAN->GetGroupFromName(m_sGroupName); -} /* If PREFSMAN->m_bFastLoad is true, always load from cache if possible. * Don't read the contents of sDir if we can avoid it. That means we can't call @@ -481,7 +477,7 @@ bool Song::ReloadFromSongDir( RString sDir ) return false; copy.RemoveAutoGenNotes(); *this = copy; - m_SongTiming.m_fBeat0GroupOffsetInSeconds = GetGroup()->GetSyncOffset(); + m_SongTiming.m_fBeat0GroupOffsetInSeconds = SONGMAN->GetGroupFromName(m_sGroupName)->GetSyncOffset(); /* Go through the steps, first setting their Song pointer to this song * (instead of the copy used above), and constructing a map to let us @@ -497,7 +493,7 @@ bool Song::ReloadFromSongDir( RString sDir ) // Reapply the Group Offset if the steps have their own timing data. if( mNewSteps[id]->m_Timing.empty() ) continue; - mNewSteps[id]->m_Timing.m_fBeat0GroupOffsetInSeconds = GetGroup()->GetSyncOffset(); + mNewSteps[id]->m_Timing.m_fBeat0GroupOffsetInSeconds = SONGMAN->GetGroupFromName(m_sGroupName)->GetSyncOffset(); } // Now we wipe out the new pointers, which were shallow copied and not deep copied... @@ -2281,12 +2277,6 @@ public: return 1; } - static int GetGroup( T* p, lua_State *L ) - { - p->GetGroup()->PushSelf(L); - return 1; - } - static int MusicLengthSeconds( T* p, lua_State *L ) { lua_pushnumber(L, p->m_fMusicLengthSeconds); @@ -2506,7 +2496,6 @@ public: ADD_METHOD( IsEnabled ); ADD_METHOD(IsCustomSong); ADD_METHOD( GetGroupName ); - ADD_METHOD( GetGroup ); ADD_METHOD( MusicLengthSeconds ); ADD_METHOD( GetSampleStart ); ADD_METHOD( GetSampleLength ); diff --git a/src/Song.h b/src/Song.h index 1064fc7192..bad933f76e 100644 --- a/src/Song.h +++ b/src/Song.h @@ -209,8 +209,6 @@ public: RString GetDisplayArtist() const; RString GetMainTitle() const; - Group* GetGroup() const; - /** * @brief Retrieve the transliterated title, or the main title if there is no translit. * @return the proper title. */ diff --git a/src/SongManager.cpp b/src/SongManager.cpp index 348a387bcb..278ccf4406 100644 --- a/src/SongManager.cpp +++ b/src/SongManager.cpp @@ -595,6 +595,7 @@ RString SongManager::GetSongGroupBackgroundPath( RString sSongGroup ) const return RString(); } */ + void SongManager::GetSongGroupNames( std::vector &AddTo ) const { AddTo.insert(AddTo.end(), m_sSongGroupNames.begin(), m_sSongGroupNames.end() ); @@ -851,6 +852,11 @@ std::vector SongManager::GetPreferredSortSongsBySectionName( const RStrin return AddTo; } +Group* SongManager::GetGroup( const Song* pSong ) const +{ + return GetGroupFromName( pSong->m_sGroupName ); +} + Group* SongManager::GetGroupFromName( const RString& sGroupName ) const { auto iter = m_mapGroupsByName.find( sGroupName ); @@ -2236,6 +2242,17 @@ public: return 1; } + static int GetGroup( T* p, lua_State *L ) + { + Song *pSong = Luna::check(L,1); + Group *pGroup = p->GetGroup(pSong); + if( pGroup != nullptr ) + pGroup->PushSelf(L); + else + lua_pushnil(L); + return 1; + } + static int GetSongsInGroup( T* p, lua_State *L ) { std::vector v = p->GetSongs(SArg(1)); @@ -2321,6 +2338,7 @@ public: ADD_METHOD( GetCourseColor ); ADD_METHOD( GetSongRank ); ADD_METHOD( GetSongGroupNames ); + ADD_METHOD( GetGroup ); ADD_METHOD( GetSongsInGroup ); ADD_METHOD( GetCoursesInGroup ); ADD_METHOD( ShortenGroupName ); diff --git a/src/SongManager.h b/src/SongManager.h index 4351ebdf4c..775a74b884 100644 --- a/src/SongManager.h +++ b/src/SongManager.h @@ -150,6 +150,7 @@ public: std::map GetGroupGroupMap() const { return m_mapGroupsByName;}; std::map> GetSeriesGroupMap() const { return m_mapSeries;}; Group* GetGroupFromName( const RString &sGroupName ) const; + Group* GetGroup( const Song *pSong ) const; std::vector GetPreferredSortSectionNames() const; std::vector GetPreferredSortSongsBySectionName( const RString &sSectionName ) const; void GetPreferredSortSongsBySectionName( const RString &sSectionName, std::vector &AddTo ) const; diff --git a/src/SongUtil.cpp b/src/SongUtil.cpp index 9050e626dd..22fc5a1c9f 100644 --- a/src/SongUtil.cpp +++ b/src/SongUtil.cpp @@ -596,12 +596,12 @@ void SongUtil::SortSongPointerArrayByGenre( std::vector &vpSongsInOut ) int SongUtil::CompareSongPointersByGroup(const Song *pSong1, const Song *pSong2) { // Check if the sort title exists - if( pSong1->GetGroup()->GetSortTitle().empty() || pSong2->GetGroup()->GetSortTitle().empty() ) { + 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 pSong1->GetGroup()->GetSortTitle() < pSong2->GetGroup()->GetSortTitle(); + return SONGMAN->GetGroup(pSong1)->GetSortTitle() < SONGMAN->GetGroup(pSong2)->GetSortTitle(); } } @@ -609,8 +609,8 @@ static int CompareSongPointersByGroupAndTitle( const Song *pSong1, const Song *p { // Check if the sort title exists - const RString &sGroup1 = pSong1->GetGroup()->GetSortTitle(); - const RString &sGroup2 = pSong2->GetGroup()->GetSortTitle(); + const RString &sGroup1 = SONGMAN->GetGroup(pSong1)->GetSortTitle(); + const RString &sGroup2 = SONGMAN->GetGroup(pSong2)->GetSortTitle(); if( sGroup1 < sGroup2 ) return true; @@ -655,7 +655,7 @@ RString SongUtil::GetSectionNameFromSongAndSort( const Song* pSong, SortOrder so return SONGMAN->SongToPreferredSortSectionName( pSong ); case SORT_GROUP: // guaranteed not empty - return pSong->GetGroup()->GetSortTitle(); + return SONGMAN->GetGroup(pSong)->GetSortTitle(); case SORT_TITLE: case SORT_ARTIST: {