Changeset View
Changeset View
Standalone View
Standalone View
source/gui/scripting/ScriptFunctions.cpp
Show All 33 Lines | |||||
#include "lib/sysdep/sysdep.h" | #include "lib/sysdep/sysdep.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
#include "lobby/scripting/JSInterface_Lobby.h" | #include "lobby/scripting/JSInterface_Lobby.h" | ||||
#include "maths/FixedVector3D.h" | #include "maths/FixedVector3D.h" | ||||
#include "network/NetClient.h" | #include "network/NetClient.h" | ||||
#include "network/NetServer.h" | #include "network/NetServer.h" | ||||
#include "network/NetTurnManager.h" | #include "network/NetTurnManager.h" | ||||
#include "ps/Campaigns.h" | |||||
#include "ps/CConsole.h" | #include "ps/CConsole.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Errors.h" | #include "ps/Errors.h" | ||||
#include "ps/GUID.h" | #include "ps/GUID.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/GameSetup/Atlas.h" | #include "ps/GameSetup/Atlas.h" | ||||
#include "ps/GameSetup/Config.h" | #include "ps/GameSetup/Config.h" | ||||
#include "ps/Globals.h" // g_frequencyFilter | #include "ps/Globals.h" // g_frequencyFilter | ||||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | if (g_Game) | ||||
g_Game->SetViewedPlayerID(id); | g_Game->SetViewedPlayerID(id); | ||||
} | } | ||||
JS::Value GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate) | JS::Value GetEngineInfo(ScriptInterface::CxPrivate* pCxPrivate) | ||||
{ | { | ||||
return SavedGames::GetEngineInfo(*(pCxPrivate->pScriptInterface)); | return SavedGames::GetEngineInfo(*(pCxPrivate->pScriptInterface)); | ||||
} | } | ||||
bool DeleteCampaignGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& name) | |||||
{ | |||||
return Campaigns::DeleteGame(name); | |||||
} | |||||
void StartNetworkGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | void StartNetworkGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | ||||
{ | { | ||||
ENSURE(g_NetClient); | ENSURE(g_NetClient); | ||||
g_NetClient->SendStartGameMessage(); | g_NetClient->SendStartGameMessage(); | ||||
} | } | ||||
void StartGame(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs, int playerID) | void StartGame(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs, int playerID) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
void SaveGamePrefix(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& prefix, const std::wstring& description, JS::HandleValue GUIMetadata) | void SaveGamePrefix(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& prefix, const std::wstring& description, JS::HandleValue GUIMetadata) | ||||
{ | { | ||||
shared_ptr<ScriptInterface::StructuredClone> GUIMetadataClone = pCxPrivate->pScriptInterface->WriteStructuredClone(GUIMetadata); | shared_ptr<ScriptInterface::StructuredClone> GUIMetadataClone = pCxPrivate->pScriptInterface->WriteStructuredClone(GUIMetadata); | ||||
if (SavedGames::SavePrefix(prefix, description, *g_Game->GetSimulation2(), GUIMetadataClone) < 0) | if (SavedGames::SavePrefix(prefix, description, *g_Game->GetSimulation2(), GUIMetadataClone) < 0) | ||||
LOGERROR("Failed to save game"); | LOGERROR("Failed to save game"); | ||||
} | } | ||||
JS::Value GetSavedGames(ScriptInterface::CxPrivate* pCxPrivate) | |||||
{ | |||||
return SavedGames::GetSavedGames(*(pCxPrivate->pScriptInterface)); | |||||
} | |||||
bool DeleteSavedGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& name) | |||||
{ | |||||
return SavedGames::DeleteSavedGame(name); | |||||
} | |||||
leper: Why is this being moved? | |||||
void SetNetworkGameAttributes(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1) | void SetNetworkGameAttributes(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1) | ||||
{ | { | ||||
ENSURE(g_NetClient); | ENSURE(g_NetClient); | ||||
//TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere | //TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere | ||||
// (with no obvious reason). | // (with no obvious reason). | ||||
JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); | JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | void SendNetworkReady(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int message) | ||||
g_NetClient->SendReadyMessage(message); | g_NetClient->SendReadyMessage(message); | ||||
} | } | ||||
JS::Value GetAIs(ScriptInterface::CxPrivate* pCxPrivate) | JS::Value GetAIs(ScriptInterface::CxPrivate* pCxPrivate) | ||||
{ | { | ||||
return ICmpAIManager::GetAIs(*(pCxPrivate->pScriptInterface)); | return ICmpAIManager::GetAIs(*(pCxPrivate->pScriptInterface)); | ||||
} | } | ||||
JS::Value GetSavedGames(ScriptInterface::CxPrivate* pCxPrivate) | |||||
{ | |||||
return SavedGames::GetSavedGames(*(pCxPrivate->pScriptInterface)); | |||||
} | |||||
bool DeleteSavedGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& name) | |||||
{ | |||||
return SavedGames::DeleteSavedGame(name); | |||||
} | |||||
void OpenURL(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& url) | void OpenURL(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& url) | ||||
{ | { | ||||
sys_open_url(url); | sys_open_url(url); | ||||
} | } | ||||
std::wstring GetMatchID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | std::wstring GetMatchID(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | ||||
{ | { | ||||
return ps_generate_guid().FromUTF8(); | return ps_generate_guid().FromUTF8(); | ||||
▲ Show 20 Lines • Show All 563 Lines • ▼ Show 20 Lines | void GuiScriptingInit(ScriptInterface& scriptInterface) | ||||
scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes"); | scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes"); | ||||
scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer"); | scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer"); | ||||
scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady"); | scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady"); | ||||
scriptInterface.RegisterFunction<void, std::wstring, &SendNetworkChat>("SendNetworkChat"); | scriptInterface.RegisterFunction<void, std::wstring, &SendNetworkChat>("SendNetworkChat"); | ||||
scriptInterface.RegisterFunction<void, int, &SendNetworkReady>("SendNetworkReady"); | scriptInterface.RegisterFunction<void, int, &SendNetworkReady>("SendNetworkReady"); | ||||
scriptInterface.RegisterFunction<JS::Value, &GetAIs>("GetAIs"); | scriptInterface.RegisterFunction<JS::Value, &GetAIs>("GetAIs"); | ||||
scriptInterface.RegisterFunction<JS::Value, &GetEngineInfo>("GetEngineInfo"); | scriptInterface.RegisterFunction<JS::Value, &GetEngineInfo>("GetEngineInfo"); | ||||
// Campaigns | |||||
scriptInterface.RegisterFunction<bool, std::wstring, &DeleteCampaignGame>("DeleteCampaignGame"); | |||||
// Saved games | // Saved games | ||||
scriptInterface.RegisterFunction<JS::Value, std::wstring, &StartSavedGame>("StartSavedGame"); | scriptInterface.RegisterFunction<JS::Value, std::wstring, &StartSavedGame>("StartSavedGame"); | ||||
scriptInterface.RegisterFunction<JS::Value, &GetSavedGames>("GetSavedGames"); | scriptInterface.RegisterFunction<JS::Value, &GetSavedGames>("GetSavedGames"); | ||||
scriptInterface.RegisterFunction<bool, std::wstring, &DeleteSavedGame>("DeleteSavedGame"); | scriptInterface.RegisterFunction<bool, std::wstring, &DeleteSavedGame>("DeleteSavedGame"); | ||||
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, JS::HandleValue, &SaveGame>("SaveGame"); | scriptInterface.RegisterFunction<void, std::wstring, std::wstring, JS::HandleValue, &SaveGame>("SaveGame"); | ||||
scriptInterface.RegisterFunction<void, std::wstring, std::wstring, JS::HandleValue, &SaveGamePrefix>("SaveGamePrefix"); | scriptInterface.RegisterFunction<void, std::wstring, std::wstring, JS::HandleValue, &SaveGamePrefix>("SaveGamePrefix"); | ||||
scriptInterface.RegisterFunction<void, &QuickSave>("QuickSave"); | scriptInterface.RegisterFunction<void, &QuickSave>("QuickSave"); | ||||
scriptInterface.RegisterFunction<void, &QuickLoad>("QuickLoad"); | scriptInterface.RegisterFunction<void, &QuickLoad>("QuickLoad"); | ||||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Why is this being moved?