Changeset View
Changeset View
Standalone View
Standalone View
source/ps/scripting/JSInterface_Game.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | void JSI_Game::StartGame(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleValue attribs, int playerID) | ||||
ENSURE(!g_NetServer); | ENSURE(!g_NetServer); | ||||
ENSURE(!g_NetClient); | ENSURE(!g_NetClient); | ||||
ENSURE(!g_Game); | ENSURE(!g_Game); | ||||
g_Game = new CGame(true); | g_Game = new CGame(true); | ||||
// Convert from GUI script context to sim script context | // Convert from GUI script context to sim script context | ||||
CSimulation2* sim = g_Game->GetSimulation2(); | CSimulation2* sim = g_Game->GetSimulation2(); | ||||
ScriptInterface::Request rqSim(sim->GetScriptInterface()); | ScriptRequest rqSim(sim->GetScriptInterface()); | ||||
JS::RootedValue gameAttribs(rqSim.cx, | JS::RootedValue gameAttribs(rqSim.cx, | ||||
sim->GetScriptInterface().CloneValueFromOtherCompartment(*(pCmptPrivate->pScriptInterface), attribs)); | sim->GetScriptInterface().CloneValueFromOtherCompartment(*(pCmptPrivate->pScriptInterface), attribs)); | ||||
g_Game->SetPlayerID(playerID); | g_Game->SetPlayerID(playerID); | ||||
g_Game->StartGame(&gameAttribs, ""); | g_Game->StartGame(&gameAttribs, ""); | ||||
} | } | ||||
Show All 35 Lines | |||||
{ | { | ||||
g_Game->SetSimRate(rate); | g_Game->SetSimRate(rate); | ||||
} | } | ||||
bool JSI_Game::IsPaused(ScriptInterface::CmptPrivate* pCmptPrivate) | bool JSI_Game::IsPaused(ScriptInterface::CmptPrivate* pCmptPrivate) | ||||
{ | { | ||||
if (!g_Game) | if (!g_Game) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCmptPrivate); | ScriptRequest rq(pCmptPrivate->pScriptInterface); | ||||
JS_ReportError(rq.cx, "Game is not started"); | ScriptException::Raise(rq, "Game is not started"); | ||||
return false; | return false; | ||||
} | } | ||||
return g_Game->m_Paused; | return g_Game->m_Paused; | ||||
} | } | ||||
void JSI_Game::SetPaused(ScriptInterface::CmptPrivate* pCmptPrivate, bool pause, bool sendMessage) | void JSI_Game::SetPaused(ScriptInterface::CmptPrivate* pCmptPrivate, bool pause, bool sendMessage) | ||||
{ | { | ||||
if (!g_Game) | if (!g_Game) | ||||
{ | { | ||||
ScriptInterface::Request rq(pCmptPrivate); | ScriptRequest rq(pCmptPrivate->pScriptInterface); | ||||
JS_ReportError(rq.cx, "Game is not started"); | ScriptException::Raise(rq, "Game is not started"); | ||||
return; | return; | ||||
} | } | ||||
g_Game->m_Paused = pause; | g_Game->m_Paused = pause; | ||||
#if CONFIG2_AUDIO | #if CONFIG2_AUDIO | ||||
if (g_SoundManager) | if (g_SoundManager) | ||||
g_SoundManager->Pause(pause); | g_SoundManager->Pause(pause); | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator