1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

start working on flags

This commit is contained in:
Xeno333 2025-06-14 22:50:31 -05:00
parent 33908990cc
commit 75a7c3b4de
7 changed files with 44 additions and 10 deletions

View file

@ -90,10 +90,12 @@ local function create_world_formspec(dialogdata)
end end
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 for k, v in pairs(lua_mapgens) do
if not is_internal_mapgen and v.title == dialogdata.mg then if not is_internal_mapgen and v.title == dialogdata.mg then
current_mapgen = k current_mapgen = k
is_lua_mapgen = true
end end
mapgens[#mapgens+1] = k mapgens[#mapgens+1] = k
end end
@ -181,6 +183,11 @@ local function create_world_formspec(dialogdata)
end end
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: -- The logic of the flag element IDs is as follows:
-- "flag_main_foo-bar-baz" controls dialogdata.flags["main"]["foo_bar_baz"] -- "flag_main_foo-bar-baz" controls dialogdata.flags["main"]["foo_bar_baz"]
-- see the buttonhandler for the implementation of this -- 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 if disallowed_mapgen_settings["mg_flags"] then
return "", y return "", y
end 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;" .. local form = "checkbox[0," .. y .. ";flag_main_caves;" ..
fgettext("Caves") .. ";"..strflag(flags.main, "caves").."]" fgettext("Caves") .. ";"..strflag(flags.main, "caves").."]"
@ -285,7 +295,7 @@ local function create_world_formspec(dialogdata)
local str_flags, str_spflags local str_flags, str_spflags
local label_flags, label_spflags = "", "" local label_flags, label_spflags = "", ""
y = y + 0.3 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 if str_flags ~= "" then
label_flags = "label[0,"..y_start..";" .. fgettext("Mapgen flags") .. "]" label_flags = "label[0,"..y_start..";" .. fgettext("Mapgen flags") .. "]"
y_start = y + 0.4 y_start = y + 0.4
@ -414,7 +424,7 @@ local function create_world_buttonhandler(this, fields)
end end
if not is_internal_mapgen then 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 for name, v in pairs(lua_mapgens) do
if v.title == this.data.mg or (v.title == nil and name == this.data.mg) then if v.title == this.data.mg or (v.title == nil and name == this.data.mg) then
mapgen_internal = "singlenode" mapgen_internal = "singlenode"

View file

@ -438,7 +438,7 @@ A `Settings` file that provides meta information about the mapgen.
internal ID used to track versions. internal ID used to track versions.
* `textdomain`: Textdomain used to translate title and description. Defaults to mapgen. * `textdomain`: Textdomain used to translate title and description. Defaults to mapgen.
See [Translating content meta](#translating-content-meta). See [Translating content meta](#translating-content-meta).
* `mapgen_flags`: List of flags to be used
Aliases Aliases

View file

@ -109,7 +109,7 @@ of manually putting one, as different OSs use different delimiters. E.g.
* `handle:stop()` or `core.sound_stop(handle)` * `handle:stop()` or `core.sound_stop(handle)`
* `core.get_mapgen_names([include_hidden=false])` -> table of map generator algorithms * `core.get_mapgen_names([include_hidden=false])` -> table of map generator algorithms
registered in the core (possible in async calls) registered in the core (possible in async calls)
* `core.get_lua_mapgen_descriptions_and_title()` -> map of `[mapgen_name] = {desc = <mapgen_description>, title = <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. in `mapgen.conf`, and `nil` if they don't exist.
* `core.get_cache_path()` -> path of cache * `core.get_cache_path()` -> path of cache
* `core.get_temp_path([param])` (possible in async calls) * `core.get_temp_path([param])` (possible in async calls)

View file

@ -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")) if (info.exists("description"))

View file

@ -38,8 +38,9 @@ struct ModSpec
bool part_of_modpack = false; bool part_of_modpack = false;
bool is_modpack = false; bool is_modpack = false;
// lua-defined mapgen // lua-defined mapgen only
bool is_mapgen = false; bool is_mapgen = false;
std::unordered_set<std::string> mapgen_flags;
/** /**
* A constructed canonical path to represent this mod's location. * A constructed canonical path to represent this mod's location.

View file

@ -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/")); 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_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); lua_settable(L, top);
} }
} }
@ -1108,7 +1122,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(set_background); API_FCT(set_background);
API_FCT(set_topleft_text); API_FCT(set_topleft_text);
API_FCT(get_mapgen_names); 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_user_path);
API_FCT(get_modpath); API_FCT(get_modpath);
API_FCT(get_modpaths); API_FCT(get_modpaths);
@ -1150,7 +1164,7 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
API_FCT(get_worlds); API_FCT(get_worlds);
API_FCT(get_games); API_FCT(get_games);
API_FCT(get_mapgen_names); 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_user_path);
API_FCT(get_modpath); API_FCT(get_modpath);
API_FCT(get_modpaths); API_FCT(get_modpaths);

View file

@ -51,7 +51,7 @@ private:
static int l_get_mapgen_names(lua_State *L); 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); static int l_get_language(lua_State *L);