2014-11-18 03:16:59 +01:00
|
|
|
local world_path = minetest.get_worldpath()
|
2013-09-03 01:16:14 +02:00
|
|
|
|
2014-11-18 03:16:59 +01:00
|
|
|
areas.config = {}
|
|
|
|
|
2019-07-11 20:02:32 +02:00
|
|
|
local function setting(name, tp, default)
|
|
|
|
local full_name = "areas." .. name
|
2014-11-18 03:16:59 +01:00
|
|
|
local value
|
2019-07-11 20:02:32 +02:00
|
|
|
if tp == "bool" then
|
2017-05-13 10:59:30 +02:00
|
|
|
value = minetest.settings:get_bool(full_name)
|
2019-07-11 20:02:32 +02:00
|
|
|
default = value == nil and minetest.is_yes(default)
|
2014-11-18 03:16:59 +01:00
|
|
|
elseif tp == "string" then
|
2017-05-13 10:59:30 +02:00
|
|
|
value = minetest.settings:get(full_name)
|
2019-07-11 20:02:32 +02:00
|
|
|
elseif tp == "v3f" then
|
2014-11-18 03:16:59 +01:00
|
|
|
value = minetest.setting_get_pos(full_name)
|
2019-07-11 20:02:32 +02:00
|
|
|
default = value == nil and minetest.string_to_pos(default)
|
|
|
|
elseif tp == "float" or tp == "int" then
|
2017-05-13 10:59:30 +02:00
|
|
|
value = tonumber(minetest.settings:get(full_name))
|
2019-07-11 20:02:32 +02:00
|
|
|
local v, other = default:match("^(%S+) (.+)")
|
|
|
|
default = value == nil and tonumber(other and v or default)
|
2014-11-18 03:16:59 +01:00
|
|
|
else
|
2019-07-11 20:02:32 +02:00
|
|
|
error("Cannot parse setting type " .. tp)
|
2014-11-18 03:16:59 +01:00
|
|
|
end
|
2019-07-11 20:02:32 +02:00
|
|
|
|
2013-09-03 01:16:14 +02:00
|
|
|
if value == nil then
|
|
|
|
value = default
|
2019-07-11 20:02:32 +02:00
|
|
|
assert(default ~= nil, "Cannot parse default for " .. full_name)
|
2013-09-03 01:16:14 +02:00
|
|
|
end
|
2019-07-11 20:02:32 +02:00
|
|
|
--print("add", name, default, value)
|
2014-11-18 03:16:59 +01:00
|
|
|
areas.config[name] = value
|
2013-09-03 01:16:14 +02:00
|
|
|
end
|
|
|
|
|
2019-07-11 20:02:32 +02:00
|
|
|
local file = io.open(areas.modpath .. "/settingtypes.txt", "r")
|
|
|
|
for line in file:lines() do
|
|
|
|
local name, tp, value = line:match("^areas%.(%S+) %(.*%) (%S+) (.*)")
|
|
|
|
if value then
|
|
|
|
setting(name, tp, value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
file:close()
|
|
|
|
|
2014-11-18 03:16:59 +01:00
|
|
|
--------------
|
|
|
|
-- Settings --
|
|
|
|
--------------
|
2013-09-03 01:16:14 +02:00
|
|
|
|
2019-07-11 20:02:32 +02:00
|
|
|
setting("filename", "string", world_path.."/areas.dat")
|
2019-04-02 06:21:31 +02:00
|
|
|
|