run profile's CustomLoadFunction when changing theme or assigning a local profile to a player
This should make the custom load functions a lot more useful.
This commit is contained in:
+24
-19
@@ -789,6 +789,29 @@ void Profile::IncrementCategoryPlayCount( StepsType st, RankingCategory rc )
|
|||||||
if( X==NULL ) LOG->Warn("Failed to read section " #X); \
|
if( X==NULL ) LOG->Warn("Failed to read section " #X); \
|
||||||
else Load##X##FromNode(X); }
|
else Load##X##FromNode(X); }
|
||||||
|
|
||||||
|
void Profile::LoadCustomFunction( RString sDir )
|
||||||
|
{
|
||||||
|
/* Get the theme's custom load function:
|
||||||
|
* [Profile]
|
||||||
|
* CustomLoadFunction=function(profile, profileDir) ... end
|
||||||
|
*/
|
||||||
|
Lua *L = LUA->Get();
|
||||||
|
LuaReference customLoadFunc = THEME->GetMetricR("Profile", "CustomLoadFunction");
|
||||||
|
customLoadFunc.PushSelf(L);
|
||||||
|
ASSERT_M(!lua_isnil(L, -1), "CustomLoadFunction not defined");
|
||||||
|
|
||||||
|
// Pass profile and profile directory as arguments
|
||||||
|
this->PushSelf(L);
|
||||||
|
LuaHelpers::Push(L, sDir);
|
||||||
|
|
||||||
|
// Run it
|
||||||
|
RString sError;
|
||||||
|
if (!LuaHelpers::RunScriptOnStack(L, sError, 2, 0))
|
||||||
|
LOG->Warn("Error running CustomLoadFunction: %s", sError.c_str());
|
||||||
|
|
||||||
|
LUA->Release(L);
|
||||||
|
}
|
||||||
|
|
||||||
ProfileLoadResult Profile::LoadAllFromDir( RString sDir, bool bRequireSignature )
|
ProfileLoadResult Profile::LoadAllFromDir( RString sDir, bool bRequireSignature )
|
||||||
{
|
{
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
@@ -881,25 +904,7 @@ ProfileLoadResult Profile::LoadAllFromDir( RString sDir, bool bRequireSignature
|
|||||||
if (ret != ProfileLoadResult_Success)
|
if (ret != ProfileLoadResult_Success)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Get the theme's custom load function:
|
LoadCustomFunction( sDir );
|
||||||
* [Profile]
|
|
||||||
* CustomLoadFunction=function(profile, profileDir) ... end
|
|
||||||
*/
|
|
||||||
Lua *L = LUA->Get();
|
|
||||||
LuaReference customLoadFunc = THEME->GetMetricR("Profile", "CustomLoadFunction");
|
|
||||||
customLoadFunc.PushSelf(L);
|
|
||||||
ASSERT_M(!lua_isnil(L, -1), "CustomLoadFunction not defined");
|
|
||||||
|
|
||||||
// Pass profile and profile directory as arguments
|
|
||||||
this->PushSelf(L);
|
|
||||||
LuaHelpers::Push(L, sDir);
|
|
||||||
|
|
||||||
// Run it
|
|
||||||
RString sError;
|
|
||||||
if (!LuaHelpers::RunScriptOnStack(L, sError, 2, 0))
|
|
||||||
LOG->Warn("Error running CustomLoadFunction: %s", sError.c_str());
|
|
||||||
|
|
||||||
LUA->Release(L);
|
|
||||||
|
|
||||||
return ProfileLoadResult_Success;
|
return ProfileLoadResult_Success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -349,6 +349,7 @@ public:
|
|||||||
|
|
||||||
// Loading and saving
|
// Loading and saving
|
||||||
ProfileLoadResult LoadAllFromDir( RString sDir, bool bRequireSignature );
|
ProfileLoadResult LoadAllFromDir( RString sDir, bool bRequireSignature );
|
||||||
|
void LoadCustomFunction( RString sDir );
|
||||||
bool SaveAllToDir( RString sDir, bool bSignData ) const;
|
bool SaveAllToDir( RString sDir, bool bSignData ) const;
|
||||||
|
|
||||||
ProfileLoadResult LoadEditableDataFromDir( RString sDir );
|
ProfileLoadResult LoadEditableDataFromDir( RString sDir );
|
||||||
|
|||||||
@@ -201,6 +201,8 @@ bool ProfileManager::LoadLocalProfileFromMachine( PlayerNumber pn )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetProfile(pn)->LoadCustomFunction( m_sProfileDir[pn] );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
#include "RageFile.h"
|
#include "RageFile.h"
|
||||||
#if !defined(SMPACKAGE)
|
#if !defined(SMPACKAGE)
|
||||||
#include "ScreenManager.h"
|
#include "ScreenManager.h"
|
||||||
|
#include "ProfileManager.h"
|
||||||
|
#include "Profile.h"
|
||||||
#include "ActorUtil.h"
|
#include "ActorUtil.h"
|
||||||
#endif
|
#endif
|
||||||
#include "Foreach.h"
|
#include "Foreach.h"
|
||||||
@@ -415,12 +417,20 @@ void ThemeManager::SwitchThemeAndLanguage( const RString &sThemeName_, const RSt
|
|||||||
// reload common sounds
|
// reload common sounds
|
||||||
if( SCREENMAN != NULL )
|
if( SCREENMAN != NULL )
|
||||||
SCREENMAN->ThemeChanged();
|
SCREENMAN->ThemeChanged();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Lua globals can use metrics which are cached, and vice versa. Update Lua
|
/* Lua globals can use metrics which are cached, and vice versa. Update Lua
|
||||||
* globals first; it's Lua's job to explicitly update cached metrics that it
|
* globals first; it's Lua's job to explicitly update cached metrics that it
|
||||||
* uses. */
|
* uses. */
|
||||||
UpdateLuaGlobals();
|
UpdateLuaGlobals();
|
||||||
|
|
||||||
|
// Reload MachineProfile with new theme's CustomLoadFunction
|
||||||
|
if( PROFILEMAN != NULL )
|
||||||
|
{
|
||||||
|
Profile* pProfile = PROFILEMAN->GetMachineProfile();
|
||||||
|
pProfile->LoadCustomFunction( "/Save/MachineProfile/" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use theme metrics for localization.
|
// Use theme metrics for localization.
|
||||||
|
|||||||
Reference in New Issue
Block a user