diff options
author | kwolekr <kwolekr@minetest.net> | 2014-12-29 12:58:55 -0500 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2014-12-29 12:59:59 -0500 |
commit | 5e2753c712e8f65fa50f4889fc1422393ba21413 (patch) | |
tree | 04aab9306f77497e712ad13ae3445d878280881d /src/script/lua_api | |
parent | ff3cfb746e203ed02160de09b1912b543c5a25f0 (diff) | |
download | minetest-5e2753c712e8f65fa50f4889fc1422393ba21413.tar.gz minetest-5e2753c712e8f65fa50f4889fc1422393ba21413.tar.bz2 minetest-5e2753c712e8f65fa50f4889fc1422393ba21413.zip |
Expose mapgen parameters on scripting init
Add minetest.get_mapgen_params()
Deprecate minetest.register_on_mapgen_init()
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_mapgen.cpp | 48 | ||||
-rw-r--r-- | src/script/lua_api/l_mapgen.h | 4 |
2 files changed, 39 insertions, 13 deletions
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index cccbba5a8..b7d7d096e 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -325,6 +325,31 @@ int ModApiMapgen::l_get_mapgen_object(lua_State *L) return 0; } +int ModApiMapgen::l_get_mapgen_params(lua_State *L) +{ + MapgenParams *params = &getServer(L)->getEmergeManager()->params; + + lua_newtable(L); + + lua_pushstring(L, params->mg_name.c_str()); + lua_setfield(L, -2, "mgname"); + + lua_pushinteger(L, params->seed); + lua_setfield(L, -2, "seed"); + + lua_pushinteger(L, params->water_level); + lua_setfield(L, -2, "water_level"); + + lua_pushinteger(L, params->chunksize); + lua_setfield(L, -2, "chunksize"); + + std::string flagstr = writeFlagString(params->flags, flagdesc_mapgen, (u32)-1); + lua_pushstring(L, flagstr.c_str()); + lua_setfield(L, -2, "flags"); + + return 1; +} + // set_mapgen_params(params) // set mapgen parameters int ModApiMapgen::l_set_mapgen_params(lua_State *L) @@ -332,38 +357,34 @@ int ModApiMapgen::l_set_mapgen_params(lua_State *L) if (!lua_istable(L, 1)) return 0; - EmergeManager *emerge = getServer(L)->getEmergeManager(); - assert(emerge); - - std::string flagstr; + MapgenParams *params = &getServer(L)->getEmergeManager()->params; u32 flags = 0, flagmask = 0; lua_getfield(L, 1, "mgname"); if (lua_isstring(L, -1)) { - emerge->params.mg_name = std::string(lua_tostring(L, -1)); - delete emerge->params.sparams; - emerge->params.sparams = NULL; + params->mg_name = lua_tostring(L, -1); + delete params->sparams; + params->sparams = NULL; } lua_getfield(L, 1, "seed"); if (lua_isnumber(L, -1)) - emerge->params.seed = lua_tointeger(L, -1); + params->seed = lua_tointeger(L, -1); lua_getfield(L, 1, "water_level"); if (lua_isnumber(L, -1)) - emerge->params.water_level = lua_tointeger(L, -1); + params->water_level = lua_tointeger(L, -1); lua_getfield(L, 1, "flagmask"); if (lua_isstring(L, -1)) { - flagstr = lua_tostring(L, -1); - emerge->params.flags &= ~readFlagString(flagstr, flagdesc_mapgen, NULL); + params->flags &= ~readFlagString(lua_tostring(L, -1), flagdesc_mapgen, NULL); errorstream << "set_mapgen_params(): flagmask field is deprecated, " "see lua_api.txt" << std::endl; } if (getflagsfield(L, 1, "flags", flagdesc_mapgen, &flags, &flagmask)) { - emerge->params.flags &= ~flagmask; - emerge->params.flags |= flags; + params->flags &= ~flagmask; + params->flags |= flags; } return 0; @@ -818,6 +839,7 @@ void ModApiMapgen::Initialize(lua_State *L, int top) { API_FCT(get_mapgen_object); + API_FCT(get_mapgen_params); API_FCT(set_mapgen_params); API_FCT(set_noiseparams); API_FCT(set_gen_notify); diff --git a/src/script/lua_api/l_mapgen.h b/src/script/lua_api/l_mapgen.h index 247043a01..e98838470 100644 --- a/src/script/lua_api/l_mapgen.h +++ b/src/script/lua_api/l_mapgen.h @@ -33,6 +33,10 @@ private: // returns the requested object used during map generation static int l_get_mapgen_object(lua_State *L); + // get_mapgen_params() + // returns the currently active map generation parameter set + static int l_get_mapgen_params(lua_State *L); + // set_mapgen_params(params) // set mapgen parameters static int l_set_mapgen_params(lua_State *L); |