From bc3dccca5c66019dfbd218f39f086f7384f97d88 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Mon, 12 Sep 2022 19:24:54 +0200 Subject: Mainmenu: Properly sort mods and games (#12758) This also removes trivial and unused pkgmgr functions Fixes a bug caused by sorting in 2133fc8 --- src/script/lua_api/l_mainmenu.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/script/lua_api') 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 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(); -- cgit v1.2.3