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