From 71b2570f0919d3bb5575c9ec694ecd004222fcea Mon Sep 17 00:00:00 2001 From: Andrew Ward Date: Wed, 28 Mar 2018 22:14:16 +0100 Subject: Load dependencies and description from mod.conf --- src/script/lua_api/l_mainmenu.cpp | 148 +++++++++++++++++++++++++------------- src/script/lua_api/l_mainmenu.h | 8 ++- 2 files changed, 104 insertions(+), 52 deletions(-) (limited to 'src/script') diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 95696bc20..027b7b0f8 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -257,56 +257,6 @@ int ModApiMainMenu::l_get_worlds(lua_State *L) return 1; } -/******************************************************************************/ -int ModApiMainMenu::l_get_games(lua_State *L) -{ - std::vector games = getAvailableGames(); - - lua_newtable(L); - int top = lua_gettop(L); - unsigned int index = 1; - - for (const SubgameSpec &game : games) { - lua_pushnumber(L,index); - lua_newtable(L); - int top_lvl2 = lua_gettop(L); - - lua_pushstring(L,"id"); - lua_pushstring(L, game.id.c_str()); - lua_settable(L, top_lvl2); - - lua_pushstring(L,"path"); - lua_pushstring(L, game.path.c_str()); - lua_settable(L, top_lvl2); - - lua_pushstring(L,"gamemods_path"); - lua_pushstring(L, game.gamemods_path.c_str()); - lua_settable(L, top_lvl2); - - lua_pushstring(L,"name"); - lua_pushstring(L, game.name.c_str()); - lua_settable(L, top_lvl2); - - lua_pushstring(L,"menuicon_path"); - lua_pushstring(L, game.menuicon_path.c_str()); - lua_settable(L, top_lvl2); - - lua_pushstring(L,"addon_mods_paths"); - lua_newtable(L); - int table2 = lua_gettop(L); - int internal_index=1; - for (const std::string &addon_mods_path : game.addon_mods_paths) { - lua_pushnumber(L,internal_index); - lua_pushstring(L, addon_mods_path.c_str()); - lua_settable(L, table2); - internal_index++; - } - lua_settable(L, top_lvl2); - lua_settable(L, top); - index++; - } - return 1; -} /******************************************************************************/ int ModApiMainMenu::l_get_favorites(lua_State *L) { @@ -477,6 +427,103 @@ int ModApiMainMenu::l_delete_favorite(lua_State *L) return 0; } +/******************************************************************************/ +int ModApiMainMenu::l_get_games(lua_State *L) +{ + std::vector games = getAvailableGames(); + + lua_newtable(L); + int top = lua_gettop(L); + unsigned int index = 1; + + for (const SubgameSpec &game : games) { + lua_pushnumber(L, index); + lua_newtable(L); + int top_lvl2 = lua_gettop(L); + + lua_pushstring(L, "id"); + lua_pushstring(L, game.id.c_str()); + lua_settable(L, top_lvl2); + + lua_pushstring(L, "path"); + lua_pushstring(L, game.path.c_str()); + lua_settable(L, top_lvl2); + + lua_pushstring(L, "gamemods_path"); + lua_pushstring(L, game.gamemods_path.c_str()); + lua_settable(L, top_lvl2); + + lua_pushstring(L, "name"); + lua_pushstring(L, game.name.c_str()); + lua_settable(L, top_lvl2); + + lua_pushstring(L, "menuicon_path"); + lua_pushstring(L, game.menuicon_path.c_str()); + lua_settable(L, top_lvl2); + + lua_pushstring(L, "addon_mods_paths"); + lua_newtable(L); + int table2 = lua_gettop(L); + int internal_index = 1; + for (const std::string &addon_mods_path : game.addon_mods_paths) { + lua_pushnumber(L, internal_index); + lua_pushstring(L, addon_mods_path.c_str()); + lua_settable(L, table2); + internal_index++; + } + lua_settable(L, top_lvl2); + lua_settable(L, top); + index++; + } + return 1; +} + +/******************************************************************************/ +int ModApiMainMenu::l_get_mod_info(lua_State *L) +{ + std::string path = luaL_checkstring(L, 1); + + ModSpec spec; + spec.path = path; + parseModContents(spec); + + lua_newtable(L); + + lua_pushstring(L, spec.name.c_str()); + lua_setfield(L, -2, "name"); + + lua_pushstring(L, spec.is_modpack ? "modpack" : "mod"); + lua_setfield(L, -2, "type"); + + lua_pushstring(L, spec.desc.c_str()); + lua_setfield(L, -2, "description"); + + lua_pushstring(L, spec.path.c_str()); + lua_setfield(L, -2, "path"); + + // Dependencies + lua_newtable(L); + int i = 1; + for (const auto &dep : spec.depends) { + lua_pushstring(L, dep.c_str()); + lua_rawseti(L, -2, i); + i++; + } + lua_setfield(L, -2, "depends"); + + // Optional Dependencies + lua_newtable(L); + i = 1; + for (const auto &dep : spec.optdepends) { + lua_pushstring(L, dep.c_str()); + lua_rawseti(L, -2, i); + i++; + } + lua_setfield(L, -2, "optional_depends"); + + return 1; +} + /******************************************************************************/ int ModApiMainMenu::l_show_keys_menu(lua_State *L) { @@ -968,6 +1015,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) API_FCT(get_table_index); API_FCT(get_worlds); API_FCT(get_games); + API_FCT(get_mod_info); API_FCT(start); API_FCT(close); API_FCT(get_favorites); diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index ffaab7dca..2faeaf63e 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -71,8 +71,6 @@ private: static int l_get_worlds(lua_State *L); - static int l_get_games(lua_State *L); - static int l_get_mapgen_names(lua_State *L); static int l_get_favorites(lua_State *L); @@ -81,6 +79,12 @@ private: static int l_gettext(lua_State *L); + //packages + + static int l_get_games(lua_State *L); + + static int l_get_mod_info(lua_State *L); + //gui static int l_show_keys_menu(lua_State *L); -- cgit v1.2.3