Allow PreferredSongs/PreferredCourses to be set from absolute paths
This commit is contained in:
@@ -5888,11 +5888,15 @@ local args = {
|
||||
<Function name='ShortenGroupName' return='string' arguments='string sGroupName'>
|
||||
Returns the shortened group name (based on entries in Translations.xml).
|
||||
</Function>
|
||||
<Function name='SetPreferredCourses' return='void' arguments='string sListName'>
|
||||
Loads preferred courses from <code>{theme}/Other/SongManager sListName.txt</code>.
|
||||
<Function name='SetPreferredCourses' return='void' arguments='string sListName, bool bIsAbsolute'>
|
||||
By default, loads preferred courses from <code>{theme}/Other/SongManager sListName.txt</code>.
|
||||
(New since ITGmania 0.5.2) If the optional argument <code>bIsAbsolute</code> is set, instead treats
|
||||
sListName as an absolute path instead of loading it from the Theme's <code>Other</code> directory.
|
||||
</Function>
|
||||
<Function name='SetPreferredSongs' return='void' arguments='string sListName'>
|
||||
Loads preferred songs from <code>{theme}/Other/SongManager sListName.txt</code>.
|
||||
<Function name='SetPreferredSongs' return='void' arguments='string sListName, bool bIsAbsolute'>
|
||||
By default, loads preferred songs from <code>{theme}/Other/SongManager sListName.txt</code>.
|
||||
(New since ITGmania 0.5.2) If the optional argument <code>bIsAbsolute</code> is set, instead treats
|
||||
sListName as an absolute path instead of loading it from the Theme's <code>Other</code> directory.
|
||||
</Function>
|
||||
<Function name='SongToPreferredSortSectionName' return='string' arguments='Song s'>
|
||||
Returns the preferred sort section name for the specified Song.
|
||||
|
||||
+38
-8
@@ -1593,15 +1593,15 @@ void SongManager::UpdateShuffled()
|
||||
std::shuffle( m_pShuffledCourses.begin(), m_pShuffledCourses.end(), g_RandomNumberGenerator );
|
||||
}
|
||||
|
||||
void SongManager::UpdatePreferredSort(RString sPreferredSongs, RString sPreferredCourses)
|
||||
{
|
||||
void SongManager::SetPreferredSongs(RString sPreferredSongs, bool bIsAbsolute) {
|
||||
ASSERT( UNLOCKMAN != nullptr );
|
||||
|
||||
{
|
||||
m_vPreferredSongSort.clear();
|
||||
|
||||
std::vector<RString> asLines;
|
||||
RString sFile = THEME->GetPathO( "SongManager", sPreferredSongs );
|
||||
RString sFile = sPreferredSongs;
|
||||
if (!bIsAbsolute)
|
||||
sFile = THEME->GetPathO( "SongManager", sPreferredSongs );
|
||||
GetFileContents( sFile, asLines );
|
||||
if( asLines.empty() )
|
||||
return;
|
||||
@@ -1695,17 +1695,24 @@ void SongManager::UpdatePreferredSort(RString sPreferredSongs, RString sPreferre
|
||||
m_vPreferredSongSort.erase( m_vPreferredSongSort.begin()+i );
|
||||
|
||||
for (PreferredSortSection const &i : m_vPreferredSongSort)
|
||||
{
|
||||
for (Song const *j : i.vpSongs)
|
||||
{
|
||||
ASSERT( j != nullptr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SongManager::SetPreferredCourses(RString sPreferredCourses, bool bIsAbsolute)
|
||||
{
|
||||
ASSERT( UNLOCKMAN != nullptr );
|
||||
|
||||
m_vPreferredCourseSort.clear();
|
||||
|
||||
std::vector<RString> asLines;
|
||||
RString sFile = THEME->GetPathO( "SongManager", sPreferredCourses );
|
||||
RString sFile = sPreferredCourses;
|
||||
if (!bIsAbsolute)
|
||||
sFile = THEME->GetPathO( "SongManager", sPreferredCourses );
|
||||
if( !GetFileContents(sFile, asLines) )
|
||||
return;
|
||||
|
||||
@@ -1770,6 +1777,7 @@ void SongManager::UpdatePreferredSort(RString sPreferredSongs, RString sPreferre
|
||||
m_vPreferredCourseSort.erase( m_vPreferredCourseSort.begin()+i );
|
||||
|
||||
for (CoursePointerVector const &i : m_vPreferredCourseSort)
|
||||
{
|
||||
for (Course *j : i)
|
||||
{
|
||||
ASSERT( j != nullptr );
|
||||
@@ -1777,6 +1785,12 @@ void SongManager::UpdatePreferredSort(RString sPreferredSongs, RString sPreferre
|
||||
}
|
||||
}
|
||||
|
||||
void SongManager::UpdatePreferredSort(RString sPreferredSongs, RString sPreferredCourses)
|
||||
{
|
||||
SetPreferredSongs(sPreferredSongs);
|
||||
SetPreferredCourses(sPreferredCourses);
|
||||
}
|
||||
|
||||
void SongManager::SortSongs()
|
||||
{
|
||||
SongUtil::SortSongPointerArrayByTitle( m_pSongs );
|
||||
@@ -2026,13 +2040,29 @@ class LunaSongManager: public Luna<SongManager>
|
||||
public:
|
||||
static int SetPreferredSongs( T* p, lua_State *L )
|
||||
{
|
||||
p->UpdatePreferredSort( SArg(1), "PreferredCourses.txt" );
|
||||
COMMON_RETURN_SELF;
|
||||
RString sPreferredSongs = SArg(1);
|
||||
if ( lua_gettop(L) >= 2 && !lua_isnil(L, 2) )
|
||||
{
|
||||
p->SetPreferredSongs( sPreferredSongs, BArg(2) );
|
||||
}
|
||||
else
|
||||
{
|
||||
p->SetPreferredSongs( sPreferredSongs );
|
||||
}
|
||||
|
||||
COMMON_RETURN_SELF;
|
||||
}
|
||||
static int SetPreferredCourses( T* p, lua_State *L )
|
||||
{
|
||||
p->UpdatePreferredSort( "PreferredSongs.txt", SArg(1) );
|
||||
RString sPreferredCourses = SArg(1);
|
||||
if ( lua_gettop(L) >= 2 && !lua_isnil(L, 2) )
|
||||
{
|
||||
p->SetPreferredSongs( sPreferredCourses, BArg(2) );
|
||||
}
|
||||
else
|
||||
{
|
||||
p->SetPreferredSongs( sPreferredCourses );
|
||||
}
|
||||
COMMON_RETURN_SELF;
|
||||
}
|
||||
static int GetAllSongs( T* p, lua_State *L )
|
||||
|
||||
@@ -179,6 +179,8 @@ public:
|
||||
|
||||
void UpdatePopular();
|
||||
void UpdateShuffled(); // re-shuffle songs and courses
|
||||
void SetPreferredSongs(RString sPreferredSongs = "PreferredSongs.txt", bool bIsAbsolute = false);
|
||||
void SetPreferredCourses(RString sPreferredCourses = "PreferredCourses.txt", bool bIsAbsolute = false);
|
||||
void UpdatePreferredSort(RString sPreferredSongs = "PreferredSongs.txt", RString sPreferredCourses = "PreferredCourses.txt");
|
||||
void SortSongs(); // sort m_pSongs by CompareSongPointersByTitle
|
||||
|
||||
|
||||
Reference in New Issue
Block a user