Changeset View
Changeset View
Standalone View
Standalone View
source/ps/scripting/JSInterface_SavedGame.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
JS::Value JSI_SavedGame::StartSavedGame(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& name) | JS::Value JSI_SavedGame::StartSavedGame(ScriptInterface::CmptPrivate* pCmptPrivate, const std::wstring& name) | ||||
{ | { | ||||
// We need to be careful with different compartments and contexts. | // We need to be careful with different compartments and contexts. | ||||
// The GUI calls this function from the GUI context and expects the return value in the same context. | // The GUI calls this function from the GUI context and expects the return value in the same context. | ||||
// The game we start from here creates another context and expects data in this context. | // The game we start from here creates another context and expects data in this context. | ||||
ScriptInterface::Request rqGui(pCmptPrivate); | ScriptRequest rqGui(pCmptPrivate->pScriptInterface); | ||||
ENSURE(!g_NetServer); | ENSURE(!g_NetServer); | ||||
ENSURE(!g_NetClient); | ENSURE(!g_NetClient); | ||||
ENSURE(!g_Game); | ENSURE(!g_Game); | ||||
// Load the saved game data from disk | // Load the saved game data from disk | ||||
JS::RootedValue guiContextMetadata(rqGui.cx); | JS::RootedValue guiContextMetadata(rqGui.cx); | ||||
std::string savedState; | std::string savedState; | ||||
Status err = SavedGames::Load(name, *(pCmptPrivate->pScriptInterface), &guiContextMetadata, savedState); | Status err = SavedGames::Load(name, *(pCmptPrivate->pScriptInterface), &guiContextMetadata, savedState); | ||||
if (err < 0) | if (err < 0) | ||||
return JS::UndefinedValue(); | return JS::UndefinedValue(); | ||||
g_Game = new CGame(true); | g_Game = new CGame(true); | ||||
{ | { | ||||
CSimulation2* sim = g_Game->GetSimulation2(); | CSimulation2* sim = g_Game->GetSimulation2(); | ||||
ScriptInterface::Request rqGame(sim->GetScriptInterface()); | ScriptRequest rqGame(sim->GetScriptInterface()); | ||||
JS::RootedValue gameContextMetadata(rqGame.cx, | JS::RootedValue gameContextMetadata(rqGame.cx, | ||||
sim->GetScriptInterface().CloneValueFromOtherCompartment(*(pCmptPrivate->pScriptInterface), guiContextMetadata)); | sim->GetScriptInterface().CloneValueFromOtherCompartment(*(pCmptPrivate->pScriptInterface), guiContextMetadata)); | ||||
JS::RootedValue gameInitAttributes(rqGame.cx); | JS::RootedValue gameInitAttributes(rqGame.cx); | ||||
sim->GetScriptInterface().GetProperty(gameContextMetadata, "initAttributes", &gameInitAttributes); | sim->GetScriptInterface().GetProperty(gameContextMetadata, "initAttributes", &gameInitAttributes); | ||||
int playerID; | int playerID; | ||||
sim->GetScriptInterface().GetProperty(gameContextMetadata, "playerID", playerID); | sim->GetScriptInterface().GetProperty(gameContextMetadata, "playerID", playerID); | ||||
Show All 18 Lines |
Wildfire Games · Phabricator