generate_from_settingtypes.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. local settings = ...
  2. local concat = table.concat
  3. local insert = table.insert
  4. local sprintf = string.format
  5. local rep = string.rep
  6. local minetest_example_header = [[
  7. # This file contains a list of all available settings and their default value for minetest.conf
  8. # By default, all the settings are commented and not functional.
  9. # Uncomment settings by removing the preceding #.
  10. # minetest.conf is read by default from:
  11. # ../minetest.conf
  12. # ../../minetest.conf
  13. # Any other path can be chosen by passing the path as a parameter
  14. # to the program, eg. "minetest.exe --config ../minetest.conf.example".
  15. # Further documentation:
  16. # http://wiki.minetest.net/
  17. ]]
  18. local group_format_template = [[
  19. # %s = {
  20. # offset = %s,
  21. # scale = %s,
  22. # spread = (%s, %s, %s),
  23. # seed = %s,
  24. # octaves = %s,
  25. # persistence = %s,
  26. # lacunarity = %s,
  27. # flags = %s
  28. # }
  29. ]]
  30. local function create_minetest_conf_example()
  31. local result = { minetest_example_header }
  32. for _, entry in ipairs(settings) do
  33. if entry.type == "category" then
  34. if entry.level == 0 then
  35. insert(result, "#\n# " .. entry.name .. "\n#\n\n")
  36. else
  37. insert(result, rep("#", entry.level))
  38. insert(result, "# " .. entry.name .. "\n\n")
  39. end
  40. else
  41. local group_format = false
  42. if entry.noise_params and entry.values then
  43. if entry.type == "noise_params_2d" or entry.type == "noise_params_3d" then
  44. group_format = true
  45. end
  46. end
  47. if entry.comment ~= "" then
  48. for _, comment_line in ipairs(entry.comment:split("\n", true)) do
  49. insert(result, "# " .. comment_line .. "\n")
  50. end
  51. end
  52. insert(result, "# type: " .. entry.type)
  53. if entry.min then
  54. insert(result, " min: " .. entry.min)
  55. end
  56. if entry.max then
  57. insert(result, " max: " .. entry.max)
  58. end
  59. if entry.values and entry.noise_params == nil then
  60. insert(result, " values: " .. concat(entry.values, ", "))
  61. end
  62. if entry.possible then
  63. insert(result, " possible values: " .. concat(entry.possible, ", "))
  64. end
  65. insert(result, "\n")
  66. if group_format == true then
  67. insert(result, sprintf(group_format_template, entry.name, entry.values[1],
  68. entry.values[2], entry.values[3], entry.values[4], entry.values[5],
  69. entry.values[6], entry.values[7], entry.values[8], entry.values[9],
  70. entry.values[10]))
  71. else
  72. local append
  73. if entry.default ~= "" then
  74. append = " " .. entry.default
  75. end
  76. insert(result, sprintf("# %s =%s\n\n", entry.name, append or ""))
  77. end
  78. end
  79. end
  80. return concat(result)
  81. end
  82. local translation_file_header = [[
  83. // This file is automatically generated
  84. // It conatins a bunch of fake gettext calls, to tell xgettext about the strings in config files
  85. // To update it, refer to the bottom of builtin/mainmenu/dlg_settings_advanced.lua
  86. fake_function() {]]
  87. local function create_translation_file()
  88. local result = { translation_file_header }
  89. for _, entry in ipairs(settings) do
  90. if entry.type == "category" then
  91. insert(result, sprintf("\tgettext(%q);", entry.name))
  92. else
  93. if entry.readable_name then
  94. insert(result, sprintf("\tgettext(%q);", entry.readable_name))
  95. end
  96. if entry.comment ~= "" then
  97. local comment_escaped = entry.comment:gsub("\n", "\\n")
  98. comment_escaped = comment_escaped:gsub("\"", "\\\"")
  99. insert(result, "\tgettext(\"" .. comment_escaped .. "\");")
  100. end
  101. end
  102. end
  103. insert(result, "}\n")
  104. return concat(result, "\n")
  105. end
  106. local file = assert(io.open("minetest.conf.example", "w"))
  107. file:write(create_minetest_conf_example())
  108. file:close()
  109. file = assert(io.open("src/settings_translation_file.cpp", "w"))
  110. -- If 'minetest.conf.example' appears in the 'bin' folder, the line below may have to be
  111. -- used instead. The file will also appear in the 'bin' folder.
  112. --file = assert(io.open("settings_translation_file.cpp", "w"))
  113. file:write(create_translation_file())
  114. file:close()