Profile: add custom load/save hooks
Themes can use these to implement custom per-profile data, such as SpeedMods.txt. For memory cards, they will be executed while the card is mounted and should read/write everything they will need at that point.
This commit is contained in:
@@ -1183,6 +1183,8 @@ JudgmentTransformCommand=%JudgmentTransformSharedCommand
|
||||
[Profile]
|
||||
ShowCoinData=true
|
||||
UnlockAuthString=""
|
||||
CustomLoadFunction=function(profile, dir) end
|
||||
CustomSaveFunction=function(profile, dir) end
|
||||
|
||||
[RadarValues]
|
||||
WriteComplexValues=true
|
||||
|
||||
+45
-1
@@ -876,7 +876,31 @@ ProfileLoadResult Profile::LoadAllFromDir( RString sDir, bool bRequireSignature
|
||||
return ProfileLoadResult_FailedTampered;
|
||||
LOG->Trace( "Done." );
|
||||
|
||||
return LoadStatsXmlFromNode( &xml );
|
||||
ProfileLoadResult ret = LoadStatsXmlFromNode(&xml);
|
||||
if (ret != ProfileLoadResult_Success)
|
||||
return ret;
|
||||
|
||||
/* 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);
|
||||
|
||||
return ProfileLoadResult_Success;
|
||||
}
|
||||
|
||||
ProfileLoadResult Profile::LoadStatsXmlFromNode( const XNode *xml, bool bIgnoreEditable )
|
||||
@@ -936,6 +960,26 @@ bool Profile::SaveAllToDir( RString sDir, bool bSignData ) const
|
||||
FILEMAN->CreateDir( sDir + SCREENSHOTS_SUBDIR );
|
||||
FILEMAN->CreateDir( sDir + RIVAL_SUBDIR );
|
||||
|
||||
/* Get the theme's custom save function:
|
||||
* [Profile]
|
||||
* CustomSaveFunction=function(profile, profileDir) ... end
|
||||
*/
|
||||
Lua *L = LUA->Get();
|
||||
LuaReference customSaveFunc = THEME->GetMetricR("Profile", "CustomSaveFunction");
|
||||
customSaveFunc.PushSelf(L);
|
||||
ASSERT_M(!lua_isnil(L, -1), "CustomSaveFunction not defined");
|
||||
|
||||
// Pass profile and profile directory as arguments
|
||||
const_cast<Profile *>(this)->PushSelf(L);
|
||||
LuaHelpers::Push(L, sDir);
|
||||
|
||||
// Run it
|
||||
RString sError;
|
||||
if (!LuaHelpers::RunScriptOnStack(L, sError, 2, 0))
|
||||
LOG->Warn("Error running CustomSaveFunction: %s", sError.c_str());
|
||||
|
||||
LUA->Release(L);
|
||||
|
||||
return bSaved;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user