1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Prefer C++ in case of conflict and pass title rather than internal name

This commit is contained in:
Xeno333 2025-06-10 21:00:21 -05:00
parent c887425ac4
commit ea0ae5b62b
8 changed files with 93 additions and 20 deletions

2
.gitignore vendored
View file

@ -68,6 +68,8 @@ AppDir
/sounds /sounds
/mods/* /mods/*
!/mods/mods_here.txt !/mods/mods_here.txt
/mapgens/*
!/mapgens/mapgens_here.txt
/worlds/* /worlds/*
!/worlds/worlds_here.txt !/worlds/worlds_here.txt
/clientmods/* /clientmods/*

View file

@ -79,11 +79,22 @@ local mgv6_biomes = {
} }
local function create_world_formspec(dialogdata) local function create_world_formspec(dialogdata)
local current_mapgen = dialogdata.mg local current_mapgen = dialogdata.mg
local mapgens = core.get_mapgen_names() local mapgens = core.get_mapgen_names()
local lua_mapgens = core.get_lua_mapgen_descriptions()
-- This is used to make sure that the internal mapgens are never overwritten by an ill-playing mapgen
local is_internal_mapgen = false
for _, mg in pairs(mapgens) do
if mg == current_mapgen then
is_internal_mapgen = true
end
end
local lua_mapgens = core.get_lua_mapgen_descriptions_and_title()
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
current_mapgen = k
end
mapgens[#mapgens+1] = k mapgens[#mapgens+1] = k
end end
@ -145,7 +156,13 @@ local function create_world_formspec(dialogdata)
selindex = i selindex = i
end end
i = i + 1 i = i + 1
mglist = mglist .. core.formspec_escape(v) .. ","
local mapgen_title = (lua_mapgens[v] or {}).title
if not mapgen_title then
mapgen_title = v
end
mglist = mglist .. core.formspec_escape(mapgen_title) .. ","
end end
if not selindex then if not selindex then
selindex = 1 selindex = 1
@ -155,8 +172,12 @@ local function create_world_formspec(dialogdata)
end end
local current_mapgen_internal = current_mapgen local current_mapgen_internal = current_mapgen
if lua_mapgens[current_mapgen_internal] and current_mapgen == dialogdata.mg then if not is_internal_mapgen then
current_mapgen_internal = "singlenode" -- Select singlenode if using lua-defined mapgen
-- Here we have to make sure it doesn't override an internal mapgen
if lua_mapgens[current_mapgen_internal] ~= nil and (current_mapgen == dialogdata.mg or lua_mapgens[current_mapgen_internal].title == dialogdata.mg) then
current_mapgen_internal = "singlenode"
end
end end
-- The logic of the flag element IDs is as follows: -- The logic of the flag element IDs is as follows:
@ -382,10 +403,24 @@ local function create_world_buttonhandler(this, fields)
local mapgen_internal = this.data.mg local mapgen_internal = this.data.mg
local mapgen = nil local mapgen = nil
local lua_mapgens = core.get_lua_mapgen_descriptions() -- This is used to make sure that the internal mapgens are never overwritten by an ill-playing mapgen
if lua_mapgens[this.data.mg] then local internal_mapgens = core.get_mapgen_names()
mapgen_internal = "singlenode" local is_internal_mapgen = false
mapgen = this.data.mg for _, mg in pairs(internal_mapgens) do
if mg == this.data.mg then
is_internal_mapgen = true
end
end
if not is_internal_mapgen then
local lua_mapgens = core.get_lua_mapgen_descriptions_and_title()
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"
mapgen = name
break
end
end
end end
-- actual names as used by engine -- actual names as used by engine

View file

@ -421,6 +421,7 @@ Mapgen directory structure
├── mapgenname ├── mapgenname
│   ├── mapgen.conf │   ├── mapgen.conf
│   ├── init.lua │   ├── init.lua
│   ├── locale/
│   └── <custom data and code> │   └── <custom data and code>
└── another └── another

View file

@ -109,8 +109,8 @@ 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()` -> map of `[mapgen_name] = mapgen_description` as listed * `core.get_lua_mapgen_descriptions_and_title()` -> map of `[mapgen_name] = {desc = <mapgen_description>, title = <title>}` as listed
in `mapgen.conf`. 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)
* `param`=true: returns path to a newly created temporary file * `param`=true: returns path to a newly created temporary file

View file

@ -88,6 +88,9 @@ bool parseModContents(ModSpec &spec)
else else
spec.deprecation_msgs.push_back("Mods not having a mod.conf file with the name is deprecated."); spec.deprecation_msgs.push_back("Mods not having a mod.conf file with the name is deprecated.");
if (info.exists("title"))
spec.title = info.get("title");
if (info.exists("author")) if (info.exists("author"))
spec.author = info.get("author"); spec.author = info.get("author");

View file

@ -27,6 +27,7 @@ struct ModSpec
std::string author; std::string author;
std::string path; // absolute path on disk std::string path; // absolute path on disk
std::string desc; std::string desc;
std::string title;
int release = 0; int release = 0;
// if normal mod: // if normal mod:

View file

@ -664,18 +664,49 @@ int ModApiMainMenu::l_get_mapgen_names(lua_State *L)
} }
/******************************************************************************/ /******************************************************************************/
int ModApiMainMenu::l_get_lua_mapgen_descriptions(lua_State *L) int ModApiMainMenu::l_get_lua_mapgen_descriptions_and_title(lua_State *L)
{ {
std::vector<ModSpec> addon_mods_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/"));
lua_newtable(L); lua_newtable(L);
for (const auto &mod : addon_mods_in_path) { int top = lua_gettop(L);
// If more than one mapgen use the same title.
std::map<std::string, int> mapgen_title_counts;
for (const auto &mod : mapgens_in_path) {
if (mod.is_mapgen) { if (mod.is_mapgen) {
lua_pushstring(L, mod.desc.c_str()); lua_pushstring(L, mod.name.c_str());
lua_setfield(L, -2, mod.name.c_str());
lua_newtable(L);
int top_lvl2 = lua_gettop(L);
lua_pushstring(L, "desc");
if (mod.title != "")
lua_pushstring(L, mod.desc.c_str());
else
lua_pushnil(L);
lua_settable(L, top_lvl2);
lua_pushstring(L, "title");
if (mod.title != "") {
std::string mapgen_tite = mod.title;
if (mapgen_title_counts.find(mod.title) == mapgen_title_counts.end()) {
mapgen_title_counts[mod.title] = 0;
} else {
mapgen_title_counts[mod.title]++;
mapgen_tite = mapgen_tite + " (" + mod.name + ")";
}
lua_pushstring(L, mapgen_tite.c_str());
} else {
lua_pushnil(L);
}
lua_settable(L, top_lvl2);
lua_settable(L, top);
} }
} }
return 1; return 1;
} }
@ -1077,7 +1108,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); API_FCT(get_lua_mapgen_descriptions_and_title);
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);
@ -1119,7 +1150,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); API_FCT(get_lua_mapgen_descriptions_and_title);
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(lua_State *L); static int l_get_lua_mapgen_descriptions_and_title(lua_State *L);
static int l_get_language(lua_State *L); static int l_get_language(lua_State *L);