Allow to toggle autogen

This commit is contained in:
Wuzzy 2022-04-16 04:44:05 +02:00
parent 018f8e9404
commit 776108ac19

View File

@ -67,9 +67,14 @@ current_perlin.dimensions = 2
-- of the nearest number (counting downwards) that is divisible by sidelen.
-- This is (kind of) analogous to the "sidelen" parameter of mapgen decorations.
current_perlin.sidelen = 1
-- Place position of current perlin (relevant for single placing)
current_perlin.pos = {}
current_perlin.auto_build = true
-- If enabled, automatically generate nodes around player
current_perlin.autogen = false
-- Remember which areas have been loaded by the autogen so far
-- Index: Hash of node position, value: true if loaded
current_perlin.loaded_areas = {}
------------
@ -604,6 +609,14 @@ local show_formspec = function(player, noiseparams, profile_id)
if #np_profiles > 1 then
delete_btn = "button[7.25,0.5;2.0,0.5;delete_np_profile;"..F(S("Delete")).."]"
end
local autogen_label
local create_btn = ""
if current_perlin.autogen then
autogen_label = S("Disable mapgen")
else
autogen_label = S("Enable mapgen")
create_btn = "button[3.5,0;3,1;create;"..F(S("Apply and create")).."]"
end
local form = [[
formspec_version[4]size[10,12.5]
container[0.25,0.25]
@ -679,8 +692,8 @@ local show_formspec = function(player, noiseparams, profile_id)
container[0,10.95]
button[0.5,0;3,1;apply;]]..F(S("Apply"))..[[]
button[3.5,0;3,1;create;]]..F(S("Apply and create"))..[[]
button_exit[6.5,0;3,1;close;]]..F(S("Close"))..[[]
]]..create_btn..[[
button[6.5,0;3,1;toggle_autogen;]]..F(autogen_label)..[[]
container_end[]
]]
minetest.show_formspec(player:get_player_name(), "perlin_explorer:creator", form)
@ -726,7 +739,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
end
-- Handle other fields
local do_apply = fields.apply ~= nil
local do_apply = fields.apply ~= nil or fields.toggle_autogen ~= nil
local do_create = fields.create ~= nil or fields.key_enter_field ~= nil
if (do_create or do_apply or fields.add_np_profile or fields.np_profiles) then
if fields.offset and fields.scale and fields.seed and fields.spread_x and fields.spread_y and fields.spread_z and fields.octaves and fields.persistence and fields.lacunarity then
@ -820,6 +833,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif msg == false then
minetest.log("error", "[perlin_explorer] Error generating Perlin noise nodes!")
end
elseif fields.toggle_autogen then
current_perlin.autogen = not current_perlin.autogen
local profile = tonumber(fields.np_profiles)
show_formspec(player, noiseparams, profile)
minetest.log("action", "[perlin_explorer] Autogen state is now: "..tostring(current_perlin.autogen))
end
end
end
@ -852,7 +870,7 @@ minetest.register_globalstep(function(dtime)
return
end
timer = 0
if current_perlin.noise and current_perlin.auto_build then
if current_perlin.noise and current_perlin.autogen then
local player = minetest.get_player_by_name("singleplayer")
if not player then
return