Use the new settings API
This commit is contained in:
parent
8c10f568bc
commit
302a51a0b6
81
settings.lua
81
settings.lua
@ -5,13 +5,13 @@ local function define_str(flag, default, write_to_config)
|
||||
if value then -- This flag exists in vmg.conf, return its value
|
||||
return value, true
|
||||
else
|
||||
local on_config = minetest.setting_get("vmg_" .. flag) -- get this flag in minetest.conf
|
||||
local on_config = minetest.settings:get("vmg_" .. flag) -- get this flag in minetest.conf
|
||||
if on_config then -- This flag exists in minetest.conf, so return its value
|
||||
vmg.settings:set(flag, on_config)
|
||||
return on_config, false
|
||||
else -- Flag don't exist anywhere, so the default value will be written in settings and returned
|
||||
if write_to_config then
|
||||
minetest.setting_set("vmg_" .. flag, default) -- write to minetest.conf if write_to_config is enabled (usually disabled)
|
||||
minetest.settings:set("vmg_" .. flag, default) -- write to minetest.conf if write_to_config is enabled (usually disabled)
|
||||
end
|
||||
vmg.settings:set(flag, default) -- write to vmg.conf
|
||||
return default, false -- return default value
|
||||
@ -24,98 +24,73 @@ local function define_num(flag, default, write_to_config)
|
||||
if value then -- This flag exists in vmg.conf, return its value
|
||||
return tonumber(value), true
|
||||
else
|
||||
local on_config = minetest.setting_get("vmg_" .. flag) -- get this flag in minetest.conf
|
||||
local on_config = minetest.settings:get("vmg_" .. flag) -- get this flag in minetest.conf
|
||||
if on_config then -- This flag exists in minetest.conf, so return its value
|
||||
vmg.settings:set(flag, on_config)
|
||||
return tonumber(on_config), false
|
||||
else -- Flag don't exist anywhere, so the default value will be written in settings and returned
|
||||
if write_to_config then
|
||||
minetest.setting_set("vmg_" .. flag, default) -- write to minetest.conf if write_to_config is enabled (usually disabled)
|
||||
minetest.settings:set("vmg_" .. flag, default) -- write to minetest.conf if write_to_config is enabled (usually disabled)
|
||||
end
|
||||
vmg.settings:set(flag, default) -- write to vmg.conf
|
||||
return default, false -- return default value
|
||||
return tonumber(default), false -- return default value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function define_bool(flag, default, write_to_config)
|
||||
local value = vmg.settings:get_bool(flag)
|
||||
if value ~= nil then -- This flag exists in vmg.conf, return its value
|
||||
if value then -- This flag exists in vmg.conf, return its value
|
||||
return value, true
|
||||
else
|
||||
local on_config = minetest.setting_getbool("vmg_" .. flag) -- get this flag in minetest.conf
|
||||
if on_config ~= nil then -- This flag exists in minetest.conf, so return its value
|
||||
vmg.settings:set(flag, tostring(on_config))
|
||||
local on_config = minetest.settings:get_bool("vmg_" .. flag) -- get this flag in minetest.conf
|
||||
if on_config then -- This flag exists in minetest.conf, so return its value
|
||||
vmg.settings:set_bool(flag, on_config)
|
||||
return on_config, false
|
||||
else -- Flag don't exist anywhere, so the default value will be written in settings and returned
|
||||
if write_to_config then
|
||||
minetest.setting_setbool("vmg_" .. flag, default) -- write to minetest.conf if write_to_config is enabled (usually disabled)
|
||||
minetest.settings:set_bool("vmg_" .. flag, default) -- write to minetest.conf if write_to_config is enabled (usually disabled)
|
||||
end
|
||||
vmg.settings:set(flag, tostring(default)) -- write to vmg.conf
|
||||
vmg.settings:set_bool(flag, default) -- write to vmg.conf
|
||||
return default, false -- return default value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function define_noise(flag, default, write_to_config)
|
||||
local value = vmg.settings:get(flag)
|
||||
local value = vmg.settings:get_np_group(flag)
|
||||
if value then -- This flag exists in vmg.conf, return its value
|
||||
return vmg.string_to_noise(value), true
|
||||
return value, true
|
||||
else
|
||||
local on_config = minetest.setting_get("vmg_" .. flag) -- get this flag in minetest.conf
|
||||
local on_config = minetest.settings:get_np_group("vmg_" .. flag) -- get this flag in minetest.conf
|
||||
if on_config then -- This flag exists in minetest.conf, so return its value
|
||||
vmg.settings:set(flag, on_config)
|
||||
return vmg.string_to_noise(on_config), false
|
||||
vmg.settings:set_np_group(flag, on_config)
|
||||
return on_config, false
|
||||
else -- Flag don't exist anywhere, so the default value will be written in settings and returned
|
||||
local str_default = vmg.noise_to_string(default)
|
||||
if write_to_config then
|
||||
minetest.setting_set("vmg_" .. flag, str_default) -- write to minetest.conf if write_to_config is enabled (usually disabled)
|
||||
minetest.settings:set_np_group("vmg_" .. flag, default) -- write to minetest.conf if write_to_config is enabled (usually disabled)
|
||||
end
|
||||
vmg.settings:set(flag, str_default) -- write to vmg.conf
|
||||
vmg.settings:set_np_group(flag, default) -- write to vmg.conf
|
||||
return default, false -- return default value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local definefunc = {
|
||||
string = define_str,
|
||||
number = define_num,
|
||||
boolean = define_bool,
|
||||
table = define_noise,
|
||||
}
|
||||
|
||||
function vmg.define(flag, default, write_to_config)
|
||||
local typeval = type(default) -- Select function from the type of the default value
|
||||
if typeval == "string" then
|
||||
return define_str(flag, default, write_to_config)
|
||||
elseif typeval == "number" then
|
||||
return define_num(flag, default, write_to_config)
|
||||
elseif typeval == "boolean" then
|
||||
return define_bool(flag, default, write_to_config)
|
||||
elseif typeval == "table" then
|
||||
return define_noise(flag, default, write_to_config)
|
||||
local f = definefunc[typeval] -- Choose the appropriate function
|
||||
if f then
|
||||
return f(flag, default, write_to_config)
|
||||
end
|
||||
end
|
||||
|
||||
function vmg.noise_to_string(n)
|
||||
return n.offset ..
|
||||
", " .. n.scale ..
|
||||
", " .. minetest.pos_to_string(n.spread) ..
|
||||
", " .. n.seed ..
|
||||
", " .. n.octaves ..
|
||||
", " .. n.persist ..
|
||||
", " .. n.lacunarity
|
||||
end
|
||||
|
||||
function vmg.string_to_noise(str)
|
||||
local t = {}
|
||||
for line in str:gmatch("[%d%.%-e]+") do
|
||||
table.insert(t, tonumber(line))
|
||||
end
|
||||
return {
|
||||
offset = t[1],
|
||||
scale = t[2],
|
||||
spread = {x=t[3], y=t[4], z=t[5]},
|
||||
seed = t[6],
|
||||
octaves = t[7],
|
||||
persist = t[8],
|
||||
lacunarity = t[9],
|
||||
}
|
||||
end
|
||||
|
||||
if vmg.loglevel >= 2 then
|
||||
print("[Valleys Mapgen] Loading mapgen ...")
|
||||
end
|
||||
|
@ -149,23 +149,23 @@ vmg_leaves_colors (Leaves colors) bool true
|
||||
# Base ground height
|
||||
# large and smooth noise
|
||||
# 2D noise
|
||||
vmg_noise_1 (#1: Base ground height) noise_params -10, 50, (1024,1024,1024), 5202, 6, 0.4, 2
|
||||
vmg_noise_1 (#1: Base ground height) noise_params_2d -10, 50, (1024,1024,1024), 5202, 6, 0.4, 2
|
||||
|
||||
# Valleys noise
|
||||
# place a river where around zero
|
||||
# 2D noise
|
||||
vmg_noise_2 (#2: Valleys) noise_params 0, 1, (256,256,256), -6050, 5, 0.6, 2
|
||||
# 3D noise
|
||||
vmg_noise_2 (#2: Valleys) noise_params_3d 0, 1, (256,256,256), -6050, 5, 0.6, 2
|
||||
|
||||
# Valleys depth
|
||||
# significant influence on terrain height
|
||||
# this value will be squared
|
||||
# 2D noise
|
||||
vmg_noise_3 (#3: Valleys depth) noise_params 5, 4, (512,512,512), -1914, 1, 1, 2
|
||||
vmg_noise_3 (#3: Valleys depth) noise_params_2d 5, 4, (512,512,512), -1914, 1, 1, 2
|
||||
|
||||
# Valleys profile
|
||||
# higher values = larger valleys
|
||||
# 2D noise
|
||||
vmg_noise_4 (#4: Valleys profile) noise_params 0.6, 0.5, (512,512,512), 777, 1, 1, 2
|
||||
vmg_noise_4 (#4: Valleys profile) noise_params_2d 0.6, 0.5, (512,512,512), 777, 1, 1, 2
|
||||
|
||||
# Inter-valleys slopes
|
||||
# determines how much the 3D noise #6 impacts the terrain.
|
||||
@ -173,82 +173,82 @@ vmg_noise_4 (#4: Valleys profile) noise_params 0.6, 0.5, (512,512,512), 777, 1,
|
||||
# low values = smooth terrain, round and wide mountain tops
|
||||
# high values = steep terrain, sharp mountains peaks
|
||||
# 2D noise
|
||||
vmg_noise_5 (#5: Inter-valleys slopes) noise_params 0.5, 0.5, (128,128,128), 746, 1, 1, 2
|
||||
vmg_noise_5 (#5: Inter-valleys slopes) noise_params_2d 0.5, 0.5, (128,128,128), 746, 1, 1, 2
|
||||
|
||||
# Inter-valleys filling
|
||||
# 3D noise
|
||||
vmg_noise_6 (#6: Inter-valleys filling) noise_params 0, 1, (256,512,256), 1993, 6, 0.8, 2
|
||||
vmg_noise_6 (#6: Inter-valleys filling) noise_params_3d 0, 1, (256,512,256), 1993, 6, 0.8, 2
|
||||
|
||||
[**Caves noises #8-12]
|
||||
# First cave noise
|
||||
# 3D noise
|
||||
vmg_noise_8 (#8: Caves I) noise_params 0, 1, (32,32,32), -4640, 4, 0.5, 2
|
||||
vmg_noise_8 (#8: Caves I) noise_params_3d 0, 1, (32,32,32), -4640, 4, 0.5, 2
|
||||
|
||||
# Second cave noise
|
||||
# 3D noise
|
||||
vmg_noise_9 (#9: Caves II) noise_params 0, 1, (32,32,32), 8804, 4, 0.5, 2
|
||||
vmg_noise_9 (#9: Caves II) noise_params_3d 0, 1, (32,32,32), 8804, 4, 0.5, 2
|
||||
|
||||
# Third cave noise
|
||||
# 3D noise
|
||||
vmg_noise_10 (#10: Caves III) noise_params 0, 1, (32,32,32), -4780, 4, 0.5, 2
|
||||
vmg_noise_10 (#10: Caves III) noise_params_3d 0, 1, (32,32,32), -4780, 4, 0.5, 2
|
||||
|
||||
# Fourth cave noise, also determines lava
|
||||
# 3D noise
|
||||
vmg_noise_11 (#11: Caves IV and Lava) noise_params 0, 1, (32,32,32), -9969, 4, 0.5, 2
|
||||
vmg_noise_11 (#11: Caves IV and Lava) noise_params_3d 0, 1, (32,32,32), -9969, 4, 0.5, 2
|
||||
|
||||
# Lava can only spawn when this noise is up to a certain threshold
|
||||
# that depends on Y coordinate and Lava depth parameter
|
||||
# 3D noise
|
||||
vmg_noise_12 (#12: Geological heat) noise_params 0, 1, (64,64,64), 3314, 4, 0.5, 2
|
||||
vmg_noise_12 (#12: Geological heat) noise_params_3d 0, 1, (64,64,64), 3314, 4, 0.5, 2
|
||||
|
||||
[**Dirt noises #7 #13-16]
|
||||
# Dirt thickness at y=0
|
||||
# reduced by elevation according to Average stone level parameter
|
||||
# 2D noise
|
||||
vmg_noise_7 (#7: Dirt thickness) noise_params 4, 1.75, (256,256,256), 1605, 3, 0.5, 2
|
||||
vmg_noise_7 (#7: Dirt thickness) noise_params_2d 4, 1.75, (256,256,256), 1605, 3, 0.5, 2
|
||||
|
||||
# Clay noise
|
||||
# above Normal dirt threshold parameter, make clayey dirt
|
||||
# above Clay threshold parameter, make pure clay
|
||||
# significant influence on plants
|
||||
# 2D noise
|
||||
vmg_noise_13 (#13: Clay) noise_params 0, 1, (256,256,256), 2835, 5, 0.5, 4
|
||||
vmg_noise_13 (#13: Clay) noise_params_2d 0, 1, (256,256,256), 2835, 5, 0.5, 4
|
||||
|
||||
# Silt noise
|
||||
# above Normal dirt threshold parameter, make silty dirt
|
||||
# above Silt threshold parameter, make pure silt
|
||||
# significant influence on plants
|
||||
# 2D noise
|
||||
vmg_noise_14 (#14: Silt) noise_params 0, 1, (256,256,256), 6674, 5, 0.5, 4
|
||||
vmg_noise_14 (#14: Silt) noise_params_2d 0, 1, (256,256,256), 6674, 5, 0.5, 4
|
||||
|
||||
# Sand noise
|
||||
# above Normal dirt threshold parameter, make sandy dirt
|
||||
# above Sand threshold parameter, make pure desert sand
|
||||
# significant influence on plants
|
||||
# 2D noise
|
||||
vmg_noise_15 (#15: Sand) noise_params 0, 1, (256,256,256), 6940, 5, 0.5, 4
|
||||
vmg_noise_15 (#15: Sand) noise_params_2d 0, 1, (256,256,256), 6940, 5, 0.5, 4
|
||||
|
||||
# Beaches
|
||||
# also used as abstract biome parameter by plants
|
||||
# 2D noise
|
||||
vmg_noise_16 (#16: Beaches) noise_params 2, 8, (256,256,256), 2349, 3, 0.5, 2
|
||||
vmg_noise_16 (#16: Beaches) noise_params_2d 2, 8, (256,256,256), 2349, 3, 0.5, 2
|
||||
|
||||
[**Climate noises #17-18]
|
||||
# Temperature
|
||||
# decreased by elevation
|
||||
# 3D noise
|
||||
vmg_noise_17 (#17: Temperature) noise_params 0, 1, (768,256,768), -1805, 4, 0.5, 4
|
||||
vmg_noise_17 (#17: Temperature) noise_params_3d 0, 1, (768,256,768), -1805, 4, 0.5, 4
|
||||
|
||||
# Humidity
|
||||
# modified by dirt type and water proximity
|
||||
# 2D noise
|
||||
vmg_noise_18 (#18: Humidity) noise_params 0, 1, (243,243,243), -5787, 4, 0.5, 3
|
||||
vmg_noise_18 (#18: Humidity) noise_params_2d 0, 1, (243,243,243), -5787, 4, 0.5, 3
|
||||
|
||||
[**Simple caves noises #19-20]
|
||||
# Simple caves I
|
||||
# 3D noise
|
||||
vmg_noise_19 (#19: Simple caves I) noise_params 0, 1, (64,64,64), -8402, 3, 0.5, 2
|
||||
vmg_noise_19 (#19: Simple caves I) noise_params_3d 0, 1, (64,64,64), -8402, 3, 0.5, 2
|
||||
|
||||
# Simple caves II
|
||||
# 3D noise
|
||||
vmg_noise_20 (#20: Simple caves II) noise_params 0, 1, (64,64,64), 3944, 3, 0.5, 2
|
||||
vmg_noise_20 (#20: Simple caves II) noise_params_3d 0, 1, (64,64,64), 3944, 3, 0.5, 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user