settings.lua 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. local world_path = minetest.get_worldpath()
  2. areas.config = {}
  3. local function setting(name, tp, default)
  4. local full_name = "areas." .. name
  5. local value
  6. if tp == "bool" then
  7. value = minetest.settings:get_bool(full_name)
  8. default = value == nil and minetest.is_yes(default)
  9. elseif tp == "string" then
  10. value = minetest.settings:get(full_name)
  11. elseif tp == "v3f" then
  12. value = minetest.setting_get_pos(full_name)
  13. default = value == nil and minetest.string_to_pos(default)
  14. elseif tp == "float" or tp == "int" then
  15. value = tonumber(minetest.settings:get(full_name))
  16. local v, other = default:match("^(%S+) (.+)")
  17. default = value == nil and tonumber(other and v or default)
  18. else
  19. error("Cannot parse setting type " .. tp)
  20. end
  21. if value == nil then
  22. value = default
  23. assert(default ~= nil, "Cannot parse default for " .. full_name)
  24. end
  25. --print("add", name, default, value)
  26. areas.config[name] = value
  27. end
  28. local file = io.open(areas.modpath .. "/settingtypes.txt", "r")
  29. for line in file:lines() do
  30. local name, tp, value = line:match("^areas%.(%S+) %(.*%) (%S+) (.*)")
  31. if value then
  32. setting(name, tp, value)
  33. end
  34. end
  35. file:close()
  36. --------------
  37. -- Settings --
  38. --------------
  39. setting("filename", "string", world_path.."/areas.dat")