generate_from_settingtypes.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. if comment_line == "" then
  50. insert(result, "#\n")
  51. else
  52. insert(result, "# " .. comment_line .. "\n")
  53. end
  54. end
  55. end
  56. insert(result, "# type: " .. entry.type)
  57. if entry.min then
  58. insert(result, " min: " .. entry.min)
  59. end
  60. if entry.max then
  61. insert(result, " max: " .. entry.max)
  62. end
  63. if entry.values and entry.noise_params == nil then
  64. insert(result, " values: " .. concat(entry.values, ", "))
  65. end
  66. if entry.possible then
  67. insert(result, " possible values: " .. concat(entry.possible, ", "))
  68. end
  69. insert(result, "\n")
  70. if group_format == true then
  71. local flags = entry.values[10]
  72. if flags ~= "" then
  73. flags = " "..flags
  74. end
  75. insert(result, sprintf(group_format_template, entry.name, entry.values[1],
  76. entry.values[2], entry.values[3], entry.values[4], entry.values[5],
  77. entry.values[6], entry.values[7], entry.values[8], entry.values[9],
  78. flags))
  79. else
  80. local append
  81. if entry.default ~= "" then
  82. append = " " .. entry.default
  83. end
  84. insert(result, sprintf("# %s =%s\n\n", entry.name, append or ""))
  85. end
  86. end
  87. end
  88. return concat(result)
  89. end
  90. local translation_file_header = [[
  91. // This file is automatically generated
  92. // It contains a bunch of fake gettext calls, to tell xgettext about the strings in config files
  93. // To update it, refer to the bottom of builtin/mainmenu/dlg_settings_advanced.lua
  94. fake_function() {]]
  95. local function create_translation_file()
  96. local result = { translation_file_header }
  97. for _, entry in ipairs(settings) do
  98. if entry.type == "category" then
  99. insert(result, sprintf("\tgettext(%q);", entry.name))
  100. else
  101. if entry.readable_name then
  102. insert(result, sprintf("\tgettext(%q);", entry.readable_name))
  103. end
  104. if entry.comment ~= "" then
  105. local comment_escaped = entry.comment:gsub("\n", "\\n")
  106. comment_escaped = comment_escaped:gsub("\"", "\\\"")
  107. insert(result, "\tgettext(\"" .. comment_escaped .. "\");")
  108. end
  109. end
  110. end
  111. insert(result, "}\n")
  112. return concat(result, "\n")
  113. end
  114. local file = assert(io.open("minetest.conf.example", "w"))
  115. file:write(create_minetest_conf_example())
  116. file:close()
  117. file = assert(io.open("src/settings_translation_file.cpp", "w"))
  118. -- If 'minetest.conf.example' appears in the 'bin' folder, the line below may have to be
  119. -- used instead. The file will also appear in the 'bin' folder.
  120. --file = assert(io.open("settings_translation_file.cpp", "w"))
  121. file:write(create_translation_file())
  122. file:close()