-
Notifications
You must be signed in to change notification settings - Fork 5
/
settings.lua
110 lines (100 loc) · 4.29 KB
/
settings.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
vmg.settings = Settings(minetest.get_worldpath() .. "/vmg.conf") -- Create settings object
local function define_str(flag, default, write_to_config)
local value = vmg.settings:get(flag)
if value then -- This flag exists in vmg.conf, return its value
return value, true
else
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.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
end
end
end
local function define_num(flag, default, write_to_config)
local value = vmg.settings:get(flag)
if value then -- This flag exists in vmg.conf, return its value
return tonumber(value), true
else
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.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 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 then -- This flag exists in vmg.conf, return its value
return value, true
else
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.settings:set_bool("vmg_" .. flag, default) -- write to minetest.conf if write_to_config is enabled (usually disabled)
end
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_np_group(flag)
if value then -- This flag exists in vmg.conf, return its value
return value, true
else
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_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
if write_to_config then
minetest.settings:set_np_group("vmg_" .. flag, default) -- write to minetest.conf if write_to_config is enabled (usually disabled)
end
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
local f = definefunc[typeval] -- Choose the appropriate function
if f then
return f(flag, default, write_to_config)
end
end
if vmg.loglevel >= 2 then
print("[Valleys Mapgen] Loading mapgen ...")
end
-- Choose the appropriate mapgen version
local version = vmg.define("version", vmg.version)
if vmg.valleys_c then
dofile(vmg.path .. "/mapgen_c.lua")
elseif version == vmg.version then
dofile(vmg.path .. "/mapgen.lua")
elseif not pcall(dofile, vmg.path .. "/old_mapgens/" .. version .. ".lua") then
print("[Valleys Mapgen] Missing compatibility mapgen for version " .. version .. ". Using latest version, you may see artifacts.")
end
-- Write settings after loading
minetest.after(0, function() vmg.settings:write() end)