Changeset View
Changeset View
Standalone View
Standalone View
source/ps/scripting/JSInterface_ModIo.cpp
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | void JSI_ModIo::CancelRequest(ScriptInterface::CxPrivate* UNUSED(pCxPrivate)) | ||||
{ | { | ||||
LOGERROR("ModIoCancelRequest called before ModIoGetMods"); | LOGERROR("ModIoCancelRequest called before ModIoGetMods"); | ||||
return; | return; | ||||
} | } | ||||
g_ModIo->CancelRequest(); | g_ModIo->CancelRequest(); | ||||
} | } | ||||
JS::Value JSI_ModIo::GetMods(ScriptInterface::CxPrivate* pCxPrivate) | JS::Value JSI_ModIo::GetMods(ScriptInterface::CxPrivate* pCxPrivate) | ||||
elexis: Can be teted by loading the screen, works. | |||||
{ | { | ||||
if (!g_ModIo) | if (!g_ModIo) | ||||
{ | { | ||||
LOGERROR("ModIoGetMods called before ModIoStartGetGameId"); | LOGERROR("ModIoGetMods called before ModIoStartGetGameId"); | ||||
return JS::NullValue(); | return JS::NullValue(); | ||||
} | } | ||||
ScriptInterface* scriptInterface = pCxPrivate->pScriptInterface; | ScriptInterface* scriptInterface = pCxPrivate->pScriptInterface; | ||||
JSContext* cx = scriptInterface->GetContext(); | JSContext* cx = scriptInterface->GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
const std::vector<ModIoModData>& availableMods = g_ModIo->GetMods(); | const std::vector<ModIoModData>& availableMods = g_ModIo->GetMods(); | ||||
JS::RootedObject mods(cx, JS_NewArrayObject(cx, availableMods.size())); | JS::RootedObject mods(cx, JS_NewArrayObject(cx, availableMods.size())); | ||||
Done Inline ActionsUsing new semantics here. elexis: Using new semantics here. | |||||
if (!mods) | if (!mods) | ||||
return JS::NullValue(); | return JS::NullValue(); | ||||
u32 i = 0; | u32 i = 0; | ||||
for (const ModIoModData& mod : availableMods) | for (const ModIoModData& mod : availableMods) | ||||
{ | { | ||||
JS::RootedValue m(cx, JS::ObjectValue(*JS_NewPlainObject(cx))); | JS::RootedValue m(cx); | ||||
scriptInterface->CreateObject(&m); | |||||
for (const std::pair<std::string, std::string>& prop : mod.properties) | for (const std::pair<std::string, std::string>& prop : mod.properties) | ||||
scriptInterface->SetProperty(m, prop.first.c_str(), prop.second, true); | scriptInterface->SetProperty(m, prop.first.c_str(), prop.second, true); | ||||
scriptInterface->SetProperty(m, "dependencies", mod.dependencies, true); | scriptInterface->SetProperty(m, "dependencies", mod.dependencies, true); | ||||
JS_SetElement(cx, mods, i++, m); | JS_SetElement(cx, mods, i++, m); | ||||
} | } | ||||
Show All 21 Lines | if (!g_ModIo) | ||||
LOGERROR("ModIoGetDownloadProgress called before ModIoGetMods"); | LOGERROR("ModIoGetDownloadProgress called before ModIoGetMods"); | ||||
return JS::NullValue(); | return JS::NullValue(); | ||||
} | } | ||||
ScriptInterface* scriptInterface = pCxPrivate->pScriptInterface; | ScriptInterface* scriptInterface = pCxPrivate->pScriptInterface; | ||||
JSContext* cx = scriptInterface->GetContext(); | JSContext* cx = scriptInterface->GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue progressData(cx, JS::ObjectValue(*JS_NewPlainObject(cx))); | |||||
const DownloadProgressData& progress = g_ModIo->GetDownloadProgress(); | const DownloadProgressData& progress = g_ModIo->GetDownloadProgress(); | ||||
JS::RootedValue progressData(cx); | |||||
scriptInterface->CreateObject(&progressData); | |||||
Done Inline ActionsDownloaded a mod, worked. View works too. elexis: Downloaded a mod, worked. View works too. | |||||
scriptInterface->SetProperty(progressData, "status", statusStrings.at(progress.status), true); | scriptInterface->SetProperty(progressData, "status", statusStrings.at(progress.status), true); | ||||
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); | ||||
elexisAuthorUnsubmitted Done Inline ActionsCould use the template function, but then there'd be a scriptInterface->FreezeObject call, but then the other CreateObject call above would be inconsistent, so I'll just not touch this. elexis: Could use the template function, but then there'd be a scriptInterface->FreezeObject call, but… | |||||
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"); | scriptInterface.RegisterFunction<void, &JSI_ModIo::StartGetGameId>("ModIoStartGetGameId"); | ||||
scriptInterface.RegisterFunction<void, &JSI_ModIo::StartListMods>("ModIoStartListMods"); | scriptInterface.RegisterFunction<void, &JSI_ModIo::StartListMods>("ModIoStartListMods"); | ||||
scriptInterface.RegisterFunction<void, uint32_t, &JSI_ModIo::StartDownloadMod>("ModIoStartDownloadMod"); | scriptInterface.RegisterFunction<void, uint32_t, &JSI_ModIo::StartDownloadMod>("ModIoStartDownloadMod"); | ||||
scriptInterface.RegisterFunction<bool, &JSI_ModIo::AdvanceRequest>("ModIoAdvanceRequest"); | scriptInterface.RegisterFunction<bool, &JSI_ModIo::AdvanceRequest>("ModIoAdvanceRequest"); | ||||
scriptInterface.RegisterFunction<void, &JSI_ModIo::CancelRequest>("ModIoCancelRequest"); | scriptInterface.RegisterFunction<void, &JSI_ModIo::CancelRequest>("ModIoCancelRequest"); | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_ModIo::GetMods>("ModIoGetMods"); | scriptInterface.RegisterFunction<JS::Value, &JSI_ModIo::GetMods>("ModIoGetMods"); | ||||
scriptInterface.RegisterFunction<JS::Value, &JSI_ModIo::GetDownloadProgress>("ModIoGetDownloadProgress"); | scriptInterface.RegisterFunction<JS::Value, &JSI_ModIo::GetDownloadProgress>("ModIoGetDownloadProgress"); | ||||
} | } |
Wildfire Games · Phabricator
Can be teted by loading the screen, works.