Move GetGroup to SONGMAN, rename variables consistently, move "pack.ini" to constant var, flip sync bias sign

This commit is contained in:
Crash Cringle
2025-03-03 23:25:32 -08:00
committed by teejusb
parent ea588c8504
commit ac767b3ce8
7 changed files with 57 additions and 43 deletions
+29 -21
View File
@@ -14,6 +14,14 @@
#include <tuple>
#include <vector>
/** @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<RString> 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;
+2 -2
View File
@@ -755,7 +755,7 @@ void MusicWheel::BuildWheelItemDatas( std::vector<MusicWheelItemData *> &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<MusicWheelItemData *> &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;
}
+2 -13
View File
@@ -277,10 +277,6 @@ const RString &Song::GetSongFilePath() const
* <set> into Song.h, which is heavily used. */
static std::set<RString> 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 );
-2
View File
@@ -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. */
+18
View File
@@ -595,6 +595,7 @@ RString SongManager::GetSongGroupBackgroundPath( RString sSongGroup ) const
return RString();
}
*/
void SongManager::GetSongGroupNames( std::vector<RString> &AddTo ) const
{
AddTo.insert(AddTo.end(), m_sSongGroupNames.begin(), m_sSongGroupNames.end() );
@@ -851,6 +852,11 @@ std::vector<Song*> 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<Song>::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<Song*> 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 );
+1
View File
@@ -150,6 +150,7 @@ public:
std::map<RString, Group*> GetGroupGroupMap() const { return m_mapGroupsByName;};
std::map<RString, std::vector<Group*>> GetSeriesGroupMap() const { return m_mapSeries;};
Group* GetGroupFromName( const RString &sGroupName ) const;
Group* GetGroup( const Song *pSong ) const;
std::vector<RString> GetPreferredSortSectionNames() const;
std::vector<Song*> GetPreferredSortSongsBySectionName( const RString &sSectionName ) const;
void GetPreferredSortSongsBySectionName( const RString &sSectionName, std::vector<Song*> &AddTo ) const;
+5 -5
View File
@@ -596,12 +596,12 @@ void SongUtil::SortSongPointerArrayByGenre( std::vector<Song*> &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:
{