Add Group() for USB songs
This commit is contained in:
+13
-5
@@ -41,11 +41,19 @@ Group::~Group()
|
||||
|
||||
}
|
||||
|
||||
Group::Group(const RString& sDir, const RString& sGroupDirName) {
|
||||
RString sPackIniPath = sDir + sGroupDirName + "/" + INI_FILE;
|
||||
m_sPath = sDir + sGroupDirName;
|
||||
m_sGroupName = Basename(sGroupDirName);
|
||||
m_sDisplayTitle = m_sGroupName;
|
||||
Group::Group(const RString& sDir, const RString& sGroupDirName, bool bFromProfile) {
|
||||
RString sPackIniPath;
|
||||
if (bFromProfile) {
|
||||
sPackIniPath = sDir + "/" + INI_FILE;
|
||||
m_sPath = sDir;
|
||||
m_sGroupName = sDir.substr(1, sDir.find('/', 1) - 1);
|
||||
m_sDisplayTitle = sGroupDirName;
|
||||
} else {
|
||||
sPackIniPath = sDir + sGroupDirName + "/" + INI_FILE;
|
||||
m_sPath = sDir + sGroupDirName;
|
||||
m_sGroupName = Basename(sGroupDirName);
|
||||
m_sDisplayTitle = m_sGroupName;
|
||||
}
|
||||
m_sSortTitle = m_sGroupName;
|
||||
m_sTranslitTitle = m_sGroupName;
|
||||
m_sSeries = "";
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ class Group
|
||||
{
|
||||
public:
|
||||
Group();
|
||||
Group( const RString& sDir, const RString& sGroupDirName);
|
||||
Group( const RString& sDir, const RString& sGroupDirName, bool bFromProfile = false);
|
||||
~Group();
|
||||
// Lua
|
||||
void PushSelf( lua_State *L );
|
||||
|
||||
+16
-1
@@ -6,6 +6,7 @@
|
||||
#include "IniFile.h"
|
||||
#include "GameManager.h"
|
||||
#include "GameState.h"
|
||||
#include "Group.h"
|
||||
#include "RageLog.h"
|
||||
#include "Song.h"
|
||||
#include "SongManager.h"
|
||||
@@ -96,6 +97,11 @@ void Profile::ClearSongs()
|
||||
delete curr_song;
|
||||
}
|
||||
m_songs.clear();
|
||||
|
||||
if (m_group != nullptr)
|
||||
{
|
||||
delete m_group;
|
||||
}
|
||||
}
|
||||
|
||||
int Profile::HighScoresForASong::GetNumTimesPlayed() const
|
||||
@@ -1181,7 +1187,7 @@ ProfileLoadResult Profile::LoadAllFromDir( RString sDir, bool bRequireSignature
|
||||
// entire song list to remove custom songs when unloading the profile is
|
||||
// wasteful. -Kyz
|
||||
|
||||
void Profile::LoadSongsFromDir(RString const& dir, ProfileSlot prof_slot)
|
||||
void Profile::LoadSongsFromDir(RString const& dir, ProfileSlot prof_slot, bool isMemoryCard)
|
||||
{
|
||||
if(!PREFSMAN->m_custom_songs_enable)
|
||||
{
|
||||
@@ -1198,6 +1204,10 @@ void Profile::LoadSongsFromDir(RString const& dir, ProfileSlot prof_slot)
|
||||
|
||||
StripCvsAndSvn(song_folders);
|
||||
StripMacResourceForks(song_folders);
|
||||
|
||||
Group* group = new Group(songs_folder, GetDisplayNameOrHighScoreName(), true);
|
||||
m_group = group;
|
||||
|
||||
LOG->Trace("Found %i songs in profile.", int(song_folders.size()));
|
||||
// Only songs that are successfully loaded count towards the limit. -Kyz
|
||||
for(size_t song_index= 0; song_index < song_folders.size()
|
||||
@@ -1224,6 +1234,11 @@ void Profile::LoadSongsFromDir(RString const& dir, ProfileSlot prof_slot)
|
||||
}
|
||||
float load_time= song_load_start_time.Ago();
|
||||
LOG->Trace("Successfully loaded %zu songs in %.6f from profile.", m_songs.size(), load_time);
|
||||
|
||||
if (m_songs.size() <= 0) {
|
||||
delete m_group;
|
||||
m_group = nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+3
-1
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "GameConstantsAndTypes.h"
|
||||
#include "Grade.h"
|
||||
#include "Group.h"
|
||||
#include "HighScore.h"
|
||||
#include "DateTime.h"
|
||||
#include "SongUtil.h" // for SongID
|
||||
@@ -205,6 +206,7 @@ public:
|
||||
std::map<RString,RString> m_sDefaultModifiers;
|
||||
SortOrder m_SortOrder;
|
||||
std::vector<Song*> m_songs;
|
||||
Group* m_group;
|
||||
Difficulty m_LastDifficulty;
|
||||
CourseDifficulty m_LastCourseDifficulty;
|
||||
StepsType m_LastStepsType;
|
||||
@@ -403,7 +405,7 @@ public:
|
||||
void HandleStatsPrefixChange(RString dir, bool require_signature);
|
||||
ProfileLoadResult LoadAllFromDir( RString sDir, bool bRequireSignature );
|
||||
ProfileLoadResult LoadStatsFromDir(RString dir, bool require_signature);
|
||||
void LoadSongsFromDir(RString const& dir, ProfileSlot prof_slot);
|
||||
void LoadSongsFromDir(RString const& dir, ProfileSlot prof_slot, bool isMemoryCard = true);
|
||||
void LoadTypeFromDir(RString dir);
|
||||
void LoadCustomFunction(RString sDir, PlayerNumber pn);
|
||||
bool SaveAllToDir( RString sDir, bool bSignData ) const;
|
||||
|
||||
+1
-1
@@ -311,7 +311,7 @@ bool Song::LoadFromSongDir(RString sDir, bool load_autosave, ProfileSlot from_pr
|
||||
else
|
||||
{
|
||||
m_LoadedFromProfile= from_profile;
|
||||
m_sGroupName= PROFILEMAN->GetProfile(from_profile)->m_sDisplayName;
|
||||
m_sGroupName= sDir.substr(1, sDir.find('/', 1) - 1);
|
||||
use_cache= false;
|
||||
}
|
||||
|
||||
|
||||
+21
-9
@@ -271,6 +271,13 @@ void SongManager::SanityCheckGroupDir( RString sDir ) const
|
||||
|
||||
void SongManager::AddGroup( RString sDir, RString sGroupDirName, Group* group )
|
||||
{
|
||||
|
||||
if ( group == nullptr ) {
|
||||
// Could not AddGroup 'sGroupDirName'. Group object is null.
|
||||
LOG->Warn( "Could not AddGroup '%s'. Group object is null.", sGroupDirName.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned j;
|
||||
for(j = 0; j < m_sSongGroupNames.size(); ++j)
|
||||
if( sGroupDirName == m_sSongGroupNames[j] )
|
||||
@@ -279,12 +286,6 @@ void SongManager::AddGroup( RString sDir, RString sGroupDirName, Group* group )
|
||||
if( j != m_sSongGroupNames.size() )
|
||||
return; // the group is already added
|
||||
|
||||
if ( group == nullptr ) {
|
||||
// Could not AddGroup 'sGroupDirName'. Group object is null.
|
||||
LOG->Warn( "Could not AddGroup '%s'. Group object is null.", sGroupDirName.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
RString sBannerPath;
|
||||
|
||||
// Look for a group banner in this group folder
|
||||
@@ -346,7 +347,7 @@ void SongManager::AddGroup( RString sDir, RString sGroupDirName, Group* group )
|
||||
*/
|
||||
m_sSongGroupBannerPaths.push_back( sBannerPath );
|
||||
m_sSongGroupNames.push_back( sGroupDirName );
|
||||
|
||||
|
||||
// Add the group to its series if the group has one and if the series exists
|
||||
if( group->GetSeries() != "" )
|
||||
{
|
||||
@@ -706,7 +707,7 @@ RageColor SongManager::GetSongGroupColor( const RString &sSongGroup ) const
|
||||
Profile* prof= PROFILEMAN->GetProfile(pn);
|
||||
if(prof != nullptr)
|
||||
{
|
||||
if(prof->GetDisplayNameOrHighScoreName() == sSongGroup)
|
||||
if(prof->m_group->GetGroupName() == sSongGroup)
|
||||
{
|
||||
return profile_song_group_colors.GetValue(pn % num_profile_song_group_colors);
|
||||
}
|
||||
@@ -880,7 +881,7 @@ const std::vector<Song*> &SongManager::GetSongs( const RString &sGroupName ) con
|
||||
Profile* prof= PROFILEMAN->GetProfile(pn);
|
||||
if(prof != nullptr)
|
||||
{
|
||||
if(prof->GetDisplayNameOrHighScoreName() == sGroupName)
|
||||
if(prof->m_group->GetGroupName() == sGroupName)
|
||||
{
|
||||
return prof->m_songs;
|
||||
}
|
||||
@@ -938,6 +939,17 @@ Group* SongManager::GetGroupFromName( const RString& sGroupName ) const
|
||||
auto iter = m_mapNameToGroup.find( sGroupName );
|
||||
if( iter != m_mapNameToGroup.end() )
|
||||
return iter->second;
|
||||
FOREACH_EnabledPlayer(pn)
|
||||
{
|
||||
Profile* prof= PROFILEMAN->GetProfile(pn);
|
||||
if(prof != nullptr)
|
||||
{
|
||||
if(prof->m_group->GetGroupName() == sGroupName)
|
||||
{
|
||||
return prof->m_group;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user