]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Fix types of get_mapgen_setting_noiseparams (#12025)
authorLars Müller <34514239+appgurueu@users.noreply.github.com>
Fri, 4 Feb 2022 19:28:43 +0000 (20:28 +0100)
committerGitHub <noreply@github.com>
Fri, 4 Feb 2022 19:28:43 +0000 (20:28 +0100)
builtin/mainmenu/dlg_settings_advanced.lua
src/script/common/c_content.cpp
src/script/common/c_converter.cpp
src/script/common/c_converter.h

index 772509670ec394577b2c7199a38bbe7a1d123ff1..83f9054463a0a6add6194260fe0120d21181d063 100644 (file)
@@ -517,24 +517,20 @@ end
 
 local function get_current_np_group_as_string(setting)
        local value = core.settings:get_np_group(setting.name)
-       local t
        if value == nil then
-               t = setting.default
-       else
-               t = value.offset .. ", " ..
-                       value.scale .. ", (" ..
-                       value.spread.x .. ", " ..
-                       value.spread.y .. ", " ..
-                       value.spread.z .. "), " ..
-                       value.seed .. ", " ..
-                       value.octaves .. ", " ..
-                       value.persistence .. ", " ..
-                       value.lacunarity
-               if value.flags ~= "" then
-                       t = t .. ", " .. value.flags
-               end
+               return setting.default
        end
-       return t
+       return ("%g, %g, (%g, %g, %g), %g, %g, %g, %g"):format(
+               value.offset,
+               value.scale,
+               value.spread.x,
+               value.spread.y,
+               value.spread.z,
+               value.seed,
+               value.octaves,
+               value.persistence,
+               value.lacunarity
+       ) .. (value.flags ~= "" and (", " .. value.flags) or "")
 end
 
 local checkboxes = {} -- handle checkboxes events
@@ -667,7 +663,7 @@ local function create_change_setting_formspec(dialogdata)
        elseif setting.type == "v3f" then
                local val = get_current_value(setting)
                local v3f = {}
-               for line in val:gmatch("[+-]?[%d.-e]+") do -- All numeric characters
+               for line in val:gmatch("[+-]?[%d.+-eE]+") do -- All numeric characters
                        table.insert(v3f, line)
                end
 
index 8a5a3fe711fe157e05bca4e598daa9ace0088a96..b6eaa6b13b897acbd7c8c2179a7897266a3f3aaa 100644 (file)
@@ -1697,24 +1697,19 @@ bool read_noiseparams(lua_State *L, int index, NoiseParams *np)
 void push_noiseparams(lua_State *L, NoiseParams *np)
 {
        lua_newtable(L);
-       push_float_string(L, np->offset);
-       lua_setfield(L, -2, "offset");
-       push_float_string(L, np->scale);
-       lua_setfield(L, -2, "scale");
-       push_float_string(L, np->persist);
-       lua_setfield(L, -2, "persistence");
-       push_float_string(L, np->lacunarity);
-       lua_setfield(L, -2, "lacunarity");
-       lua_pushnumber(L, np->seed);
-       lua_setfield(L, -2, "seed");
-       lua_pushnumber(L, np->octaves);
-       lua_setfield(L, -2, "octaves");
+       setfloatfield(L, -1, "offset",      np->offset);
+       setfloatfield(L, -1, "scale",       np->scale);
+       setfloatfield(L, -1, "persist",     np->persist);
+       setfloatfield(L, -1, "persistence", np->persist);
+       setfloatfield(L, -1, "lacunarity",  np->lacunarity);
+       setintfield(  L, -1, "seed",        np->seed);
+       setintfield(  L, -1, "octaves",     np->octaves);
 
        push_flags_string(L, flagdesc_noiseparams, np->flags,
                np->flags);
        lua_setfield(L, -2, "flags");
 
-       push_v3_float_string(L, np->spread);
+       push_v3f(L, np->spread);
        lua_setfield(L, -2, "spread");
 }
 
index 19734b913bf8349d40afa28090b445b05f77399b..716405593b14cd0f7ec7ebb78f2d0a252fb9d7cd 100644 (file)
@@ -73,13 +73,6 @@ static void set_vector_metatable(lua_State *L)
        lua_pop(L, 1);
 }
 
-
-void push_float_string(lua_State *L, float value)
-{
-       auto str = ftos(value);
-       lua_pushstring(L, str.c_str());
-}
-
 void push_v3f(lua_State *L, v3f p)
 {
        lua_createtable(L, 0, 3);
@@ -101,26 +94,6 @@ void push_v2f(lua_State *L, v2f p)
        lua_setfield(L, -2, "y");
 }
 
-void push_v3_float_string(lua_State *L, v3f p)
-{
-       lua_createtable(L, 0, 3);
-       push_float_string(L, p.X);
-       lua_setfield(L, -2, "x");
-       push_float_string(L, p.Y);
-       lua_setfield(L, -2, "y");
-       push_float_string(L, p.Z);
-       lua_setfield(L, -2, "z");
-}
-
-void push_v2_float_string(lua_State *L, v2f p)
-{
-       lua_createtable(L, 0, 2);
-       push_float_string(L, p.X);
-       lua_setfield(L, -2, "x");
-       push_float_string(L, p.Y);
-       lua_setfield(L, -2, "y");
-}
-
 v2s16 read_v2s16(lua_State *L, int index)
 {
        v2s16 p;
index 6ad6f32121ecfd7950d10ff1695042e86e3d56d7..a14eb91861fabffd8bde61443ed02a6d4847e42b 100644 (file)
@@ -118,9 +118,6 @@ std::vector<aabb3f> read_aabb3f_vector  (lua_State *L, int index, f32 scale);
 size_t              read_stringlist     (lua_State *L, int index,
                                          std::vector<std::string> *result);
 
-void                push_float_string   (lua_State *L, float value);
-void                push_v3_float_string(lua_State *L, v3f p);
-void                push_v2_float_string(lua_State *L, v2f p);
 void                push_v2s16          (lua_State *L, v2s16 p);
 void                push_v2s32          (lua_State *L, v2s32 p);
 void                push_v3s16          (lua_State *L, v3s16 p);