1
1
-- saved state for each player
2
2
local gui_nodename1 = {} -- mapping of player names to node names (arbitrary strings may also appear as values)
3
3
local gui_nodename2 = {} -- mapping of player names to node names (arbitrary strings may also appear as values)
4
- local gui_radius = {} -- mapping of player names to radii (arbitrary strings may also appear as values)
5
4
local gui_axis = {} -- mapping of player names to axes (one of 1, 2, 3, or 4, representing the axes in the `axis_indices` table below)
6
- local gui_length = {} -- mapping of player names to lengths (arbitrary strings may also appear as values)
5
+ local gui_distance1 = {} -- mapping of player names to a distance, usually side length (arbitrary strings may also appear as values)
6
+ local gui_distance2 = {} -- mapping of player names to a distance, usually radius (arbitrary strings may also appear as values)
7
+ local gui_distance3 = {} -- mapping of player names to a distance, usually spacing (arbitrary strings may also appear as values)
7
8
local gui_formspec = {} -- mapping of player names to formspecs (arbitrary strings may also appear as values)
8
9
10
+ -- set default values
11
+ setmetatable (gui_nodename1 , {__index = function () return " Cobblestone" end })
12
+ setmetatable (gui_nodename2 , {__index = function () return " Stone" end })
13
+ setmetatable (gui_axis , {__index = function () return 4 end })
14
+ setmetatable (gui_distance1 , {__index = function () return " 10" end })
15
+ setmetatable (gui_distance2 , {__index = function () return " 5" end })
16
+ setmetatable (gui_distance3 , {__index = function () return " 2" end })
17
+ setmetatable (gui_formspec , {__index = function () return " " end })
18
+
9
19
local axis_indices = {[" X axis" ]= 1 , [" Y axis" ]= 2 , [" Z axis" ]= 3 , [" Look direction" ]= 4 }
10
20
local axis_values = {" x" , " y" , " z" , " ?" }
21
+ setmetatable (axis_indices , {__index = function () return 4 end })
22
+ setmetatable (axis_values , {__index = function () return " ?" end })
11
23
12
24
local register_gui_chatcommand = function (identifier , name , command , callback )
13
25
callback = callback or function (name , command ) command (name , " " ) end
@@ -92,7 +104,7 @@ register_gui_chatcommand("worldedit_gui_volume", "Region Volume", "/volume")
92
104
worldedit .register_gui_function (" worldedit_gui_set" , {
93
105
name = " Set Nodes" , privs = minetest .chatcommands [" /set" ].privs ,
94
106
get_formspec = function (name )
95
- local node = gui_nodename1 [name ] or " Cobblestone "
107
+ local node = gui_nodename1 [name ]
96
108
local nodename = worldedit .normalize_nodename (node )
97
109
return " size[6.5,3]" .. worldedit .get_formspec_header (" worldedit_gui_set" ) ..
98
110
string.format (" field[0.5,1.5;4,0.8;worldedit_gui_set_node;Name;%s]" , minetest .formspec_escape (node )) ..
@@ -104,14 +116,12 @@ worldedit.register_gui_function("worldedit_gui_set", {
104
116
})
105
117
106
118
worldedit .register_gui_handler (" worldedit_gui_set" , function (name , fields )
107
- if fields .worldedit_gui_set_search then
108
- gui_nodename1 [name ] = tostring (fields .worldedit_gui_set_node )
109
- worldedit .show_page (name , " worldedit_gui_set" )
110
- return true
111
- elseif fields .worldedit_gui_set_submit then
119
+ if fields .worldedit_gui_set_search or fields .worldedit_gui_set_submit then
112
120
gui_nodename1 [name ] = tostring (fields .worldedit_gui_set_node )
113
121
worldedit .show_page (name , " worldedit_gui_set" )
114
- minetest .chatcommands [" /set" ].func (name , gui_nodename1 [name ])
122
+ if fields .worldedit_gui_set_submit then
123
+ minetest .chatcommands [" /set" ].func (name , gui_nodename1 [name ])
124
+ end
115
125
return true
116
126
end
117
127
return false
@@ -120,10 +130,8 @@ end)
120
130
worldedit .register_gui_function (" worldedit_gui_replace" , {
121
131
name = " Replace Nodes" , privs = minetest .chatcommands [" /replace" ].privs ,
122
132
get_formspec = function (name )
123
- local search = gui_nodename1 [name ] or " Cobblestone"
124
- local search_nodename = worldedit .normalize_nodename (search )
125
- local replace = gui_nodename2 [name ] or " Stone"
126
- local replace_nodename = worldedit .normalize_nodename (replace )
133
+ local search , replace = gui_nodename1 [name ], gui_nodename2 [name ]
134
+ local search_nodename , replace_nodename = worldedit .normalize_nodename (search ), worldedit .normalize_nodename (replace )
127
135
return " size[6.5,4]" .. worldedit .get_formspec_header (" worldedit_gui_replace" ) ..
128
136
string.format (" field[0.5,1.5;4,0.8;worldedit_gui_replace_search;Name;%s]" , minetest .formspec_escape (search )) ..
129
137
" button[4,1.18;1.5,0.8;worldedit_gui_replace_search_search;Search]" ..
@@ -139,21 +147,14 @@ worldedit.register_gui_function("worldedit_gui_replace", {
139
147
})
140
148
141
149
worldedit .register_gui_handler (" worldedit_gui_replace" , function (name , fields )
142
- if fields .worldedit_gui_replace_search_search then
143
- gui_nodename1 [name ] = tostring (fields .worldedit_gui_replace_search )
144
- worldedit .show_page (name , " worldedit_gui_replace" )
145
- return true
146
- elseif fields .worldedit_gui_replace_replace_search then
147
- gui_nodename2 [name ] = tostring (fields .worldedit_gui_replace_replace )
148
- worldedit .show_page (name , " worldedit_gui_replace" )
149
- return true
150
- elseif fields .worldedit_gui_replace_submit or fields .worldedit_gui_replace_submit_inverse then
150
+ if fields .worldedit_gui_replace_search_search or fields .worldedit_gui_replace_replace_search
151
+ or fields .worldedit_gui_replace_submit or fields .worldedit_gui_replace_submit_inverse then
151
152
gui_nodename1 [name ] = tostring (fields .worldedit_gui_replace_search )
152
153
gui_nodename2 [name ] = tostring (fields .worldedit_gui_replace_replace )
153
154
worldedit .show_page (name , " worldedit_gui_replace" )
154
155
if fields .worldedit_gui_replace_submit then
155
156
minetest .chatcommands [" /replace" ].func (name , string.format (" %s %s" , gui_nodename1 [name ], gui_nodename2 [name ]))
156
- else
157
+ elseif fields . worldedit_gui_replace_submit_inverse then
157
158
minetest .chatcommands [" /replaceinverse" ].func (name , string.format (" %s %s" , gui_nodename1 [name ], gui_nodename2 [name ]))
158
159
end
159
160
return true
164
165
worldedit .register_gui_function (" worldedit_gui_sphere_dome" , {
165
166
name = " Sphere/Dome" , privs = minetest .chatcommands [" /sphere" ].privs ,
166
167
get_formspec = function (name )
167
- local node = gui_nodename1 [name ] or " Cobblestone"
168
- local radius = gui_radius [name ] or " 5"
168
+ local node , radius = gui_nodename1 [name ], gui_distance2 [name ]
169
169
local nodename = worldedit .normalize_nodename (node )
170
170
return " size[6.5,5]" .. worldedit .get_formspec_header (" worldedit_gui_sphere_dome" ) ..
171
171
string.format (" field[0.5,1.5;4,0.8;worldedit_gui_sphere_dome_node;Name;%s]" , minetest .formspec_escape (node )) ..
@@ -181,23 +181,20 @@ worldedit.register_gui_function("worldedit_gui_sphere_dome", {
181
181
})
182
182
183
183
worldedit .register_gui_handler (" worldedit_gui_sphere_dome" , function (name , fields )
184
- if fields .worldedit_gui_sphere_dome_search then
185
- gui_nodename1 [name ] = tostring (fields .worldedit_gui_sphere_dome_node )
186
- worldedit .show_page (name , " worldedit_gui_sphere_dome" )
187
- return true
188
- elseif fields .worldedit_gui_sphere_dome_submit_hollow or fields .worldedit_gui_sphere_dome_submit_solid
184
+ if fields .worldedit_gui_sphere_dome_search
185
+ or fields .worldedit_gui_sphere_dome_submit_hollow or fields .worldedit_gui_sphere_dome_submit_solid
189
186
or fields .worldedit_gui_sphere_dome_submit_hollow_dome or fields .worldedit_gui_sphere_dome_submit_solid_dome then
190
187
gui_nodename1 [name ] = tostring (fields .worldedit_gui_sphere_dome_node )
191
- gui_radius [name ] = tostring (fields .worldedit_gui_sphere_dome_radius )
188
+ gui_distance2 [name ] = tostring (fields .worldedit_gui_sphere_dome_radius )
192
189
worldedit .show_page (name , " worldedit_gui_sphere_dome" )
193
190
if fields .worldedit_gui_sphere_dome_submit_hollow then
194
- minetest .chatcommands [" /hollowsphere" ].func (name , string.format (" %s %s" , gui_radius [name ], gui_nodename1 [name ]))
191
+ minetest .chatcommands [" /hollowsphere" ].func (name , string.format (" %s %s" , gui_distance2 [name ], gui_nodename1 [name ]))
195
192
elseif fields .worldedit_gui_sphere_dome_submit_solid then
196
- minetest .chatcommands [" /sphere" ].func (name , string.format (" %s %s" , gui_radius [name ], gui_nodename1 [name ]))
193
+ minetest .chatcommands [" /sphere" ].func (name , string.format (" %s %s" , gui_distance2 [name ], gui_nodename1 [name ]))
197
194
elseif fields .worldedit_gui_sphere_dome_submit_hollow_dome then
198
- minetest .chatcommands [" /hollowdome" ].func (name , string.format (" %s %s" , gui_radius [name ], gui_nodename1 [name ]))
199
- else -- fields.worldedit_gui_sphere_dome_submit_solid_dome
200
- minetest .chatcommands [" /dome" ].func (name , string.format (" %s %s" , gui_radius [name ], gui_nodename1 [name ]))
195
+ minetest .chatcommands [" /hollowdome" ].func (name , string.format (" %s %s" , gui_distance2 [name ], gui_nodename1 [name ]))
196
+ elseif fields .worldedit_gui_sphere_dome_submit_solid_dome then
197
+ minetest .chatcommands [" /dome" ].func (name , string.format (" %s %s" , gui_distance2 [name ], gui_nodename1 [name ]))
201
198
end
202
199
return true
203
200
end
@@ -207,10 +204,7 @@ end)
207
204
worldedit .register_gui_function (" worldedit_gui_cylinder" , {
208
205
name = " Cylinder" , privs = minetest .chatcommands [" /cylinder" ].privs ,
209
206
get_formspec = function (name )
210
- local node = gui_nodename1 [name ] or " Cobblestone"
211
- local axis = gui_axis [name ] or 4
212
- local length = gui_length [name ] or " 10"
213
- local radius = gui_radius [name ] or " 5"
207
+ local node , axis , length , radius = gui_nodename1 [name ], gui_axis [name ], gui_distance1 [name ], gui_distance2 [name ]
214
208
local nodename = worldedit .normalize_nodename (node )
215
209
return " size[6.5,5]" .. worldedit .get_formspec_header (" worldedit_gui_cylinder" ) ..
216
210
string.format (" field[0.5,1.5;4,0.8;worldedit_gui_cylinder_node;Name;%s]" , minetest .formspec_escape (node )) ..
@@ -226,20 +220,79 @@ worldedit.register_gui_function("worldedit_gui_cylinder", {
226
220
})
227
221
228
222
worldedit .register_gui_handler (" worldedit_gui_cylinder" , function (name , fields )
229
- if fields .worldedit_gui_cylinder_search then
230
- gui_nodename1 [name ] = fields .worldedit_gui_cylinder_node
231
- worldedit .show_page (name , " worldedit_gui_cylinder" )
232
- return true
233
- elseif fields .worldedit_gui_cylinder_submit_hollow or fields .worldedit_gui_cylinder_submit_solid then
223
+ if fields .worldedit_gui_cylinder_search
224
+ or fields .worldedit_gui_cylinder_submit_hollow or fields .worldedit_gui_cylinder_submit_solid then
234
225
gui_nodename1 [name ] = tostring (fields .worldedit_gui_cylinder_node )
235
- gui_axis [name ] = axis_indices [fields .worldedit_gui_cylinder_axis ] or 4
236
- gui_length [name ] = tostring (fields .worldedit_gui_cylinder_length )
237
- gui_radius [name ] = tostring (fields .worldedit_gui_cylinder_radius )
226
+ gui_axis [name ] = axis_indices [fields .worldedit_gui_cylinder_axis ]
227
+ gui_distance1 [name ] = tostring (fields .worldedit_gui_cylinder_length )
228
+ gui_distance2 [name ] = tostring (fields .worldedit_gui_cylinder_radius )
238
229
worldedit .show_page (name , " worldedit_gui_cylinder" )
239
230
if fields .worldedit_gui_cylinder_submit_hollow then
240
- minetest .chatcommands [" /hollowcylinder" ].func (name , string.format (" %s %s %s %s" , axis_values [gui_axis [name ]], gui_length [name ], gui_radius [name ], gui_nodename1 [name ]))
241
- else -- fields.worldedit_gui_cylinder_submit_solid
242
- minetest .chatcommands [" /cylinder" ].func (name , string.format (" %s %s %s %s" , axis_values [gui_axis [name ]], gui_length [name ], gui_radius [name ], gui_nodename1 [name ]))
231
+ minetest .chatcommands [" /hollowcylinder" ].func (name , string.format (" %s %s %s %s" , axis_values [gui_axis [name ]], gui_distance1 [name ], gui_distance2 [name ], gui_nodename1 [name ]))
232
+ elseif fields .worldedit_gui_cylinder_submit_solid then
233
+ minetest .chatcommands [" /cylinder" ].func (name , string.format (" %s %s %s %s" , axis_values [gui_axis [name ]], gui_distance1 [name ], gui_distance2 [name ], gui_nodename1 [name ]))
234
+ end
235
+ return true
236
+ end
237
+ return false
238
+ end )
239
+
240
+ worldedit .register_gui_function (" worldedit_gui_pyramid" , {
241
+ name = " Pyramid" , privs = minetest .chatcommands [" /pyramid" ].privs ,
242
+ get_formspec = function (name )
243
+ local node , axis , length = gui_nodename1 [name ], gui_axis [name ], gui_distance1 [name ]
244
+ local nodename = worldedit .normalize_nodename (node )
245
+ return " size[6.5,4]" .. worldedit .get_formspec_header (" worldedit_gui_pyramid" ) ..
246
+ string.format (" field[0.5,1.5;4,0.8;worldedit_gui_pyramid_node;Name;%s]" , minetest .formspec_escape (node )) ..
247
+ " button[4,1.18;1.5,0.8;worldedit_gui_pyramid_search;Search]" ..
248
+ (nodename and string.format (" item_image[5.5,1.1;1,1;%s]" , nodename )
249
+ or " image[5.5,1.1;1,1;unknown_node.png]" ) ..
250
+ string.format (" field[0.5,2.5;4,0.8;worldedit_gui_pyramid_length;Length;%s]" , minetest .formspec_escape (length )) ..
251
+ string.format (" dropdown[4,2.18;2.5;worldedit_gui_pyramid_axis;X axis,Y axis,Z axis,Look direction;%d]" , axis ) ..
252
+ " button_exit[0,3.5;3,0.8;worldedit_gui_pyramid_submit;Pyramid]"
253
+ end ,
254
+ })
255
+
256
+ worldedit .register_gui_handler (" worldedit_gui_pyramid" , function (name , fields )
257
+ if fields .worldedit_gui_pyramid_search or fields .worldedit_gui_pyramid_submit then
258
+ gui_nodename1 [name ] = tostring (fields .worldedit_gui_pyramid_node )
259
+ gui_axis [name ] = axis_indices [fields .worldedit_gui_pyramid_axis ]
260
+ gui_distance1 [name ] = tostring (fields .worldedit_gui_pyramid_length )
261
+ worldedit .show_page (name , " worldedit_gui_pyramid" )
262
+ if fields .worldedit_gui_pyramid_submit then
263
+ minetest .chatcommands [" /pyramid" ].func (name , string.format (" %s %s %s" , axis_values [gui_axis [name ]], gui_distance1 [name ], gui_nodename1 [name ]))
264
+ end
265
+ return true
266
+ end
267
+ return false
268
+ end )
269
+
270
+ worldedit .register_gui_function (" worldedit_gui_spiral" , {
271
+ name = " Spiral" , privs = minetest .chatcommands [" /spiral" ].privs ,
272
+ get_formspec = function (name )
273
+ local node , length , height , space = gui_nodename1 [name ], gui_distance1 [name ], gui_distance2 [name ], gui_distance3 [name ]
274
+ local nodename = worldedit .normalize_nodename (node )
275
+ return " size[6.5,6]" .. worldedit .get_formspec_header (" worldedit_gui_spiral" ) ..
276
+ string.format (" field[0.5,1.5;4,0.8;worldedit_gui_spiral_node;Name;%s]" , minetest .formspec_escape (node )) ..
277
+ " button[4,1.18;1.5,0.8;worldedit_gui_spiral_search;Search]" ..
278
+ (nodename and string.format (" item_image[5.5,1.1;1,1;%s]" , nodename )
279
+ or " image[5.5,1.1;1,1;unknown_node.png]" ) ..
280
+ string.format (" field[0.5,2.5;4,0.8;worldedit_gui_spiral_length;Side Length;%s]" , minetest .formspec_escape (length )) ..
281
+ string.format (" field[0.5,3.5;4,0.8;worldedit_gui_spiral_height;Height;%s]" , minetest .formspec_escape (height )) ..
282
+ string.format (" field[0.5,4.5;4,0.8;worldedit_gui_spiral_space;Wall Spacing;%s]" , minetest .formspec_escape (space )) ..
283
+ " button_exit[0,5.5;3,0.8;worldedit_gui_spiral_submit;Spiral]"
284
+ end ,
285
+ })
286
+
287
+ worldedit .register_gui_handler (" worldedit_gui_spiral" , function (name , fields )
288
+ if fields .worldedit_gui_spiral_search or fields .worldedit_gui_spiral_submit then
289
+ gui_nodename1 [name ] = fields .worldedit_gui_spiral_node
290
+ gui_distance1 [name ] = tostring (fields .worldedit_gui_spiral_length )
291
+ gui_distance2 [name ] = tostring (fields .worldedit_gui_spiral_height )
292
+ gui_distance3 [name ] = tostring (fields .worldedit_gui_spiral_space )
293
+ worldedit .show_page (name , " worldedit_gui_spiral" )
294
+ if fields .worldedit_gui_spiral_submit then
295
+ minetest .chatcommands [" /spiral" ].func (name , string.format (" %s %s %s %s" , gui_distance1 [name ], gui_distance2 [name ], gui_distance3 [name ], gui_nodename1 [name ]))
243
296
end
244
297
return true
245
298
end
@@ -250,7 +303,7 @@ worldedit.register_gui_function("worldedit_gui_copy_move", {
250
303
name = " Copy/Move" , privs = minetest .chatcommands [" /move" ].privs ,
251
304
get_formspec = function (name )
252
305
local axis = gui_axis [name ] or 4
253
- local amount = gui_length [name ] or " 10"
306
+ local amount = gui_distance1 [name ] or " 10"
254
307
return " size[6.5,3]" .. worldedit .get_formspec_header (" worldedit_gui_copy_move" ) ..
255
308
string.format (" field[0.5,1.5;4,0.8;worldedit_gui_copy_move_amount;Amount;%s]" , minetest .formspec_escape (amount )) ..
256
309
string.format (" dropdown[4,1.18;2.5;worldedit_gui_copy_move_axis;X axis,Y axis,Z axis,Look direction;%d]" , axis ) ..
@@ -262,12 +315,12 @@ worldedit.register_gui_function("worldedit_gui_copy_move", {
262
315
worldedit .register_gui_handler (" worldedit_gui_copy_move" , function (name , fields )
263
316
if fields .worldedit_gui_copy_move_copy or fields .worldedit_gui_copy_move_move then
264
317
gui_axis [name ] = axis_indices [fields .worldedit_gui_cylinder_axis ] or 4
265
- gui_length [name ] = tostring (fields .worldedit_gui_copy_move_amount )
318
+ gui_distance1 [name ] = tostring (fields .worldedit_gui_copy_move_amount )
266
319
worldedit .show_page (name , " worldedit_gui_copy_move" )
267
320
if fields .worldedit_gui_copy_move_copy then
268
- minetest .chatcommands [" /copy" ].func (name , string.format (" %s %s" , axis_values [gui_axis [name ]], gui_length [name ]))
321
+ minetest .chatcommands [" /copy" ].func (name , string.format (" %s %s" , axis_values [gui_axis [name ]], gui_distance1 [name ]))
269
322
else -- fields.worldedit_gui_copy_move_move
270
- minetest .chatcommands [" /move" ].func (name , string.format (" %s %s" , axis_values [gui_axis [name ]], gui_length [name ]))
323
+ minetest .chatcommands [" /move" ].func (name , string.format (" %s %s" , axis_values [gui_axis [name ]], gui_distance1 [name ]))
271
324
end
272
325
return true
273
326
end
0 commit comments