From 35570a0880358b0fd5e3b1439ba3918f23479cb2 Mon Sep 17 00:00:00 2001 From: Crash Cringle <30600688+CrashCringle12@users.noreply.github.com> Date: Mon, 3 Mar 2025 16:24:21 -0500 Subject: [PATCH] Condense trim/check empty pack.ini logic to vector looping --- src/Group.cpp | 73 +++++++++++++++++++----------------------- src/MusicWheelItem.cpp | 4 +-- 2 files changed, 35 insertions(+), 42 deletions(-) diff --git a/src/Group.cpp b/src/Group.cpp index e3fa426395..1e27be312c 100644 --- a/src/Group.cpp +++ b/src/Group.cpp @@ -42,12 +42,16 @@ Group::~Group() { Group::Group(const RString& sDir, const RString& sGroupDirName) { RString sPackIniPath = sDir + sGroupDirName + "/" + INI_FILE; - RString sDisplayTitle = sGroupDirName; - RString sSortTitle = sGroupDirName; - RString sTranslitTitle = ""; - RString sSeries = ""; - RString sBannerPath = ""; - float fOffset = PREFSMAN->m_fMachineSyncBias; + m_sPath = sDir + sGroupDirName; + m_sGroupName = Basename(sGroupDirName); + m_sDisplayTitle = m_sGroupName; + m_sSortTitle = m_sGroupName; + m_sTranslitTitle = m_sGroupName; + m_sSeries = ""; + m_fSyncOffset = PREFSMAN->m_fMachineSyncBias; + m_bHasPackIni = false; + m_iYearReleased = 0; + m_sBannerPath = ""; m_iVersion = INI_VERSION; if (FILEMAN->DoesFileExist(sPackIniPath)) { @@ -63,39 +67,37 @@ Group::Group(const RString& sDir, const RString& sGroupDirName) { if (!sVersion.empty()) { m_bHasPackIni = true; m_iVersion = StringToInt(sVersion); - - ini.GetValue("Group", "DisplayTitle", sDisplayTitle); - Trim(sDisplayTitle); - if (sDisplayTitle.empty()) { - sDisplayTitle = Basename(sGroupDirName); - } - ini.GetValue("Group", "Banner", sBannerPath); - if (sBannerPath.empty()) { - m_sBannerPath = sBannerPath; - } - ini.GetValue("Group", "SortTitle", sSortTitle); - Trim(sSortTitle); - if (sSortTitle.empty()) { - sSortTitle = Basename(sGroupDirName); - } - - ini.GetValue("Group", "TranslitTitle", sTranslitTitle); - Trim(sTranslitTitle); - if (sTranslitTitle.empty()) { - sTranslitTitle = sDisplayTitle; - } - - ini.GetValue("Group", "Series", sSeries); + // Define a vector of key-value pairs to cleanly iterate + std::vector> vPackfields = { + {"DisplayTitle", m_sDisplayTitle}, + {"SortTitle", m_sSortTitle}, + {"TranslitTitle", m_sTranslitTitle}, + {"Series", m_sSeries}, + {"Banner", m_sBannerPath} + }; + for (auto& [key, value] : vPackfields) { + ini.GetValue("Group", key, value); + Trim(value); + + if (value.empty()) { + if (key == "DisplayTitle" || key == "SortTitle" ) { + value = m_sGroupName; + } else if (key == "TranslitTitle") { + value = m_sDisplayTitle; + } + } + } + RString sValue = ""; ini.GetValue("Group", "SyncOffset", sValue); Trim(sValue); if (!sValue.empty()) { if (sValue.CompareNoCase("null") == 0) { - fOffset = 0.0f; + m_fSyncOffset = 0.0f; } else if (sValue.CompareNoCase("itg") == 0) { - fOffset = -0.009f; + m_fSyncOffset = -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()); } @@ -106,15 +108,6 @@ Group::Group(const RString& sDir, const RString& sGroupDirName) { LOG->Warn("Group::Group: Pack.ini version not set. Using default values."); } } - - m_sDisplayTitle = sDisplayTitle; - m_sSortTitle = sSortTitle; - m_sTranslitTitle = sTranslitTitle; - m_sSeries = sSeries; - m_sPath = sDir + sGroupDirName; - m_sGroupName = sGroupDirName; - m_fSyncOffset = fOffset; - } const std::vector &Group::GetSongs() const diff --git a/src/MusicWheelItem.cpp b/src/MusicWheelItem.cpp index e7f9ee02e1..a01b9c0dc9 100644 --- a/src/MusicWheelItem.cpp +++ b/src/MusicWheelItem.cpp @@ -227,13 +227,13 @@ void MusicWheelItem::LoadFromWheelItemData( const WheelItemBaseData *pData, int } else { if ( pWID->m_pGroup->GetSeries().empty() ) { - sDisplayName = SONGMAN->ShortenGroupName(pWID->m_sText); + sDisplayName = SONGMAN->ShortenGroupName(pWID->m_pGroup->GetDisplayTitle()); sTranslitName = SONGMAN->ShortenGroupName(pWID->m_pGroup->GetTranslitTitle()); } else { // This will eventually do something different when we eventually implement nested folders // for now, use the same behavior. - sDisplayName = SONGMAN->ShortenGroupName(pWID->m_sText); + sDisplayName = SONGMAN->ShortenGroupName(pWID->m_pGroup->GetDisplayTitle()); sTranslitName = SONGMAN->ShortenGroupName(pWID->m_pGroup->GetTranslitTitle()); } }