Changeset View
Changeset View
Standalone View
Standalone View
source/ps/scripting/JSInterface_ModIo.cpp
Show All 15 Lines | |||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "JSInterface_ModIo.h" | #include "JSInterface_ModIo.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/ModIo.h" | #include "ps/ModIo.h" | ||||
#include "scriptinterface/FunctionWrapper.h" | |||||
void JSI_ModIo::StartGetGameId(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | void JSI_ModIo::StartGetGameId() | ||||
{ | { | ||||
if (!g_ModIo) | if (!g_ModIo) | ||||
g_ModIo = new ModIo(); | g_ModIo = new ModIo(); | ||||
ENSURE(g_ModIo); | ENSURE(g_ModIo); | ||||
g_ModIo->StartGetGameId(); | g_ModIo->StartGetGameId(); | ||||
} | } | ||||
void JSI_ModIo::StartListMods(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | void JSI_ModIo::StartListMods() | ||||
{ | { | ||||
if (!g_ModIo) | if (!g_ModIo) | ||||
{ | { | ||||
LOGERROR("ModIoStartListMods called before ModIoStartGetGameId"); | LOGERROR("ModIoStartListMods called before ModIoStartGetGameId"); | ||||
return; | return; | ||||
} | } | ||||
g_ModIo->StartListMods(); | g_ModIo->StartListMods(); | ||||
} | } | ||||
void JSI_ModIo::StartDownloadMod(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), uint32_t idx) | void JSI_ModIo::StartDownloadMod(uint32_t idx) | ||||
{ | { | ||||
if (!g_ModIo) | if (!g_ModIo) | ||||
{ | { | ||||
LOGERROR("ModIoStartDownloadMod called before ModIoStartGetGameId"); | LOGERROR("ModIoStartDownloadMod called before ModIoStartGetGameId"); | ||||
return; | return; | ||||
} | } | ||||
g_ModIo->StartDownloadMod(idx); | g_ModIo->StartDownloadMod(idx); | ||||
} | } | ||||
bool JSI_ModIo::AdvanceRequest(ScriptInterface::CxPrivate* pCxPrivate) | bool JSI_ModIo::AdvanceRequest(ScriptInterface::CxPrivate* pCxPrivate) | ||||
{ | { | ||||
if (!g_ModIo) | if (!g_ModIo) | ||||
{ | { | ||||
LOGERROR("ModIoAdvanceRequest called before ModIoGetMods"); | LOGERROR("ModIoAdvanceRequest called before ModIoGetMods"); | ||||
return false; | return false; | ||||
} | } | ||||
ScriptInterface* scriptInterface = pCxPrivate->pScriptInterface; | ScriptInterface* scriptInterface = pCxPrivate->pScriptInterface; | ||||
return g_ModIo->AdvanceRequest(*scriptInterface); | return g_ModIo->AdvanceRequest(*scriptInterface); | ||||
} | } | ||||
void JSI_ModIo::CancelRequest(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | void JSI_ModIo::CancelRequest() | ||||
{ | { | ||||
if (!g_ModIo) | if (!g_ModIo) | ||||
{ | { | ||||
LOGERROR("ModIoCancelRequest called before ModIoGetMods"); | LOGERROR("ModIoCancelRequest called before ModIoGetMods"); | ||||
return; | return; | ||||
} | } | ||||
g_ModIo->CancelRequest(); | g_ModIo->CancelRequest(); | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | JS::Value JSI_ModIo::GetDownloadProgress(ScriptInterface::CxPrivate* pCxPrivate) | ||||
scriptInterface->SetProperty(progressData, "progress", progress.progress, true); | scriptInterface->SetProperty(progressData, "progress", progress.progress, true); | ||||
scriptInterface->SetProperty(progressData, "error", progress.error, true); | scriptInterface->SetProperty(progressData, "error", progress.error, true); | ||||
return progressData; | return progressData; | ||||
} | } | ||||
void JSI_ModIo::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | void JSI_ModIo::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
scriptInterface.RegisterFunction<void, &JSI_ModIo::StartGetGameId>("ModIoStartGetGameId"); | #define Register(name) ScriptWrapper::WrapAndRegister<decltype(&JSI_ModIo::name), &JSI_ModIo::name>(scriptInterface, "ModIo" #name) | ||||
scriptInterface.RegisterFunction<void, &JSI_ModIo::StartListMods>("ModIoStartListMods"); | Register(StartGetGameId); | ||||
scriptInterface.RegisterFunction<void, uint32_t, &JSI_ModIo::StartDownloadMod>("ModIoStartDownloadMod"); | Register(StartListMods); | ||||
scriptInterface.RegisterFunction<bool, &JSI_ModIo::AdvanceRequest>("ModIoAdvanceRequest"); | Register(StartDownloadMod); | ||||
scriptInterface.RegisterFunction<void, &JSI_ModIo::CancelRequest>("ModIoCancelRequest"); | Register(AdvanceRequest); | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_ModIo::GetMods>("ModIoGetMods"); | Register(CancelRequest); | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_ModIo::GetDownloadProgress>("ModIoGetDownloadProgress"); | Register(GetMods); | ||||
Register(GetDownloadProgress); | |||||
#undef Register | |||||
} | } |
Wildfire Games · Phabricator