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