mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-26 18:21:04 +00:00
move to lua
This commit is contained in:
parent
90873d62cb
commit
7f1dc29d7d
6 changed files with 25 additions and 48 deletions
|
@ -78,11 +78,21 @@ local mgv6_biomes = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local mapgens_descriptions = {
|
||||||
|
v7 = fgettext("Default mapgen with large complex mountins and plains."),
|
||||||
|
valleys = fgettext("Large valleys with complex terrain and rivers."),
|
||||||
|
carpathian = fgettext("Realistic looking world with vast plains."),
|
||||||
|
v5 = fgettext("Old mapgen."),
|
||||||
|
flat = fgettext("World Flat terrain."),
|
||||||
|
fractal = fgettext("Wold with fractal structure."),
|
||||||
|
singlenode = fgettext("Empty world, use for lua defined mapgens."),
|
||||||
|
v6 = fgettext("Simple mapgen with few features, not recommended."),
|
||||||
|
}
|
||||||
|
|
||||||
local function create_world_formspec(dialogdata)
|
local function create_world_formspec(dialogdata)
|
||||||
|
|
||||||
local current_mg = dialogdata.mg
|
local current_mg = dialogdata.mg
|
||||||
local mapgens = core.get_mapgen_names()
|
local mapgens = core.get_mapgen_names()
|
||||||
local mapgens_descriptions = core.get_mapgen_descriptions()
|
|
||||||
|
|
||||||
local flags = dialogdata.flags
|
local flags = dialogdata.flags
|
||||||
|
|
||||||
|
@ -110,7 +120,6 @@ local function create_world_formspec(dialogdata)
|
||||||
if #allowed_mapgens > 0 then
|
if #allowed_mapgens > 0 then
|
||||||
for i = #mapgens, 1, -1 do
|
for i = #mapgens, 1, -1 do
|
||||||
if table.indexof(allowed_mapgens, mapgens[i]) == -1 then
|
if table.indexof(allowed_mapgens, mapgens[i]) == -1 then
|
||||||
table.remove(mapgens_descriptions, i)
|
|
||||||
table.remove(mapgens, i)
|
table.remove(mapgens, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -119,7 +128,6 @@ local function create_world_formspec(dialogdata)
|
||||||
if #disallowed_mapgens > 0 then
|
if #disallowed_mapgens > 0 then
|
||||||
for i = #mapgens, 1, -1 do
|
for i = #mapgens, 1, -1 do
|
||||||
if table.indexof(disallowed_mapgens, mapgens[i]) > 0 then
|
if table.indexof(disallowed_mapgens, mapgens[i]) > 0 then
|
||||||
table.remove(mapgens_descriptions, i)
|
|
||||||
table.remove(mapgens, i)
|
table.remove(mapgens, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -142,7 +150,6 @@ local function create_world_formspec(dialogdata)
|
||||||
first_mg = v
|
first_mg = v
|
||||||
end
|
end
|
||||||
if current_mg == v then
|
if current_mg == v then
|
||||||
mgdescription = mapgens_descriptions[k]
|
|
||||||
selindex = i
|
selindex = i
|
||||||
end
|
end
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
@ -290,10 +297,12 @@ local function create_world_formspec(dialogdata)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
retval = retval ..
|
if mapgens_descriptions[current_mg] then
|
||||||
"label[0,2;" .. fgettext("Mapgen") .. "]"..
|
retval = retval ..
|
||||||
"dropdown[0,2.5;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]"..
|
"label[0,2;" .. fgettext("Mapgen") .. "]"..
|
||||||
"textarea[0.5,3.2;6,2;;;" .. core.formspec_escape(fgettext(mgdescription)) .. "]"
|
"dropdown[0,2.5;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]"..
|
||||||
|
"textarea[0.5,3.2;6,2;;;" .. mapgens_descriptions[current_mg] .. "]"
|
||||||
|
end
|
||||||
|
|
||||||
-- Warning when making a devtest world
|
-- Warning when making a devtest world
|
||||||
if game.id == "devtest" then
|
if game.id == "devtest" then
|
||||||
|
|
|
@ -109,8 +109,6 @@ 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_mapgen_descriptions([include_hidden=false])` -> table of map generator descriptions,
|
|
||||||
in the same order as returned by `core.get_mapgen_names` registered in the core (possible in async calls)
|
|
||||||
* `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
|
||||||
|
|
|
@ -76,14 +76,14 @@ struct MapgenDesc {
|
||||||
// Of the remaining, v5 last due to age, v7 first due to being the default.
|
// Of the remaining, v5 last due to age, v7 first due to being the default.
|
||||||
// The order of 'enum MapgenType' in mapgen.h must match this order.
|
// The order of 'enum MapgenType' in mapgen.h must match this order.
|
||||||
static MapgenDesc g_reg_mapgens[] = {
|
static MapgenDesc g_reg_mapgens[] = {
|
||||||
{"v7", true, "Default mapgen with large complex mountins and plains."},
|
{"v7", true},
|
||||||
{"valleys", true, "Large valleys with complex terrain and rivers."},
|
{"valleys", true},
|
||||||
{"carpathian", true, "Realistic looking world with vast plains."},
|
{"carpathian", true},
|
||||||
{"v5", true, "Old mapgen."},
|
{"v5", true},
|
||||||
{"flat", true, "World Flat terrain."},
|
{"flat", true},
|
||||||
{"fractal", true, "Wold with fractal structure."},
|
{"fractal", true},
|
||||||
{"singlenode", true, "Empty world, use for lua defined mapgens."},
|
{"singlenode", true},
|
||||||
{"v6", true, "Simple mapgen with few features, not recommended."},
|
{"v6", true},
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(
|
static_assert(
|
||||||
|
@ -208,14 +208,6 @@ void Mapgen::getMapgenNames(std::vector<const char *> *mgnames, bool include_hid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mapgen::getMapgenDescriptions(std::vector<const char *> *mgdescriptions, bool include_hidden)
|
|
||||||
{
|
|
||||||
for (u32 i = 0; i != ARRLEN(g_reg_mapgens); i++) {
|
|
||||||
if (include_hidden || g_reg_mapgens[i].is_user_visible)
|
|
||||||
mgdescriptions->push_back(g_reg_mapgens[i].description);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mapgen::setDefaultSettings(Settings *settings)
|
void Mapgen::setDefaultSettings(Settings *settings)
|
||||||
{
|
{
|
||||||
settings->setDefault("mg_flags", flagdesc_mapgen,
|
settings->setDefault("mg_flags", flagdesc_mapgen,
|
||||||
|
|
|
@ -243,7 +243,6 @@ public:
|
||||||
EmergeParams *emerge);
|
EmergeParams *emerge);
|
||||||
static MapgenParams *createMapgenParams(MapgenType mgtype);
|
static MapgenParams *createMapgenParams(MapgenType mgtype);
|
||||||
static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
|
static void getMapgenNames(std::vector<const char *> *mgnames, bool include_hidden);
|
||||||
static void getMapgenDescriptions(std::vector<const char *> *mgdescriptions, bool include_hidden);
|
|
||||||
static void setDefaultSettings(Settings *settings);
|
static void setDefaultSettings(Settings *settings);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -660,23 +660,6 @@ int ModApiMainMenu::l_get_mapgen_names(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
int ModApiMainMenu::l_get_mapgen_descriptions(lua_State *L)
|
|
||||||
{
|
|
||||||
std::vector<const char *> descriptions;
|
|
||||||
bool include_hidden = lua_isboolean(L, 1) && readParam<bool>(L, 1);
|
|
||||||
Mapgen::getMapgenDescriptions(&descriptions, include_hidden);
|
|
||||||
|
|
||||||
lua_newtable(L);
|
|
||||||
for (size_t i = 0; i != descriptions.size(); i++) {
|
|
||||||
lua_pushstring(L, descriptions[i]);
|
|
||||||
lua_rawseti(L, -2, i + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
int ModApiMainMenu::l_get_user_path(lua_State *L)
|
int ModApiMainMenu::l_get_user_path(lua_State *L)
|
||||||
{
|
{
|
||||||
|
@ -1075,7 +1058,6 @@ 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_mapgen_descriptions);
|
|
||||||
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);
|
||||||
|
@ -1117,7 +1099,6 @@ 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_mapgen_descriptions);
|
|
||||||
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);
|
||||||
|
|
|
@ -51,8 +51,6 @@ private:
|
||||||
|
|
||||||
static int l_get_mapgen_names(lua_State *L);
|
static int l_get_mapgen_names(lua_State *L);
|
||||||
|
|
||||||
static int l_get_mapgen_descriptions(lua_State *L);
|
|
||||||
|
|
||||||
static int l_get_language(lua_State *L);
|
static int l_get_language(lua_State *L);
|
||||||
|
|
||||||
//packages
|
//packages
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue