Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/scripting/JSInterface_ModIo.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
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(); | ScriptInterface::Request rq(scriptInterface); | ||||
JSAutoRequest rq(cx); | |||||
const std::vector<ModIoModData>& availableMods = g_ModIo->GetMods(); | const std::vector<ModIoModData>& availableMods = g_ModIo->GetMods(); | ||||
JS::RootedValue mods(cx); | JS::RootedValue mods(rq.cx); | ||||
ScriptInterface::CreateArray(cx, &mods, availableMods.size()); | ScriptInterface::CreateArray(rq, &mods, availableMods.size()); | ||||
u32 i = 0; | u32 i = 0; | ||||
for (const ModIoModData& mod : availableMods) | for (const ModIoModData& mod : availableMods) | ||||
{ | { | ||||
JS::RootedValue m(cx); | JS::RootedValue m(rq.cx); | ||||
ScriptInterface::CreateObject(cx, &m); | ScriptInterface::CreateObject(rq, &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); | ||||
scriptInterface->SetPropertyInt(mods, i++, m); | scriptInterface->SetPropertyInt(mods, i++, m); | ||||
} | } | ||||
Show All 18 Lines | |||||
{ | { | ||||
if (!g_ModIo) | 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(); | ScriptInterface::Request rq(scriptInterface); | ||||
JSAutoRequest rq(cx); | |||||
const DownloadProgressData& progress = g_ModIo->GetDownloadProgress(); | const DownloadProgressData& progress = g_ModIo->GetDownloadProgress(); | ||||
JS::RootedValue progressData(cx); | JS::RootedValue progressData(rq.cx); | ||||
ScriptInterface::CreateObject(cx, &progressData); | ScriptInterface::CreateObject(rq, &progressData); | ||||
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); | ||||
return progressData; | return progressData; | ||||
} | } | ||||
void JSI_ModIo::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | void JSI_ModIo::RegisterScriptFunctions(const ScriptInterface& scriptInterface) | ||||
Show All 9 Lines |
Wildfire Games · Phabricator