diff --git a/builtin/mainmenu/dlg_create_world.lua b/builtin/mainmenu/dlg_create_world.lua index faa8ba908..8905f731d 100644 --- a/builtin/mainmenu/dlg_create_world.lua +++ b/builtin/mainmenu/dlg_create_world.lua @@ -90,10 +90,12 @@ local function create_world_formspec(dialogdata) end end - local lua_mapgens = core.get_lua_mapgen_descriptions_and_title() + local lua_mapgens = core.get_lua_mapgens() + local is_lua_mapgen = false for k, v in pairs(lua_mapgens) do if not is_internal_mapgen and v.title == dialogdata.mg then current_mapgen = k + is_lua_mapgen = true end mapgens[#mapgens+1] = k end @@ -181,6 +183,11 @@ local function create_world_formspec(dialogdata) end end + local allowed_lua_mapgen_settings = {} + if is_lua_mapgen and lua_mapgens[current_mapgen].mapgen_flags then + allowed_lua_mapgen_settings = lua_mapgens[current_mapgen].mapgen_flags + end + -- The logic of the flag element IDs is as follows: -- "flag_main_foo-bar-baz" controls dialogdata.flags["main"]["foo_bar_baz"] -- see the buttonhandler for the implementation of this @@ -192,6 +199,9 @@ local function create_world_formspec(dialogdata) if disallowed_mapgen_settings["mg_flags"] then return "", y end + if is_lua_mapgen and not allowed_lua_mapgen_settings["mg_flags"] then + return "", y + end local form = "checkbox[0," .. y .. ";flag_main_caves;" .. fgettext("Caves") .. ";"..strflag(flags.main, "caves").."]" @@ -285,7 +295,7 @@ local function create_world_formspec(dialogdata) local str_flags, str_spflags local label_flags, label_spflags = "", "" y = y + 0.3 - str_flags, y = mg_main_flags(current_mapgen_internal, y) + str_flags, y = mg_main_flags(current_mapgen, y) if str_flags ~= "" then label_flags = "label[0,"..y_start..";" .. fgettext("Mapgen flags") .. "]" y_start = y + 0.4 @@ -414,7 +424,7 @@ local function create_world_buttonhandler(this, fields) end if not is_internal_mapgen then - local lua_mapgens = core.get_lua_mapgen_descriptions_and_title() + local lua_mapgens = core.get_lua_mapgens() for name, v in pairs(lua_mapgens) do if v.title == this.data.mg or (v.title == nil and name == this.data.mg) then mapgen_internal = "singlenode" diff --git a/doc/lua_api.md b/doc/lua_api.md index d3877e8a8..fc7127973 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -438,7 +438,7 @@ A `Settings` file that provides meta information about the mapgen. internal ID used to track versions. * `textdomain`: Textdomain used to translate title and description. Defaults to mapgen. See [Translating content meta](#translating-content-meta). - +* `mapgen_flags`: List of flags to be used Aliases diff --git a/doc/menu_lua_api.md b/doc/menu_lua_api.md index 75ae13ab7..b1ee18a88 100644 --- a/doc/menu_lua_api.md +++ b/doc/menu_lua_api.md @@ -109,7 +109,7 @@ of manually putting one, as different OSs use different delimiters. E.g. * `handle:stop()` or `core.sound_stop(handle)` * `core.get_mapgen_names([include_hidden=false])` -> table of map generator algorithms registered in the core (possible in async calls) -* `core.get_lua_mapgen_descriptions_and_title()` -> map of `[mapgen_name] = {desc = , title = }` as listed +* `core.get_lua_mapgens()` -> map of `[mapgen_name] = {desc = <mapgen_description>, title = <title>}` as listed in `mapgen.conf`, and `nil` if they don't exist. * `core.get_cache_path()` -> path of cache * `core.get_temp_path([param])` (possible in async calls) diff --git a/src/content/mods.cpp b/src/content/mods.cpp index f37f2c86e..bd8003e5c 100644 --- a/src/content/mods.cpp +++ b/src/content/mods.cpp @@ -146,6 +146,15 @@ bool parseModContents(ModSpec &spec) } } } + } else { + if (info.exists("mapgen_flags")) { + std::string dep = info.get("mapgen_flags"); + dep.erase(std::remove_if(dep.begin(), dep.end(), + static_cast<int (*)(int)>(&std::isspace)), dep.end()); + for (const auto &flag : str_split(dep, ',')) { + spec.mapgen_flags.insert(flag); + } + } } if (info.exists("description")) diff --git a/src/content/mods.h b/src/content/mods.h index 6a037e237..72d5e288f 100644 --- a/src/content/mods.h +++ b/src/content/mods.h @@ -38,8 +38,9 @@ struct ModSpec bool part_of_modpack = false; bool is_modpack = false; - // lua-defined mapgen + // lua-defined mapgen only bool is_mapgen = false; + std::unordered_set<std::string> mapgen_flags; /** * A constructed canonical path to represent this mod's location. diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index e8da2d10f..e4eae1bcf 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -664,7 +664,7 @@ int ModApiMainMenu::l_get_mapgen_names(lua_State *L) } /******************************************************************************/ -int ModApiMainMenu::l_get_lua_mapgen_descriptions_and_title(lua_State *L) +int ModApiMainMenu::l_get_lua_mapgens(lua_State *L) { std::vector<ModSpec> mapgens_in_path = flattenMods(getModsInPath(porting::path_share + DIR_DELIM + "mapgens" + DIR_DELIM, "mapgen/")); @@ -704,6 +704,20 @@ int ModApiMainMenu::l_get_lua_mapgen_descriptions_and_title(lua_State *L) } lua_settable(L, top_lvl2); + lua_pushstring(L, "mapgen_flags"); + if (!mod.mapgen_flags.empty()) { + lua_newtable(L); + int mapgen_flags_top = lua_gettop(L); + for (const auto &flag : mod.mapgen_flags) { + lua_pushstring(L, flag.c_str()); + lua_pushboolean(L, true); + lua_settable(L, mapgen_flags_top); + } + } else { + lua_pushnil(L); + } + lua_settable(L, top_lvl2); + lua_settable(L, top); } } @@ -1108,7 +1122,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) API_FCT(set_background); API_FCT(set_topleft_text); API_FCT(get_mapgen_names); - API_FCT(get_lua_mapgen_descriptions_and_title); + API_FCT(get_lua_mapgens); API_FCT(get_user_path); API_FCT(get_modpath); API_FCT(get_modpaths); @@ -1150,7 +1164,7 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top) API_FCT(get_worlds); API_FCT(get_games); API_FCT(get_mapgen_names); - API_FCT(get_lua_mapgen_descriptions_and_title); + API_FCT(get_lua_mapgens); API_FCT(get_user_path); API_FCT(get_modpath); API_FCT(get_modpaths); diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index f45138493..89fffb294 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -51,7 +51,7 @@ private: static int l_get_mapgen_names(lua_State *L); - static int l_get_lua_mapgen_descriptions_and_title(lua_State *L); + static int l_get_lua_mapgens(lua_State *L); static int l_get_language(lua_State *L);