mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-26 18:21:04 +00:00
working flags
This commit is contained in:
parent
060696be24
commit
8765654e46
5 changed files with 63 additions and 7 deletions
|
@ -187,6 +187,10 @@ local function create_world_formspec(dialogdata)
|
||||||
if is_lua_mapgen and lua_mapgens[current_mapgen].mg_flags then
|
if is_lua_mapgen and lua_mapgens[current_mapgen].mg_flags then
|
||||||
lua_mapgen_allowed_mg_flags = lua_mapgens[current_mapgen].mg_flags
|
lua_mapgen_allowed_mg_flags = lua_mapgens[current_mapgen].mg_flags
|
||||||
end
|
end
|
||||||
|
local lua_mapgen_flags = {}
|
||||||
|
if is_lua_mapgen and lua_mapgens[current_mapgen].lmg_flags then
|
||||||
|
lua_mapgen_flags = lua_mapgens[current_mapgen].lmg_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"]
|
||||||
|
@ -265,13 +269,27 @@ local function create_world_formspec(dialogdata)
|
||||||
end
|
end
|
||||||
|
|
||||||
local mg_specific_flags = function(mapgen, y)
|
local mg_specific_flags = function(mapgen, y)
|
||||||
if not flag_checkboxes[mapgen] then
|
if not is_lua_mapgen and not flag_checkboxes[mapgen] then
|
||||||
return "", y
|
return "", y
|
||||||
end
|
end
|
||||||
if disallowed_mapgen_settings["mg"..mapgen.."_spflags"] then
|
if disallowed_mapgen_settings["mg"..mapgen.."_spflags"] then
|
||||||
return "", y
|
return "", y
|
||||||
end
|
end
|
||||||
|
|
||||||
local form = ""
|
local form = ""
|
||||||
|
|
||||||
|
if is_lua_mapgen then
|
||||||
|
for tab, _ in pairs(lua_mapgen_flags) do
|
||||||
|
local id = "flag_"..mapgen.."_"..tab:gsub("_", "-")
|
||||||
|
form = form .. ("checkbox[0,%f;%s;%s;%s]"):
|
||||||
|
format(y, id, tab, "true")
|
||||||
|
|
||||||
|
y = y + 0.5
|
||||||
|
end
|
||||||
|
|
||||||
|
return form, y
|
||||||
|
end
|
||||||
|
|
||||||
for _, tab in pairs(flag_checkboxes[mapgen]) do
|
for _, tab in pairs(flag_checkboxes[mapgen]) do
|
||||||
local id = "flag_"..mapgen.."_"..tab[1]:gsub("_", "-")
|
local id = "flag_"..mapgen.."_"..tab[1]:gsub("_", "-")
|
||||||
form = form .. ("checkbox[0,%f;%s;%s;%s]"):
|
form = form .. ("checkbox[0,%f;%s;%s;%s]"):
|
||||||
|
@ -335,7 +353,7 @@ local function create_world_formspec(dialogdata)
|
||||||
y_start = 0.0
|
y_start = 0.0
|
||||||
end
|
end
|
||||||
y = y_start + 0.3
|
y = y_start + 0.3
|
||||||
str_spflags = mg_specific_flags(current_mapgen_internal, y)
|
str_spflags = mg_specific_flags(current_mapgen, y)
|
||||||
if str_spflags ~= "" then
|
if str_spflags ~= "" then
|
||||||
label_spflags = "label[0,"..y_start..";" .. fgettext("Mapgen-specific flags") .. "]"
|
label_spflags = "label[0,"..y_start..";" .. fgettext("Mapgen-specific flags") .. "]"
|
||||||
end
|
end
|
||||||
|
@ -455,8 +473,8 @@ local function create_world_buttonhandler(this, fields)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local lua_mapgens = core.get_lua_mapgens()
|
||||||
if not is_internal_mapgen then
|
if not is_internal_mapgen then
|
||||||
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"
|
||||||
|
@ -480,6 +498,12 @@ local function create_world_buttonhandler(this, fields)
|
||||||
mgvalleys_spflags = table_to_flags(this.data.flags.valleys),
|
mgvalleys_spflags = table_to_flags(this.data.flags.valleys),
|
||||||
mgflat_spflags = table_to_flags(this.data.flags.flat),
|
mgflat_spflags = table_to_flags(this.data.flags.flat),
|
||||||
}
|
}
|
||||||
|
-- Add the lua-defined mapgen flags
|
||||||
|
for mg, v in pairs(lua_mapgens) do
|
||||||
|
if this.data.flags[mg] ~= nil then
|
||||||
|
settings["lmg_" .. mg .. "_flags"] = table_to_flags(this.data.flags[mg])
|
||||||
|
end
|
||||||
|
end
|
||||||
message = core.create_world(worldname, game.id, settings)
|
message = core.create_world(worldname, game.id, settings)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -564,6 +588,11 @@ function create_create_world_dlg()
|
||||||
flat = core.settings:get_flags("mgflat_spflags"),
|
flat = core.settings:get_flags("mgflat_spflags"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for mg, tab in pairs(core.get_lua_mapgens()) do
|
||||||
|
if retval.data.flags[mg] == nil then
|
||||||
|
retval.data.flags[mg] = tab.lmg_flags
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
|
@ -148,13 +148,21 @@ bool parseModContents(ModSpec &spec)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (info.exists("mg_flags")) {
|
if (info.exists("mg_flags")) {
|
||||||
std::string dep = info.get("mg_flags");
|
std::string mg_flags = info.get("mg_flags");
|
||||||
dep.erase(std::remove_if(dep.begin(), dep.end(),
|
mg_flags.erase(std::remove_if(mg_flags.begin(), mg_flags.end(),
|
||||||
static_cast<int (*)(int)>(&std::isspace)), dep.end());
|
static_cast<int (*)(int)>(&std::isspace)), mg_flags.end());
|
||||||
for (const auto &flag : str_split(dep, ',')) {
|
for (const auto &flag : str_split(mg_flags, ',')) {
|
||||||
spec.mg_flags.insert(flag);
|
spec.mg_flags.insert(flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (info.exists("lmg_flags")) {
|
||||||
|
std::string lmg_flags = info.get("lmg_flags");
|
||||||
|
lmg_flags.erase(std::remove_if(lmg_flags.begin(), lmg_flags.end(),
|
||||||
|
static_cast<int (*)(int)>(&std::isspace)), lmg_flags.end());
|
||||||
|
for (const auto &flag : str_split(lmg_flags, ',')) {
|
||||||
|
spec.lmg_flags.insert(flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.exists("description"))
|
if (info.exists("description"))
|
||||||
|
|
|
@ -41,6 +41,7 @@ struct ModSpec
|
||||||
// lua-defined mapgen only
|
// lua-defined mapgen only
|
||||||
bool is_mapgen = false;
|
bool is_mapgen = false;
|
||||||
std::unordered_set<std::string> mg_flags;
|
std::unordered_set<std::string> mg_flags;
|
||||||
|
std::unordered_set<std::string> lmg_flags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A constructed canonical path to represent this mod's location.
|
* A constructed canonical path to represent this mod's location.
|
||||||
|
|
|
@ -416,6 +416,10 @@ void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
|
||||||
|
|
||||||
mgr.setMapSetting("seed", g_settings->get("fixed_map_seed"));
|
mgr.setMapSetting("seed", g_settings->get("fixed_map_seed"));
|
||||||
|
|
||||||
|
// If there is a lua-defined mapgen and it has flags then add its flags
|
||||||
|
if (lua_mapgen != "" && g_settings->exists("lmg_" + lua_mapgen + "_flags"))
|
||||||
|
mgr.setMapSetting("lmg_" + lua_mapgen + "_flags", g_settings->get("lmg_" + lua_mapgen + "_flags"), true);
|
||||||
|
|
||||||
mgr.makeMapgenParams();
|
mgr.makeMapgenParams();
|
||||||
mgr.saveMapMeta();
|
mgr.saveMapMeta();
|
||||||
}
|
}
|
||||||
|
|
|
@ -718,6 +718,20 @@ int ModApiMainMenu::l_get_lua_mapgens(lua_State *L)
|
||||||
}
|
}
|
||||||
lua_settable(L, top_lvl2);
|
lua_settable(L, top_lvl2);
|
||||||
|
|
||||||
|
lua_pushstring(L, "lmg_flags");
|
||||||
|
if (!mod.lmg_flags.empty()) {
|
||||||
|
lua_newtable(L);
|
||||||
|
int lmg_flags_top = lua_gettop(L);
|
||||||
|
for (const auto &flag : mod.lmg_flags) {
|
||||||
|
lua_pushstring(L, flag.c_str());
|
||||||
|
lua_pushboolean(L, true);
|
||||||
|
lua_settable(L, lmg_flags_top);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
lua_settable(L, top_lvl2);
|
||||||
|
|
||||||
lua_settable(L, top);
|
lua_settable(L, top);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue