aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2022-09-12 19:24:54 +0200
committerGitHub <noreply@github.com>2022-09-12 19:24:54 +0200
commitbc3dccca5c66019dfbd218f39f086f7384f97d88 (patch)
treed61879776c3a0a79ef985f5fc431b3c3568b32af /src
parentfe13f9dfd12c0a7f08355b83e34e7dec1bfdd86d (diff)
downloadminetest-bc3dccca5c66019dfbd218f39f086f7384f97d88.tar.xz
Mainmenu: Properly sort mods and games (#12758)
This also removes trivial and unused pkgmgr functions Fixes a bug caused by sorting in 2133fc8
Diffstat (limited to 'src')
-rw-r--r--src/script/lua_api/l_mainmenu.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index cf4a057e1..789096d23 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -522,8 +522,8 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_create_world(lua_State *L)
{
- const char *name = luaL_checkstring(L, 1);
- int gameidx = luaL_checkinteger(L,2) -1;
+ const char *name = luaL_checkstring(L, 1);
+ const char *gameid = luaL_checkstring(L, 2);
StringMap use_settings;
luaL_checktype(L, 3, LUA_TTABLE);
@@ -540,8 +540,11 @@ int ModApiMainMenu::l_create_world(lua_State *L)
+ sanitizeDirName(name, "world_");
std::vector<SubgameSpec> games = getAvailableGames();
- if (gameidx < 0 || gameidx >= (int) games.size()) {
- lua_pushstring(L, "Invalid game index");
+ auto game_it = std::find_if(games.begin(), games.end(), [gameid] (const SubgameSpec &spec) {
+ return spec.id == gameid;
+ });
+ if (game_it == games.end()) {
+ lua_pushstring(L, "Game ID not found");
return 1;
}
@@ -556,7 +559,7 @@ int ModApiMainMenu::l_create_world(lua_State *L)
// Create world if it doesn't exist
try {
- loadGameConfAndInitWorld(path, name, games[gameidx], true);
+ loadGameConfAndInitWorld(path, name, *game_it, true);
lua_pushnil(L);
} catch (const BaseException &e) {
auto err = std::string("Failed to initialize world: ") + e.what();