Changeset View
Changeset View
Standalone View
Standalone View
source/ps/Mod.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2018 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 All 11 Lines | |||||
#include <algorithm> | #include <algorithm> | ||||
#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" | ||||
elexis: I like to move it, move it! You like to move it? | |||||
std::vector<CStr> g_modsLoaded; | std::vector<CStr> g_modsLoaded; | ||||
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(); | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if (!scriptInterface.ParseJSON(modinfo.GetAsString(), &json)) | ||||
continue; | continue; | ||||
// 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) | |||||
{ | |||||
JSContext* cx = scriptInterface.GetContext(); | |||||
JSAutoRequest rq(cx); | |||||
JS::RootedValue availableMods(cx, GetAvailableMods(scriptInterface)); | |||||
JS::RootedValue ret(cx); | |||||
scriptInterface.Eval("([])", &ret); | |||||
Done Inline Actionsconst ref elexis: const ref | |||||
Done Inline Actionsremove commented code elexis: remove commented code | |||||
Done Inline ActionsThose Evals were ugly. What happened to JS_NewArrayObject? elexis: Those Evals were ugly. What happened to `JS_NewArrayObject`?
`XmppClient… | |||||
for (size_t i = 0; i < g_modsLoaded.size(); ++i) | |||||
{ | |||||
Done Inline ActionsWondering if we shouldn't ignore the user-mod here. Useless bytes saved to the disk and sent across the network. elexis: Wondering if we shouldn't ignore the user-mod here. Useless bytes saved to the disk and sent… | |||||
CStr version; | |||||
JS::RootedValue modData(cx); | |||||
Done Inline Actions(Was thinking about HasProperty, but indeed we need to call GetProperty anyhow. Adding the Has would likely even give a false sense of security, because if a mod is launched but not available, that should fail hard as soon as possible. (If theres some virtual mod on some OS but not others that should be visible in the code with extra checks probably)) elexis: (Was thinking about `HasProperty`, but indeed we need to call `GetProperty` anyhow. Adding the… | |||||
if (scriptInterface.GetProperty(availableMods, g_modsLoaded[i].c_str(), &modData)) | |||||
scriptInterface.GetProperty(modData, "version", version); | |||||
scriptInterface.SetPropertyInt(ret, i, std::vector<CStr>{g_modsLoaded[i], version}); | |||||
} | |||||
return ret; | |||||
} |
Wildfire Games · Phabricator
I like to move it, move it! You like to move it?