diff options
-rw-r--r-- | builtin/mainmenu/dlg_settings_advanced.lua | 291 | ||||
-rw-r--r-- | builtin/mainmenu/generate_from_settingtypes.lua | 39 | ||||
-rw-r--r-- | builtin/settingtypes.txt | 190 | ||||
-rw-r--r-- | doc/lua_api.txt | 14 | ||||
-rw-r--r-- | src/script/common/c_content.cpp | 10 | ||||
-rw-r--r-- | src/script/common/c_converter.cpp | 29 | ||||
-rw-r--r-- | src/script/common/c_converter.h | 3 | ||||
-rw-r--r-- | src/script/lua_api/l_settings.cpp | 38 | ||||
-rw-r--r-- | src/script/lua_api/l_settings.h | 7 |
9 files changed, 476 insertions, 145 deletions
diff --git a/builtin/mainmenu/dlg_settings_advanced.lua b/builtin/mainmenu/dlg_settings_advanced.lua index bc942c472..b784a295e 100644 --- a/builtin/mainmenu/dlg_settings_advanced.lua +++ b/builtin/mainmenu/dlg_settings_advanced.lua @@ -25,6 +25,10 @@ local CHAR_CLASSES = { FLAGS = "[%w_%-%.,]", } +local function flags_to_table(flags) + return flags:gsub("%s+", ""):split(",", true) -- Remove all spaces and split +end + -- returns error message, or nil local function parse_setting_line(settings, line, read_all, base_level, allow_secure) -- comment @@ -111,7 +115,7 @@ local function parse_setting_line(settings, line, read_all, base_level, allow_se return end - if setting_type == "string" or setting_type == "noise_params" + if setting_type == "string" or setting_type == "key" or setting_type == "v3f" then local default = remaining_line:match("^(.*)$") @@ -133,6 +137,60 @@ local function parse_setting_line(settings, line, read_all, base_level, allow_se return end + if setting_type == "noise_params_2d" + or setting_type == "noise_params_3d" then + local default = remaining_line:match("^(.*)$") + + if not default then + return "Invalid string setting" + end + + local values = {} + local ti = 1 + local index = 1 + for line in default:gmatch("[+-]?[%d.-e]+") do -- All numeric characters + index = default:find("[+-]?[%d.-e]+", index) + line:len() + table.insert(values, line) + ti = ti + 1 + if ti > 9 then + break + end + end + index = default:find("[^, ]", index) + local flags = "" + if index then + flags = default:sub(index) + default = default:sub(1, index - 3) -- Make sure no flags in single-line format + end + table.insert(values, flags) + + table.insert(settings, { + name = name, + readable_name = readable_name, + type = setting_type, + default = default, + default_table = { + offset = values[1], + scale = values[2], + spread = { + x = values[3], + y = values[4], + z = values[5] + }, + seed = values[6], + octaves = values[7], + persistence = values[8], + lacunarity = values[9], + flags = values[10] + }, + values = values, + comment = current_comment, + noise_params = true, + flags = flags_to_table("defaults,eased,absvalue") + }) + return + end + if setting_type == "bool" then if remaining_line ~= "false" and remaining_line ~= "true" then return "Invalid boolean setting" @@ -236,7 +294,7 @@ local function parse_setting_line(settings, line, read_all, base_level, allow_se readable_name = readable_name, type = "flags", default = default, - possible = possible, + possible = flags_to_table(possible), comment = current_comment, }) return @@ -430,11 +488,61 @@ local function get_current_value(setting) return value end +local function get_current_np_group(setting) + local value = core.settings:get_np_group(setting.name) + local t = {} + if value == nil then + t = setting.values + else + table.insert(t, value.offset) + table.insert(t, value.scale) + table.insert(t, value.spread.x) + table.insert(t, value.spread.y) + table.insert(t, value.spread.z) + table.insert(t, value.seed) + table.insert(t, value.octaves) + table.insert(t, value.persistence) + table.insert(t, value.lacunarity) + table.insert(t, value.flags) + end + return t +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 .. ", " .. + value.flags + end + return t +end + +local checkboxes = {} -- handle checkboxes events + local function create_change_setting_formspec(dialogdata) local setting = settings[selected_setting] - local formspec = "size[10,5.2,true]" .. - "button[5,4.5;2,1;btn_done;" .. fgettext("Save") .. "]" .. - "button[3,4.5;2,1;btn_cancel;" .. fgettext("Cancel") .. "]" .. + local height = 5.2 + if setting.type == "noise_params_2d" or setting.type == "noise_params_3d" then + -- Three flags, checkboxes on 2 columns, with a vertical space of 1/2 unit + height = 8.7 + elseif setting.type == "flags" then + -- Checkboxes on 2 columns, with a vertical space of 1/2 unit + height = 5.2 + math.ceil(#setting.possible / 2) / 2 + end + local formspec = "size[10," .. height .. ",true]" .. + "button[5," .. height - 0.7 .. ";2,1;btn_done;" .. fgettext("Save") .. "]" .. + "button[3," .. height - 0.7 .. ";2,1;btn_cancel;" .. fgettext("Cancel") .. "]" .. "tablecolumns[color;text]" .. "tableoptions[background=#00000000;highlight=#00000000;border=false]" .. "table[0,0;10,3;info;" @@ -459,21 +567,6 @@ local function create_change_setting_formspec(dialogdata) formspec = formspec .. "," .. core.formspec_escape(comment_line) .. "," end - if setting.type == "flags" then - formspec = formspec .. ",," - .. "," .. fgettext("Please enter a comma seperated list of flags.") .. "," - .. "," .. fgettext("Possible values are: ") - .. core.formspec_escape(setting.possible:gsub(",", ", ")) .. "," - elseif setting.type == "noise_params" then - formspec = formspec .. ",," - .. "," .. fgettext("Format:") .. "," - .. "," .. fgettext("<offset>, <scale>, (<spreadX>, <spreadY>, <spreadZ>),") .. "," - .. "," .. fgettext("<seed>, <octaves>, <persistence>, <lacunarity>") .. "," - elseif setting.type == "v3f" then - formspec = formspec .. ",," - .. "," .. fgettext_ne("Format is 3 numbers separated by commas and inside brackets.") .. "," - end - formspec = formspec:sub(1, -2) -- remove trailing comma formspec = formspec .. ";1]" @@ -514,8 +607,91 @@ local function create_change_setting_formspec(dialogdata) .. core.formspec_escape(current_value) .. "]" .. "button[8,3.75;2,1;btn_browser_" .. setting.type .. ";" .. fgettext("Browse") .. "]" + elseif setting.type == "noise_params_2d" or setting.type == "noise_params_3d" then + local t = get_current_np_group(setting) + local dimension = 3 + if setting.type == "noise_params_2d" then + dimension = 2 + end + + formspec = formspec + .. "label[0,2.5;(" .. dimension .. "D Noise)]" + .. "field[0.5,4;3.3,1;te_offset;Offset;" -- Offset + .. core.formspec_escape(t[1] or "") .. "]" + .. "field[3.8,4;3.3,1;te_scale;Scale;" -- Scale + .. core.formspec_escape(t[2] or "") .. "]" + .. "field[7.1,4;3.3,1;te_seed;Seed;" -- Seed + .. core.formspec_escape(t[6] or "") .. "]" + .. "label[0.5,4.7;Spread]" -- Spread + .. "field[2.0,5;2.8,1;te_spreadx;X;" + .. core.formspec_escape(t[3] or "") .. "]" + .. "field[4.8,5;2.8,1;te_spready;Y;" + .. core.formspec_escape(t[4] or "") .. "]" + .. "field[7.6,5;2.8,1;te_spreadz;Z;" + .. core.formspec_escape(t[5] or "") .. "]" + .. "field[0.5,6;3.3,1;te_octaves;Octaves;" -- Octaves + .. core.formspec_escape(t[7] or "") .. "]" + .. "field[3.8,6;3.3,1;te_persist;Persistance;" -- Persistance + .. core.formspec_escape(t[8] or "") .. "]" + .. "field[7.1,6;3.3,1;te_lacun;Lacunarity;" -- Lacunarity + .. core.formspec_escape(t[9] or "") .. "]" + + local enabled_flags = flags_to_table(t[10]) + local flags = {} + for _, name in ipairs(enabled_flags) do + -- Index by name, to avoid iterating over all enabled_flags for every possible flag. + flags[name] = true + end + -- Flags + formspec = formspec + .. "checkbox[0.5,6.5;cb_defaults;defaults;" -- defaults + .. tostring(flags["defaults"] == true) .. "]" -- to get false if nil + .. "checkbox[5,6.5;cb_eased;eased;" -- eased + .. tostring(flags["eased"] == true) .. "]" + .. "checkbox[5,7.0;cb_absvalue;absvalue;" -- absvalue + .. tostring(flags["absvalue"] == true) .. "]" + + elseif setting.type == "v3f" then + local val = get_current_value(setting) + local v3f = {} + for line in val:gmatch("[+-]?[%d.-e]+") do -- All numeric characters + table.insert(v3f, line) + end + + formspec = formspec + .. "field[0.5,4;3.3,1;te_x;X;" -- X + .. core.formspec_escape(v3f[1] or "") .. "]" + .. "field[3.8,4;3.3,1;te_y;Y;" -- Y + .. core.formspec_escape(v3f[2] or "") .. "]" + .. "field[7.1,4;3.3,1;te_z;Z;" -- Z + .. core.formspec_escape(v3f[3] or "") .. "]" + + elseif setting.type == "flags" then + local enabled_flags = flags_to_table(get_current_value(setting)) + local flags = {} + for _, name in ipairs(enabled_flags) do + -- Index by name, to avoid iterating over all enabled_flags for every possible flag. + flags[name] = true + end + local flags_count = #setting.possible + for i, name in ipairs(setting.possible) do + local x = 0.5 + local y = 3.5 + i / 2 + if i - 1 >= flags_count / 2 then -- 2nd column + x = 5 + y = y - flags_count / 4 + end + local checkbox_name = "cb_" .. name + local is_enabled = flags[name] == true -- to get false if nil + checkboxes[checkbox_name] = is_enabled + formspec = formspec .. "checkbox[" + .. x .. "," .. y + .. ";" .. checkbox_name .. ";" + .. name .. ";" .. tostring(is_enabled) .. "]" + end + else - -- TODO: fancy input for float, int, flags, noise_params, v3f + -- TODO: fancy input for float, int local width = 10 local text = get_current_value(setting) if dialogdata.error_message then @@ -535,8 +711,8 @@ local function create_change_setting_formspec(dialogdata) end local function handle_change_setting_buttons(this, fields) + local setting = settings[selected_setting] if fields["btn_done"] or fields["key_enter"] then - local setting = settings[selected_setting] if setting.type == "bool" then local new_value = fields["dd_setting_value"] -- Note: new_value is the actual (translated) value shown in the dropdown @@ -579,17 +755,49 @@ local function handle_change_setting_buttons(this, fields) core.settings:set(setting.name, new_value) elseif setting.type == "flags" then - local new_value = fields["te_setting_value"] - for _,value in ipairs(new_value:split(",", true)) do - value = value:trim() - local possible = "," .. setting.possible .. "," - if not possible:find("," .. value .. ",", 0, true) then - this.data.error_message = fgettext_ne("\"$1\" is not a valid flag.", value) - this.data.entered_text = fields["te_setting_value"] - core.update_formspec(this:get_formspec()) - return true + local values = {} + for _, name in ipairs(setting.possible) do + if checkboxes["cb_" .. name] then + table.insert(values, name) + end + end + + checkboxes = {} + + local new_value = table.concat(values, ", ") + core.settings:set(setting.name, new_value) + + elseif setting.type == "noise_params_2d" or setting.type == "noise_params_3d" then + local np_flags = {} + for _, name in ipairs(setting.flags) do + if checkboxes["cb_" .. name] then + table.insert(np_flags, name) end end + + checkboxes = {} + + local new_value = { + offset = fields["te_offset"], + scale = fields["te_scale"], + spread = { + x = fields["te_spreadx"], + y = fields["te_spready"], + z = fields["te_spreadz"] + }, + seed = fields["te_seed"], + octaves = fields["te_octaves"], + persistence = fields["te_persist"], + lacunarity = fields["te_lacun"], + flags = table.concat(np_flags, ", ") + } + core.settings:set_np_group(setting.name, new_value) + + elseif setting.type == "v3f" then + local new_value = "(" + .. fields["te_x"] .. ", " + .. fields["te_y"] .. ", " + .. fields["te_z"] .. ")" core.settings:set(setting.name, new_value) else @@ -621,6 +829,16 @@ local function handle_change_setting_buttons(this, fields) core.update_formspec(this:get_formspec()) end + if setting.type == "flags" + or setting.type == "noise_params_2d" + or setting.type == "noise_params_3d" then + for name, value in pairs(fields) do + if name:sub(1, 3) == "cb_" then + checkboxes[name] = value == "true" + end + end + end + return false end @@ -659,6 +877,10 @@ local function create_settings_formspec(tabview, name, tabdata) elseif entry.type == "key" then -- ignore key settings, since we have a special dialog for them + elseif entry.type == "noise_params_2d" or entry.type == "noise_params_3d" then + formspec = formspec .. "," .. (current_level + 1) .. "," .. core.formspec_escape(name) .. "," + .. core.formspec_escape(get_current_np_group_as_string(entry)) .. "," + else formspec = formspec .. "," .. (current_level + 1) .. "," .. core.formspec_escape(name) .. "," .. core.formspec_escape(get_current_value(entry)) .. "," @@ -743,7 +965,12 @@ local function handle_settings_buttons(this, fields, tabname, tabdata) if fields["btn_restore"] then local setting = settings[selected_setting] if setting and setting.type ~= "category" then - core.settings:set(setting.name, setting.default) + if setting.type == "noise_params_2d" + or setting.type == "noise_params_3d" then + core.settings:set_np_group(setting.name, setting.default_table) + else + core.settings:set(setting.name, setting.default) + end core.settings:write() core.update_formspec(this:get_formspec()) end diff --git a/builtin/mainmenu/generate_from_settingtypes.lua b/builtin/mainmenu/generate_from_settingtypes.lua index 6c9ba27fb..9b36843e1 100644 --- a/builtin/mainmenu/generate_from_settingtypes.lua +++ b/builtin/mainmenu/generate_from_settingtypes.lua @@ -22,6 +22,20 @@ local minetest_example_header = [[ ]] +local group_format_template = [[ +# %s = { +# offset = %s, +# scale = %s, +# spread = (%s, %s, %s), +# seed = %s, +# octaves = %s, +# persistence = %s, +# lacunarity = %s, +# flags = "%s" +# } + +]] + local function create_minetest_conf_example() local result = { minetest_example_header } for _, entry in ipairs(settings) do @@ -33,6 +47,12 @@ local function create_minetest_conf_example() insert(result, "# " .. entry.name .. "\n\n") end else + local group_format = false + if entry.noise_params and entry.values then + if entry.type == "noise_params_2d" or entry.type == "noise_params_3d" then + group_format = true + end + end if entry.comment ~= "" then for _, comment_line in ipairs(entry.comment:split("\n", true)) do insert(result, "# " .. comment_line .. "\n") @@ -45,18 +65,25 @@ local function create_minetest_conf_example() if entry.max then insert(result, " max: " .. entry.max) end - if entry.values then + if entry.values and entry.noise_params == nil then insert(result, " values: " .. concat(entry.values, ", ")) end if entry.possible then - insert(result, " possible values: " .. entry.possible:gsub(",", ", ")) + insert(result, " possible values: " .. concat(entry.possible, ", ")) end insert(result, "\n") - local append - if entry.default ~= "" then - append = " " .. entry.default + if group_format == true then + insert(result, sprintf(group_format_template, entry.name, entry.values[1], + entry.values[2], entry.values[3], entry.values[4], entry.values[5], + entry.values[6], entry.values[7], entry.values[8], entry.values[9], + entry.values[10])) + else + local append + if entry.default ~= "" then + append = " " .. entry.default + end + insert(result, sprintf("# %s =%s\n\n", entry.name, append or "")) end - insert(result, sprintf("# %s =%s\n\n", entry.name, append or "")) end end return concat(result) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 7ebee9424..ad88b97d0 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -15,7 +15,9 @@ # - filepath # - key (will be ignored in GUI, since a special key change dialog exists) # - flags -# - noise_params +# - noise_params_2d +# - noise_params_3d +# - v3f # # `type_args` can be: # * int: @@ -39,8 +41,15 @@ # * flags: # Flags are always separated by comma without spaces. # - default possible_flags -# * noise_params: -# TODO: these are currently treated like strings +# * noise_params_2d: +# Format is <offset>, <scale>, (<spreadX>, <spreadY>, <spreadZ>), <seed>, <octaves>, <persistance>, <lacunarity>[, <default flags>] +# - default +# * noise_params_3d: +# Format is <offset>, <scale>, (<spreadX>, <spreadY>, <spreadZ>), <seed>, <octaves>, <persistance>, <lacunarity>[, <default flags>] +# - default +# * v3f: +# Format is (<X>, <Y>, <Z>) +# - default # # Comments directly above a setting are bound to this setting. # All other comments are ignored. @@ -1239,7 +1248,7 @@ mapgen_limit (Map generation limit) int 31000 0 31000 # Global map generation attributes. # In Mapgen v6 the 'decorations' flag controls all decorations except trees # and junglegrass, in all other mapgens this flag controls all decorations. -# Flags that are not specified in the flag string are not modified from the default. +# Flags that are not enabled are not modified from the default. # Flags starting with 'no' are used to explicitly disable them. mg_flags (Mapgen flags) flags caves,dungeons,light,decorations caves,dungeons,light,decorations,nocaves,nodungeons,nolight,nodecorations @@ -1249,21 +1258,21 @@ projecting_dungeons (Projecting dungeons) bool true [*Biome API temperature and humidity noise parameters] # Temperature variation for biomes. -mg_biome_np_heat (Heat noise) noise_params 50, 50, (1000, 1000, 1000), 5349, 3, 0.5, 2.0 +mg_biome_np_heat (Heat noise) noise_params_2d 50, 50, (1000, 1000, 1000), 5349, 3, 0.5, 2.0, eased # Small-scale temperature variation for blending biomes on borders. -mg_biome_np_heat_blend (Heat blend noise) noise_params 0, 1.5, (8, 8, 8), 13, 2, 1.0, 2.0 +mg_biome_np_heat_blend (Heat blend noise) noise_params_2d 0, 1.5, (8, 8, 8), 13, 2, 1.0, 2.0, eased # Humidity variation for biomes. -mg_biome_np_humidity (Humidity noise) noise_params 50, 50, (1000, 1000, 1000), 842, 3, 0.5, 2.0 +mg_biome_np_humidity (Humidity noise) noise_params_2d 50, 50, (1000, 1000, 1000), 842, 3, 0.5, 2.0, eased # Small-scale humidity variation for blending biomes on borders. -mg_biome_np_humidity_blend (Humidity blend noise) noise_params 0, 1.5, (8, 8, 8), 90003, 2, 1.0, 2.0 +mg_biome_np_humidity_blend (Humidity blend noise) noise_params_2d 0, 1.5, (8, 8, 8), 90003, 2, 1.0, 2.0, eased [*Mapgen V5] # Map generation attributes specific to Mapgen v5. -# Flags that are not specified in the flag string are not modified from the default. +# Flags that are not enabled are not modified from the default. # Flags starting with 'no' are used to explicitly disable them. mgv5_spflags (Mapgen V5 specific flags) flags caverns caverns,nocaverns @@ -1288,39 +1297,26 @@ mgv5_cavern_threshold (Cavern threshold) float 0.7 [**Noises] # Variation of biome filler depth. -mgv5_np_filler_depth (Filler depth noise) noise_params 0, 1, (150, 150, 150), 261, 4, 0.7, 2.0 +mgv5_np_filler_depth (Filler depth noise) noise_params_2d 0, 1, (150, 150, 150), 261, 4, 0.7, 2.0, eased # Variation of terrain vertical scale. # When noise is < -0.55 terrain is near-flat. -mgv5_np_factor (Factor noise) noise_params 0, 1, (250, 250, 250), 920381, 3, 0.45, 2.0 +mgv5_np_factor (Factor noise) noise_params_2d 0, 1, (250, 250, 250), 920381, 3, 0.45, 2.0, eased # Y-level of average terrain surface. -mgv5_np_height (Height noise) noise_params 0, 10, (250, 250, 250), 84174, 4, 0.5, 2.0 +mgv5_np_height (Height noise) noise_params_2d 0, 10, (250, 250, 250), 84174, 4, 0.5, 2.0, eased # First of 2 3D noises that together define tunnels. -mgv5_np_cave1 (Cave1 noise) noise_params 0, 12, (50, 50, 50), 52534, 4, 0.5, 2.0 +mgv5_np_cave1 (Cave1 noise) noise_params_3d 0, 12, (50, 50, 50), 52534, 4, 0.5, 2.0 # Second of 2 3D noises that together define tunnels. -mgv5_np_cave2 (Cave2 noise) noise_params 0, 12, (50, 50, 50), 10325, 4, 0.5, 2.0 +mgv5_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (50, 50, 50), 10325, 4, 0.5, 2.0 # 3D noise defining giant caverns. -mgv5_np_cavern (Cavern noise) noise_params 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0 +mgv5_np_cavern (Cavern noise) noise_params_3d 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0 -# TODO -# Noise parameters in group format, unsupported by advanced settings -# menu but settable in minetest.conf. -# See documentation of noise parameter formats in minetest.conf.example. # 3D noise defining terrain. -#mgv5_np_ground = { -# offset = 0 -# scale = 40 -# spread = (80, 80, 80) -# seed = 983240 -# octaves = 4 -# persistence = 0.55 -# lacunarity = 2.0 -# flags = "eased" -#} +mgv5_np_ground (Ground noise) noise_params_3d 0, 40, (80, 80, 80), 983240, 4, 0.55, 2.0, eased [*Mapgen V6] @@ -1328,7 +1324,7 @@ mgv5_np_cavern (Cavern noise) noise_params 0, 1, (384, 128, 384), 723, 5, 0.63, # The 'snowbiomes' flag enables the new 5 biome system. # When the new biome system is enabled jungles are automatically enabled and # the 'jungles' flag is ignored. -# Flags that are not specified in the flag string are not modified from the default. +# Flags that are not enabled are not modified from the default. # Flags starting with 'no' are used to explicitly disable them. mgv6_spflags (Mapgen V6 specific flags) flags jungles,biomeblend,mudflow,snowbiomes,trees jungles,biomeblend,mudflow,snowbiomes,flat,trees,nojungles,nobiomeblend,nomudflow,nosnowbiomes,noflat,notrees @@ -1342,43 +1338,43 @@ mgv6_freq_beach (Beach noise threshold) float 0.15 [**Noises] # Y-level of lower terrain and lakebeds. -mgv6_np_terrain_base (Terrain base noise) noise_params -4, 20, (250, 250, 250), 82341, 5, 0.6, 2.0 +mgv6_np_terrain_base (Terrain base noise) noise_params_2d -4, 20, (250, 250, 250), 82341, 5, 0.6, 2.0, eased # Y-level of higher (cliff-top) terrain. -mgv6_np_terrain_higher (Terrain higher noise) noise_params 20, 16, (500, 500, 500), 85039, 5, 0.6, 2.0 +mgv6_np_terrain_higher (Terrain higher noise) noise_params_2d 20, 16, (500, 500, 500), 85039, 5, 0.6, 2.0, eased # Varies steepness of cliffs. -mgv6_np_steepness (Steepness noise) noise_params 0.85, 0.5, (125, 125, 125), -932, 5, 0.7, 2.0 +mgv6_np_steepness (Steepness noise) noise_params_2d 0.85, 0.5, (125, 125, 125), -932, 5, 0.7, 2.0, eased # Defines areas of 'terrain_higher' (cliff-top terrain). -mgv6_np_height_select (Height select noise) noise_params 0.5, 1, (250, 250, 250), 4213, 5, 0.69, 2.0 +mgv6_np_height_select (Height select noise) noise_params_2d 0.5, 1, (250, 250, 250), 4213, 5, 0.69, 2.0, eased # Varies depth of biome surface nodes. -mgv6_np_mud (Mud noise) noise_params 4, 2, (200, 200, 200), 91013, 3, 0.55, 2.0 +mgv6_np_mud (Mud noise) noise_params_2d 4, 2, (200, 200, 200), 91013, 3, 0.55, 2.0, eased # Defines areas with sandy beaches. -mgv6_np_beach (Beach noise) noise_params 0, 1, (250, 250, 250), 59420, 3, 0.50, 2.0 +mgv6_np_beach (Beach noise) noise_params_2d 0, 1, (250, 250, 250), 59420, 3, 0.50, 2.0, eased # Temperature variation for biomes. -mgv6_np_biome (Biome noise) noise_params 0, 1, (500, 500, 500), 9130, 3, 0.50, 2.0 +mgv6_np_biome (Biome noise) noise_params_2d 0, 1, (500, 500, 500), 9130, 3, 0.50, 2.0, eased # Variation of number of caves. -mgv6_np_cave (Cave noise) noise_params 6, 6, (250, 250, 250), 34329, 3, 0.50, 2.0 +mgv6_np_cave (Cave noise) noise_params_2d 6, 6, (250, 250, 250), 34329, 3, 0.50, 2.0, eased # Humidity variation for biomes. -mgv6_np_humidity (Humidity noise) noise_params 0.5, 0.5, (500, 500, 500), 72384, 3, 0.50, 2.0 +mgv6_np_humidity (Humidity noise) noise_params_2d 0.5, 0.5, (500, 500, 500), 72384, 3, 0.50, 2.0, eased # Defines tree areas and tree density. -mgv6_np_trees (Trees noise) noise_params 0, 1, (125, 125, 125), 2, 4, 0.66, 2.0 +mgv6_np_trees (Trees noise) noise_params_2d 0, 1, (125, 125, 125), 2, 4, 0.66, 2.0, eased # Defines areas where trees have apples. -mgv6_np_apple_trees (Apple trees noise) noise_params 0, 1, (100, 100, 100), 342902, 3, 0.45, 2.0 +mgv6_np_apple_trees (Apple trees noise) noise_params_2d 0, 1, (100, 100, 100), 342902, 3, 0.45, 2.0, eased [*Mapgen V7] # Map generation attributes specific to Mapgen v7. # 'ridges' enables the rivers. -# Flags that are not specified in the flag string are not modified from the default. +# Flags that are not enabled are not modified from the default. # Flags starting with 'no' are used to explicitly disable them. mgv7_spflags (Mapgen V7 specific flags) flags mountains,ridges,nofloatlands,caverns mountains,ridges,floatlands,caverns,nomountains,noridges,nofloatlands,nocaverns @@ -1419,54 +1415,54 @@ mgv7_cavern_threshold (Cavern threshold) float 0.7 [**Noises] # Y-level of higher (cliff-top) terrain. -mgv7_np_terrain_base (Terrain base noise) noise_params 4, 70, (600, 600, 600), 82341, 5, 0.6, 2.0 +mgv7_np_terrain_base (Terrain base noise) noise_params_2d 4, 70, (600, 600, 600), 82341, 5, 0.6, 2.0, eased # Y-level of lower terrain and lakebeds. -mgv7_np_terrain_alt (Terrain alt noise) noise_params 4, 25, (600, 600, 600), 5934, 5, 0.6, 2.0 +mgv7_np_terrain_alt (Terrain alt noise) noise_params_2d 4, 25, (600, 600, 600), 5934, 5, 0.6, 2.0, eased # Varies roughness of terrain. # Defines the 'persistence' value for terrain_base and terrain_alt noises. -mgv7_np_terrain_persist (Terrain persistence noise) noise_params 0.6, 0.1, (2000, 2000, 2000), 539, 3, 0.6, 2.0 +mgv7_np_terrain_persist (Terrain persistence noise) noise_params_2d 0.6, 0.1, (2000, 2000, 2000), 539, 3, 0.6, 2.0, eased # Defines areas of higher (cliff-top) terrain and affects steepness of cliffs. -mgv7_np_height_select (Height select noise) noise_params -8, 16, (500, 500, 500), 4213, 6, 0.7, 2.0 +mgv7_np_height_select (Height select noise) noise_params_2d -8, 16, (500, 500, 500), 4213, 6, 0.7, 2.0, eased # Variation of biome filler depth. -mgv7_np_filler_depth (Filler depth noise) noise_params 0, 1.2, (150, 150, 150), 261, 3, 0.7, 2.0 +mgv7_np_filler_depth (Filler depth noise) noise_params_2d 0, 1.2, (150, 150, 150), 261, 3, 0.7, 2.0, eased # Variation of maximum mountain height (in nodes). -mgv7_np_mount_height (Mountain height noise) noise_params 256, 112, (1000, 1000, 1000), 72449, 3, 0.6, 2.0 +mgv7_np_mount_height (Mountain height noise) noise_params_2d 256, 112, (1000, 1000, 1000), 72449, 3, 0.6, 2.0, eased # Defines large-scale river channel structure. -mgv7_np_ridge_uwater (Ridge underwater noise) noise_params 0, 1, (1000, 1000, 1000), 85039, 5, 0.6, 2.0 +mgv7_np_ridge_uwater (Ridge underwater noise) noise_params_2d 0, 1, (1000, 1000, 1000), 85039, 5, 0.6, 2.0, eased # Defines areas of floatland smooth terrain. # Smooth floatlands occur when noise > 0. -mgv7_np_floatland_base (Floatland base noise) noise_params -0.6, 1.5, (600, 600, 600), 114, 5, 0.6, 2.0 +mgv7_np_floatland_base (Floatland base noise) noise_params_2d -0.6, 1.5, (600, 600, 600), 114, 5, 0.6, 2.0, eased # Variation of hill height and lake depth on floatland smooth terrain. -mgv7_np_float_base_height (Floatland base height noise) noise_params 48, 24, (300, 300, 300), 907, 4, 0.7, 2.0 +mgv7_np_float_base_height (Floatland base height noise) noise_params_2d 48, 24, (300, 300, 300), 907, 4, 0.7, 2.0, eased # 3D noise defining mountain structure and height. # Also defines structure of floatland mountain terrain. -mgv7_np_mountain (Mountain noise) noise_params -0.6, 1, (250, 350, 250), 5333, 5, 0.63, 2.0 +mgv7_np_mountain (Mountain noise) noise_params_3d -0.6, 1, (250, 350, 250), 5333, 5, 0.63, 2.0 # 3D noise defining structure of river canyon walls. -mgv7_np_ridge (Ridge noise) noise_params 0, 1, (100, 100, 100), 6467, 4, 0.75, 2.0 +mgv7_np_ridge (Ridge noise) noise_params_3d 0, 1, (100, 100, 100), 6467, 4, 0.75, 2.0 # 3D noise defining giant caverns. -mgv7_np_cavern (Cavern noise) noise_params 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0 +mgv7_np_cavern (Cavern noise) noise_params_3d 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0 # First of 2 3D noises that together define tunnels. -mgv7_np_cave1 (Cave1 noise) noise_params 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0 +mgv7_np_cave1 (Cave1 noise) noise_params_3d 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0 # Second of 2 3D noises that together define tunnels. -mgv7_np_cave2 (Cave2 noise) noise_params 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0 +mgv7_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0 [*Mapgen Carpathian] # Map generation attributes specific to Mapgen Carpathian. -# Flags that are not specified in the flag string are not modified from the default. +# Flags that are not enabled are not modified from the default. # Flags starting with 'no' are used to explicitly disable them. mgcarpathian_spflags (Mapgen Carpathian specific flags) flags caverns caverns,nocaverns @@ -1491,58 +1487,58 @@ mgcarpathian_cavern_threshold (Cavern threshold) float 0.7 [**Noises] # 2D noise that defines the base ground level. -mgcarpathian_np_base (Base ground noise) noise_params 12, 1, (2557, 2557, 2557), 6538, 4, 0.8, 0.5 +mgcarpathian_np_base (Base ground noise) noise_params_2d 12, 1, (2557, 2557, 2557), 6538, 4, 0.8, 0.5, eased # Variation of biome filler depth. -mgcarpathian_np_filler_depth (Filler depth noise) noise_params 0, 1, (128, 128, 128), 261, 3, 0.7, 2.0 +mgcarpathian_np_filler_depth (Filler depth noise) noise_params_2d 0, 1, (128, 128, 128), 261, 3, 0.7, 2.0, eased -# First of 4 3D noises that together define hill/mountain range height. -mgcarpathian_np_height1 (Hilliness1 noise) noise_params 0, 5, (251, 251, 251), 9613, 5, 0.5, 2.0 +# First of 4 2D noises that together define hill/mountain range height. +mgcarpathian_np_height1 (Hilliness1 noise) noise_params_2d 0, 5, (251, 251, 251), 9613, 5, 0.5, 2.0, eased -# Second of 4 3D noises that together define hill/mountain range height. -mgcarpathian_np_height2 (Hilliness2 noise) noise_params 0, 5, (383, 383, 383), 1949, 5, 0.5, 2.0 +# Second of 4 2D noises that together define hill/mountain range height. +mgcarpathian_np_height2 (Hilliness2 noise) noise_params_2d 0, 5, (383, 383, 383), 1949, 5, 0.5, 2.0, eased -# Third of 4 3D noises that together define hill/mountain range height. -mgcarpathian_np_height3 (Hilliness3 noise) noise_params 0, 5, (509, 509, 509), 3211, 5, 0.5, 2.0 +# Third of 4 2D noises that together define hill/mountain range height. +mgcarpathian_np_height3 (Hilliness3 noise) noise_params_2d 0, 5, (509, 509, 509), 3211, 5, 0.5, 2.0, eased -# Fourth of 4 3D noises that together define hill/mountain range height. -mgcarpathian_np_height4 (Hilliness4 noise) noise_params 0, 5, (631, 631, 631), 1583, 5, 0.5, 2.0 +# Fourth of 4 2D noises that together define hill/mountain range height. +mgcarpathian_np_height4 (Hilliness4 noise) noise_params_2d 0, 5, (631, 631, 631), 1583, 5, 0.5, 2.0, eased # 2D noise that controls the size/occurance of rolling hills. -mgcarpathian_np_hills_terrain (Rolling hills spread noise) noise_params 1, 1, (1301, 1301, 1301), 1692, 3, 0.5, 2.0 +mgcarpathian_np_hills_terrain (Rolling hills spread noise) noise_params_2d 1, 1, (1301, 1301, 1301), 1692, 3, 0.5, 2.0, eased # 2D noise that controls the size/occurance of ridged mountain ranges. -mgcarpathian_np_ridge_terrain (Ridge mountain spread noise) noise_params 1, 1, (1889, 1889, 1889), 3568, 3, 0.5, 2.0 +mgcarpathian_np_ridge_terrain (Ridge mountain spread noise) noise_params_2d 1, 1, (1889, 1889, 1889), 3568, 3, 0.5, 2.0, eased # 2D noise that controls the size/occurance of step mountain ranges. -mgcarpathian_np_step_terrain (Step mountain spread noise) noise_params 1, 1, (1889, 1889, 1889), 4157, 3, 0.5, 2.0 +mgcarpathian_np_step_terrain (Step mountain spread noise) noise_params_2d 1, 1, (1889, 1889, 1889), 4157, 3, 0.5, 2.0, eased # 2D noise that controls the shape/size of rolling hills. -mgcarpathian_np_hills (Rolling hill size noise) noise_params 0, 3, (257, 257, 257), 6604, 6, 0.5, 2.0 +mgcarpathian_np_hills (Rolling hill size noise) noise_params_2d 0, 3, (257, 257, 257), 6604, 6, 0.5, 2.0, eased # 2D noise that controls the shape/size of ridged mountains. -mgcarpathian_np_ridge_mnt (Ridged mountain size noise) noise_params 0, 12, (743, 743, 743), 5520, 6, 0.7, 2.0 +mgcarpathian_np_ridge_mnt (Ridged mountain size noise) noise_params_2d 0, 12, (743, 743, 743), 5520, 6, 0.7, 2.0, eased # 2D noise that controls the shape/size of step mountains. -mgcarpathian_np_step_mnt (Step mountain size noise) noise_params 0, 8, (509, 509, 509), 2590, 6, 0.6, 2.0 +mgcarpathian_np_step_mnt (Step mountain size noise) noise_params_2d 0, 8, (509, 509, 509), 2590, 6, 0.6, 2.0, eased # 3D noise for mountain overhangs, cliffs, etc. Usually small variations. -mgcarpathian_np_mnt_var (Mountain variation noise) noise_params 0, 1, (499, 499, 499), 2490, 5, 0.55, 2.0 +mgcarpathian_np_mnt_var (Mountain variation noise) noise_params_3d 0, 1, (499, 499, 499), 2490, 5, 0.55, 2.0 # First of 2 3D noises that together define tunnels. -mgcarpathian_np_cave1 (Cave1 noise) noise_params 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0 +mgcarpathian_np_cave1 (Cave1 noise) noise_params_3d 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0 # Second of 2 3D noises that together define tunnels. -mgcarpathian_np_cave2 (Cave2 noise) noise_params 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0 +mgcarpathian_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0 # 3D noise defining giant caverns. -mgcarpathian_np_cavern (Cavern noise) noise_params 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0 +mgcarpathian_np_cavern (Cavern noise) noise_params_3d 0, 1, (384, 128, 384), 723, 5, 0.63, 2.0 [*Mapgen Flat] # Map generation attributes specific to Mapgen flat. # Occasional lakes and hills can be added to the flat world. -# Flags that are not specified in the flag string are not modified from the default. +# Flags that are not enabled are not modified from the default. # Flags starting with 'no' are used to explicitly disable them. mgflat_spflags (Mapgen Flat specific flags) flags nolakes,nohills lakes,hills,nolakes,nohills @@ -1577,16 +1573,16 @@ mgflat_hill_steepness (Hill steepness) float 64.0 [**Noises] # Defines location and terrain of optional hills and lakes. -mgflat_np_terrain (Terrain noise) noise_params 0, 1, (600, 600, 600), 7244, 5, 0.6, 2.0 +mgflat_np_terrain (Terrain noise) noise_params_2d 0, 1, (600, 600, 600), 7244, 5, 0.6, 2.0, eased # Variation of biome filler depth. -mgflat_np_filler_depth (Filler depth noise) noise_params 0, 1.2, (150, 150, 150), 261, 3, 0.7, 2.0 +mgflat_np_filler_depth (Filler depth noise) noise_params_2d 0, 1.2, (150, 150, 150), 261, 3, 0.7, 2.0, eased # First of 2 3D noises that together define tunnels. -mgflat_np_cave1 (Cave1 noise) noise_params 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0 +mgflat_np_cave1 (Cave1 noise) noise_params_3d 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0 # Second of 2 3D noises that together define tunnels. -mgflat_np_cave2 (Cave2 noise) noise_params 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0 +mgflat_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0 [*Mapgen Fractal] @@ -1659,16 +1655,16 @@ mgfractal_julia_w (Julia w) float 0.33 [**Noises] # Y-level of seabed. -mgfractal_np_seabed (Seabed noise) noise_params -14, 9, (600, 600, 600), 41900, 5, 0.6, 2.0 +mgfractal_np_seabed (Seabed noise) noise_params_2d -14, 9, (600, 600, 600), 41900, 5, 0.6, 2.0, eased # Variation of biome filler depth. -mgfractal_np_filler_depth (Filler depth noise) noise_params 0, 1.2, (150, 150, 150), 261, 3, 0.7, 2.0 +mgfractal_np_filler_depth (Filler depth noise) noise_params_2d 0, 1.2, (150, 150, 150), 261, 3, 0.7, 2.0, eased # First of 2 3D noises that together define tunnels. -mgfractal_np_cave1 (Cave1 noise) noise_params 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0 +mgfractal_np_cave1 (Cave1 noise) noise_params_3d 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0 # Second of 2 3D noises that together define tunnels. -mgfractal_np_cave2 (Cave2 noise) noise_params 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0 +mgfractal_np_cave2 (Cave2 noise) noise_params_3d 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0 [*Mapgen Valleys] @@ -1676,7 +1672,7 @@ mgfractal_np_cave2 (Cave2 noise) noise_params 0, 12, (67, 67, 67), 10325, 3, 0.5 # 'altitude_chill' makes higher elevations colder, which may cause biome issues. # 'humid_rivers' modifies the humidity around rivers and in areas where water would tend to pool, # it may interfere with delicately adjusted biomes. -# Flags that are not specified in the flag string are not modified from the default. +# Flags that are not enabled are not modified from the default. # Flags starting with 'no' are used to explicitly disable them. mg_valleys_spflags (Mapgen Valleys specific flags) flags altitude_chill,humid_rivers altitude_chill,noaltitude_chill,humid_rivers,nohumid_rivers @@ -1709,34 +1705,34 @@ mgvalleys_cave_width (Cave width) float 0.09 [**Noises] # Caves and tunnels form at the intersection of the two noises -mgvalleys_np_cave1 (Cave noise #1) noise_params 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0 +mgvalleys_np_cave1 (Cave noise #1) noise_params_3d 0, 12, (61, 61, 61), 52534, 3, 0.5, 2.0 # Caves and tunnels form at the intersection of the two noises -mgvalleys_np_cave2 (Cave noise #2) noise_params 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0 +mgvalleys_np_cave2 (Cave noise #2) noise_params_3d 0, 12, (67, 67, 67), 10325, 3, 0.5, 2.0 # The depth of dirt or other filler -mgvalleys_np_filler_depth (Filler Depth) noise_params 0, 1.2, (256, 256, 256), 1605, 3, 0.5, 2.0 +mgvalleys_np_filler_depth (Filler Depth) noise_params_2d 0, 1.2, (256, 256, 256), 1605, 3, 0.5, 2.0, eased # Massive caves form here. -mgvalleys_np_massive_caves (Massive cave noise) noise_params 0, 1, (768, 256, 768), 59033, 6, 0.63, 2.0 +mgvalleys_np_massive_caves (Massive cave noise) noise_params_3d 0, 1, (768, 256, 768), 59033, 6, 0.63, 2.0 # River noise -- rivers occur close to zero -mgvalleys_np_rivers (River Noise) noise_params 0, 1, (256, 256, 256), -6050, 5, 0.6, 2.0 +mgvalleys_np_rivers (River Noise) noise_params_2d 0, 1, (256, 256, 256), -6050, 5, 0.6, 2.0, eased # Base terrain height -mgvalleys_np_terrain_height (Terrain Height) noise_params -10, 50, (1024, 1024, 1024), 5202, 6, 0.4, 2.0 +mgvalleys_np_terrain_height (Terrain Height) noise_params_2d -10, 50, (1024, 1024, 1024), 5202, 6, 0.4, 2.0, eased # Raises terrain to make valleys around the rivers -mgvalleys_np_valley_depth (Valley Depth) noise_params 5, 4, (512, 512, 512), -1914, 1, 1.0, 2.0 +mgvalleys_np_valley_depth (Valley Depth) noise_params_2d 5, 4, (512, 512, 512), -1914, 1, 1.0, 2.0, eased # Slope and fill work together to modify the heights -mgvalleys_np_inter_valley_fill (Valley Fill) noise_params 0, 1, (256, 512, 256), 1993, 6, 0.8, 2.0 +mgvalleys_np_inter_valley_fill (Valley Fill) noise_params_3d 0, 1, (256, 512, 256), 1993, 6, 0.8, 2.0 # Amplifies the valleys -mgvalleys_np_valley_profile (Valley Profile) noise_params 0.6, 0.5, (512, 512, 512), 777, 1, 1.0, 2.0 +mgvalleys_np_valley_profile (Valley Profile) noise_params_2d 0.6, 0.5, (512, 512, 512), 777, 1, 1.0, 2.0, eased # Slope and fill work together to modify the heights -mgvalleys_np_inter_valley_slope (Valley Slope) noise_params 0.5, 0.5, (128, 128, 128), 746, 1, 1.0, 2.0 +mgvalleys_np_inter_valley_slope (Valley Slope) noise_params_2d 0.5, 0.5, (128, 128, 128), 746, 1, 1.0, 2.0, eased [*Advanced] diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 726c23af6..9e3895d83 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1043,13 +1043,13 @@ Accumulates the absolute value of each noise gradient result. Noise parameters format example for 2D or 3D perlin noise or perlin noise maps: np_terrain = { - offset = 0, - scale = 1, - spread = {x=500, y=500, z=500}, + offset = "0", + scale = "1", + spread = {x="500", y="500", z="500"}, seed = 571347, octaves = 5, - persist = 0.63, - lacunarity = 2.0, + persist = "0.63", + lacunarity = "2.0", flags = "defaults, absvalue" } ^ A single noise parameter table can be used to get 2D or 3D noise, @@ -4024,12 +4024,16 @@ It can be created via `Settings(filename)`. #### Methods * `get(key)`: returns a value * `get_bool(key)`: returns a boolean +* `get_np_group(key)`: returns a NoiseParams table * `set(key, value)` * Setting names can't contain whitespace or any of `="{}#`. * Setting values can't contain the sequence `\n"""`. * Setting names starting with "secure." can't be set on the main settings object (`minetest.settings`). * `set_bool(key, value)` * See documentation for set() above. +* `set_np_group(key, value)` + * `value` is a NoiseParams table. + * Also, see documentation for set() above. * `remove(key)`: returns a boolean (`true` for success) * `get_names()`: returns `{key1,...}` * `write()`: returns a boolean (`true` for success) diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 4d8cdd352..1bbfac25f 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -1586,13 +1586,13 @@ bool read_noiseparams(lua_State *L, int index, NoiseParams *np) void push_noiseparams(lua_State *L, NoiseParams *np) { lua_newtable(L); - lua_pushnumber(L, np->offset); + push_float_string(L, np->offset); lua_setfield(L, -2, "offset"); - lua_pushnumber(L, np->scale); + push_float_string(L, np->scale); lua_setfield(L, -2, "scale"); - lua_pushnumber(L, np->persist); + push_float_string(L, np->persist); lua_setfield(L, -2, "persistence"); - lua_pushnumber(L, np->lacunarity); + push_float_string(L, np->lacunarity); lua_setfield(L, -2, "lacunarity"); lua_pushnumber(L, np->seed); lua_setfield(L, -2, "seed"); @@ -1603,7 +1603,7 @@ void push_noiseparams(lua_State *L, NoiseParams *np) np->flags); lua_setfield(L, -2, "flags"); - push_v3f(L, np->spread); + push_v3_float_string(L, np->spread); lua_setfield(L, -2, "spread"); } diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index 8f88aeb60..e81cecac8 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -51,6 +51,15 @@ if (value < F1000_MIN || value > F1000_MAX) { \ #define CHECK_POS_TAB(index) CHECK_TYPE(index, "position", LUA_TTABLE) +void push_float_string(lua_State *L, float value) +{ + std::stringstream ss; + std::string str; + ss << value; + str = ss.str(); + lua_pushstring(L, str.c_str()); +} + void push_v3f(lua_State *L, v3f p) { lua_newtable(L); @@ -71,6 +80,26 @@ void push_v2f(lua_State *L, v2f p) lua_setfield(L, -2, "y"); } +void push_v3_float_string(lua_State *L, v3f p) +{ + lua_newtable(L); + 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_newtable(L); + 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; diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 18b8f6531..7827d8146 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -99,6 +99,9 @@ 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); diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index 2d6769ea1..141ac61d1 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_internal.h" #include "cpp_api/s_security.h" #include "settings.h" +#include "noise.h" #include "log.h" @@ -105,6 +106,24 @@ int LuaSettings::l_get_bool(lua_State* L) return 1; } +// get_np_group(self, key) -> value +int LuaSettings::l_get_np_group(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + LuaSettings *o = checkobject(L, 1); + + std::string key = std::string(luaL_checkstring(L, 2)); + if (o->m_settings->exists(key)) { + NoiseParams np; + o->m_settings->getNoiseParams(key, np); + push_noiseparams(L, &np); + } else { + lua_pushnil(L); + } + + return 1; +} + // set(self, key, value) int LuaSettings::l_set(lua_State* L) { @@ -138,6 +157,23 @@ int LuaSettings::l_set_bool(lua_State* L) return 1; } +// set(self, key, value) +int LuaSettings::l_set_np_group(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + LuaSettings *o = checkobject(L, 1); + + std::string key = std::string(luaL_checkstring(L, 2)); + NoiseParams value; + read_noiseparams(L, 3, &value); + + SET_SECURITY_CHECK(L, key); + + o->m_settings->setNoiseParams(key, value, false); + + return 0; +} + // remove(self, key) -> success int LuaSettings::l_remove(lua_State* L) { @@ -264,8 +300,10 @@ const char LuaSettings::className[] = "Settings"; const luaL_Reg LuaSettings::methods[] = { luamethod(LuaSettings, get), luamethod(LuaSettings, get_bool), + luamethod(LuaSettings, get_np_group), luamethod(LuaSettings, set), luamethod(LuaSettings, set_bool), + luamethod(LuaSettings, set_np_group), luamethod(LuaSettings, remove), luamethod(LuaSettings, get_names), luamethod(LuaSettings, write), diff --git a/src/script/lua_api/l_settings.h b/src/script/lua_api/l_settings.h index 500917f0a..dcf39a89e 100644 --- a/src/script/lua_api/l_settings.h +++ b/src/script/lua_api/l_settings.h @@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once +#include "common/c_content.h" #include "lua_api/l_base.h" class Settings; @@ -38,12 +39,18 @@ private: // get_bool(self, key) -> boolean static int l_get_bool(lua_State *L); + // get_np_group(self, key) -> noiseparam + static int l_get_np_group(lua_State *L); + // set(self, key, value) static int l_set(lua_State *L); // set_bool(self, key, value) static int l_set_bool(lua_State *L); + // set_np_group(self, key, value) + static int l_set_np_group(lua_State *L); + // remove(self, key) -> success static int l_remove(lua_State *L); |