aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp32
-rw-r--r--src/script/common/c_content.h3
-rw-r--r--src/script/lua_api/l_mainmenu.cpp97
-rw-r--r--src/script/lua_api/l_mainmenu.h2
4 files changed, 133 insertions, 1 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 10670a60a..166980025 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -2143,3 +2143,35 @@ void push_collision_move_result(lua_State *L, const collisionMoveResult &res)
lua_setfield(L, -2, "collisions");
/**/
}
+
+
+void push_mod_spec(lua_State *L, const ModSpec &spec, bool include_unsatisfied)
+{
+ lua_newtable(L);
+
+ lua_pushstring(L, spec.name.c_str());
+ lua_setfield(L, -2, "name");
+
+ lua_pushstring(L, spec.author.c_str());
+ lua_setfield(L, -2, "author");
+
+ lua_pushinteger(L, spec.release);
+ lua_setfield(L, -2, "release");
+
+ lua_pushstring(L, spec.desc.c_str());
+ lua_setfield(L, -2, "description");
+
+ lua_pushstring(L, spec.path.c_str());
+ lua_setfield(L, -2, "path");
+
+ lua_pushstring(L, spec.virtual_path.c_str());
+ lua_setfield(L, -2, "virtual_path");
+
+ lua_newtable(L);
+ int i = 1;
+ for (const auto &dep : spec.unsatisfied_depends) {
+ lua_pushstring(L, dep.c_str());
+ lua_rawseti(L, -2, i++);
+ }
+ lua_setfield(L, -2, "unsatisfied_depends");
+}
diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h
index 06f80328a..ade3e4c1e 100644
--- a/src/script/common/c_content.h
+++ b/src/script/common/c_content.h
@@ -42,6 +42,7 @@ extern "C" {
// We do a explicit path include because by default c_content.h include src/client/hud.h
// prior to the src/hud.h, which is not good on server only build
#include "../../hud.h"
+#include "content/mods.h"
namespace Json { class Value; }
@@ -204,3 +205,5 @@ void push_hud_element (lua_State *L, HudElement *elem);
bool read_hud_change (lua_State *L, HudElementStat &stat, HudElement *elem, void **value);
void push_collision_move_result(lua_State *L, const collisionMoveResult &res);
+
+void push_mod_spec(lua_State *L, const ModSpec &spec, bool include_unsatisfied);
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index 4a847ed6d..cf4a057e1 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -38,7 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/client.h"
#include "client/renderingengine.h"
#include "network/networkprotocol.h"
-
+#include "content/mod_configuration.h"
/******************************************************************************/
std::string ModApiMainMenu::getTextData(lua_State *L, std::string name)
@@ -410,6 +410,100 @@ int ModApiMainMenu::l_get_content_info(lua_State *L)
}
/******************************************************************************/
+int ModApiMainMenu::l_check_mod_configuration(lua_State *L)
+{
+ std::string worldpath = luaL_checkstring(L, 1);
+
+ ModConfiguration modmgr;
+
+ // Add all game mods
+ SubgameSpec gamespec = findWorldSubgame(worldpath);
+ modmgr.addGameMods(gamespec);
+ modmgr.addModsInPath(worldpath + DIR_DELIM + "worldmods", "worldmods");
+
+ // Add user-configured mods
+ std::vector<ModSpec> modSpecs;
+
+ luaL_checktype(L, 2, LUA_TTABLE);
+
+ lua_pushnil(L);
+ while (lua_next(L, 2)) {
+ // Ignore non-string keys
+ if (lua_type(L, -2) != LUA_TSTRING) {
+ throw LuaError(
+ "Unexpected non-string key in table passed to "
+ "core.check_mod_configuration");
+ }
+
+ std::string modpath = luaL_checkstring(L, -1);
+ lua_pop(L, 1);
+ std::string virtual_path = lua_tostring(L, -1);
+
+ modSpecs.emplace_back();
+ ModSpec &spec = modSpecs.back();
+ spec.name = fs::GetFilenameFromPath(modpath.c_str());
+ spec.path = modpath;
+ spec.virtual_path = virtual_path;
+ if (!parseModContents(spec)) {
+ throw LuaError("Not a mod!");
+ }
+ }
+
+ modmgr.addMods(modSpecs);
+ try {
+ modmgr.checkConflictsAndDeps();
+ } catch (const ModError &err) {
+ errorstream << err.what() << std::endl;
+
+ lua_newtable(L);
+
+ lua_pushboolean(L, false);
+ lua_setfield(L, -2, "is_consistent");
+
+ lua_newtable(L);
+ lua_setfield(L, -2, "unsatisfied_mods");
+
+ lua_newtable(L);
+ lua_setfield(L, -2, "satisfied_mods");
+
+ lua_pushstring(L, err.what());
+ lua_setfield(L, -2, "error_message");
+ return 1;
+ }
+
+
+ lua_newtable(L);
+
+ lua_pushboolean(L, modmgr.isConsistent());
+ lua_setfield(L, -2, "is_consistent");
+
+ lua_newtable(L);
+ int top = lua_gettop(L);
+ unsigned int index = 1;
+ for (const auto &spec : modmgr.getUnsatisfiedMods()) {
+ lua_pushnumber(L, index);
+ push_mod_spec(L, spec, true);
+ lua_settable(L, top);
+ index++;
+ }
+
+ lua_setfield(L, -2, "unsatisfied_mods");
+
+ lua_newtable(L);
+ top = lua_gettop(L);
+ index = 1;
+ for (const auto &spec : modmgr.getMods()) {
+ lua_pushnumber(L, index);
+ push_mod_spec(L, spec, false);
+ lua_settable(L, top);
+ index++;
+ }
+ lua_setfield(L, -2, "satisfied_mods");
+
+ return 1;
+}
+
+/******************************************************************************/
int ModApiMainMenu::l_show_keys_menu(lua_State *L)
{
GUIEngine* engine = getGuiEngine(L);
@@ -921,6 +1015,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(get_worlds);
API_FCT(get_games);
API_FCT(get_content_info);
+ API_FCT(check_mod_configuration);
API_FCT(start);
API_FCT(close);
API_FCT(show_keys_menu);
diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h
index 6ceff6dd7..9dc40c7f4 100644
--- a/src/script/lua_api/l_mainmenu.h
+++ b/src/script/lua_api/l_mainmenu.h
@@ -82,6 +82,8 @@ private:
static int l_get_content_info(lua_State *L);
+ static int l_check_mod_configuration(lua_State *L);
+
//gui
static int l_show_keys_menu(lua_State *L);