forked from minertestdude/minetest-thirsty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
configuration.lua
76 lines (61 loc) · 2.29 KB
/
configuration.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
--[[
Configuration from default, moddir and worlddir, in that order.
See init.lua for license.
]]
-- change these for other mods
local M = thirsty
local modname = 'thirsty'
local fileroot = modname
-- make sure config exists; keep constant reference to it
local C = M.config or {}
M.config = C
local function try_config_file(filename)
--print("Config from "..filename)
local file, err = io.open(filename, 'r')
if file then
file:close() -- was just for checking existance
local confcode, err = loadfile(filename)
if confcode then
confcode()
if C ~= M.config then
-- M.config was overriden, merge
for key, value in pairs(M.config) do
if type(value) == 'table' and type(C[key]) == 'table' and not value.CLEAR then
for k, v in pairs(value) do
C[key][k] = value[k]
end
else
-- copy (not a table, or asked to clear)
C[key] = value
end
end
else
-- no override? Empty, or file knows what it is doing.
end
else
minetest.log("error", "Could not load " .. filename .. ": " .. err)
end
end
end
-- mineclone2 use special separate config, this has to do with variable visibility from read contents
if core.get_modpath("mcl_core") and mcl_core then
-- read starting configuration from <modname>.default.conf
try_config_file(minetest.get_modpath(modname) .. "/" .. fileroot .. ".default.mclconf")
-- next, install-specific copy in modpath
try_config_file(minetest.get_modpath(modname) .. "/" .. fileroot .. ".mclconf")
else
-- read starting configuration from <modname>.default.conf
try_config_file(minetest.get_modpath(modname) .. "/" .. fileroot .. ".default.conf")
-- next, install-specific copy in modpath
try_config_file(minetest.get_modpath(modname) .. "/" .. fileroot .. ".conf")
end
-- last, world-specific copy in worldpath
try_config_file(minetest.get_worldpath() .. "/" .. fileroot .. ".conf")
-- remove any special keys from tables
for key, value in pairs(C) do
if type(value) == 'table' then
value.CLEAR = nil
end
end
-- write back
M.config = C