Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/Mod.cpp
Show All 22 Lines | |||||
#include "lib/file/file_system.h" | #include "lib/file/file_system.h" | ||||
#include "lib/file/vfs/vfs.h" | #include "lib/file/vfs/vfs.h" | ||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/GameSetup/GameSetup.h" | #include "ps/GameSetup/GameSetup.h" | ||||
#include "ps/GameSetup/Paths.h" | #include "ps/GameSetup/Paths.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/ScriptRuntime.h" | |||||
std::vector<CStr> g_modsLoaded; | std::vector<CStr> g_modsLoaded; | ||||
std::vector<std::vector<CStr>> g_LoadedModVersions; | |||||
CmdLineArgs g_args; | CmdLineArgs g_args; | ||||
JS::Value Mod::GetAvailableMods(const ScriptInterface& scriptInterface) | JS::Value Mod::GetAvailableMods(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedObject obj(cx, JS_NewPlainObject(cx)); | JS::RootedObject obj(cx, JS_NewPlainObject(cx)); | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | for (DirectoryNames::iterator iter = modDirsUser.begin(); iter != modDirsUser.end(); ++iter) | ||||
// Valid mod, add it to our structure | // Valid mod, add it to our structure | ||||
JS_SetProperty(cx, obj, utf8_from_wstring(iter->string()).c_str(), json); | JS_SetProperty(cx, obj, utf8_from_wstring(iter->string()).c_str(), json); | ||||
} | } | ||||
return JS::ObjectValue(*obj); | return JS::ObjectValue(*obj); | ||||
} | } | ||||
JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface) | void Mod::CacheEnabledModVersions(const shared_ptr<ScriptRuntime>& scriptRuntime) | ||||
{ | { | ||||
ScriptInterface scriptInterface("Engine", "CacheEnabledModVersions", scriptRuntime); | |||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue availableMods(cx, GetAvailableMods(scriptInterface)); | JS::RootedValue availableMods(cx, GetAvailableMods(scriptInterface)); | ||||
JS::RootedValue ret(cx, JS::ObjectValue(*JS_NewArrayObject(cx, 0))); | g_LoadedModVersions.clear(); | ||||
// Index of the created array | for (const CStr& mod : g_modsLoaded) | ||||
size_t j = 0; | |||||
for (size_t i = 0; i < g_modsLoaded.size(); ++i) | |||||
{ | { | ||||
// Ignore user and mod mod as they are irrelevant for compatibility checks | // Ignore user and mod mod as they are irrelevant for compatibility checks | ||||
if (g_modsLoaded[i] == "mod" || g_modsLoaded[i] == "user") | if (mod == "mod" || mod == "user") | ||||
continue; | continue; | ||||
CStr version; | CStr version; | ||||
JS::RootedValue modData(cx); | JS::RootedValue modData(cx); | ||||
if (scriptInterface.GetProperty(availableMods, g_modsLoaded[i].c_str(), &modData)) | if (scriptInterface.GetProperty(availableMods, mod.c_str(), &modData)) | ||||
scriptInterface.GetProperty(modData, "version", version); | scriptInterface.GetProperty(modData, "version", version); | ||||
scriptInterface.SetPropertyInt(ret, j++, std::vector<CStr>{g_modsLoaded[i], version}); | |||||
g_LoadedModVersions.push_back({mod, version}); | |||||
} | |||||
} | } | ||||
return ret; | |||||
JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface) | |||||
{ | |||||
JSContext* cx = scriptInterface.GetContext(); | |||||
JSAutoRequest rq(cx); | |||||
JS::RootedValue returnValue(cx); | |||||
scriptInterface.ToJSVal(cx, &returnValue, g_LoadedModVersions); | |||||
return returnValue; | |||||
} | } | ||||
JS::Value Mod::GetEngineInfo(const ScriptInterface& scriptInterface) | JS::Value Mod::GetEngineInfo(const ScriptInterface& scriptInterface) | ||||
{ | { | ||||
JSContext* cx = scriptInterface.GetContext(); | JSContext* cx = scriptInterface.GetContext(); | ||||
JSAutoRequest rq(cx); | JSAutoRequest rq(cx); | ||||
JS::RootedValue metainfo(cx); | JS::RootedValue metainfo(cx); | ||||
Show All 9 Lines |
Wildfire Games · Phabricator