Skip to content

Commit c48cf3c

Browse files
committedDec 20, 2013
All commands in WorldEdit are now accessible through WorldEdit GUI, except the MT Schematics stuff.
1 parent 674d647 commit c48cf3c

File tree

1 file changed

+307
-28
lines changed

1 file changed

+307
-28
lines changed
 

‎worldedit_gui/functionality.lua

+307-28
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
11
--saved state for each player
22
local gui_nodename1 = {} --mapping of player names to node names (arbitrary strings may also appear as values)
33
local gui_nodename2 = {} --mapping of player names to node names (arbitrary strings may also appear as values)
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)
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)
8-
local gui_formspec = {} --mapping of player names to formspecs (arbitrary strings may also appear as values)
4+
local gui_axis1 = {} --mapping of player names to axes (one of 1, 2, 3, or 4, representing the axes in the `axis_indices` table below)
5+
local gui_axis2 = {} --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_distance1 = {} --mapping of player names to a distance (arbitrary strings may also appear as values)
7+
local gui_distance2 = {} --mapping of player names to a distance (arbitrary strings may also appear as values)
8+
local gui_distance3 = {} --mapping of player names to a distance (arbitrary strings may also appear as values)
9+
local gui_count1 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)
10+
local gui_count2 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)
11+
local gui_count3 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values)
12+
local gui_angle = {} --mapping of player names to an angle (one of 90, 180, 270, representing the angle in degrees clockwise)
13+
local gui_filename = {} --mapping of player names to file names (arbitrary strings may also appear as values)
14+
local gui_formspec = {} --mapping of player names to formspecs
15+
local gui_code = {} --mapping of player names to formspecs
916

1017
--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+
setmetatable(gui_nodename1, {__index = function() return "Cobblestone" end})
19+
setmetatable(gui_nodename2, {__index = function() return "Stone" end})
20+
setmetatable(gui_axis1, {__index = function() return 4 end})
21+
setmetatable(gui_axis2, {__index = function() return 1 end})
22+
setmetatable(gui_distance1, {__index = function() return "10" end})
23+
setmetatable(gui_distance2, {__index = function() return "5" end})
24+
setmetatable(gui_distance3, {__index = function() return "2" end})
25+
setmetatable(gui_count1, {__index = function() return "3" end})
26+
setmetatable(gui_count2, {__index = function() return "6" end})
27+
setmetatable(gui_count3, {__index = function() return "4" end})
28+
setmetatable(gui_angle, {__index = function() return 90 end})
29+
setmetatable(gui_filename, {__index = function() return "building" end})
30+
setmetatable(gui_formspec, {__index = function() return "size[5,5]\nlabel[0,0;Hello, world!]" end})
31+
setmetatable(gui_code, {__index = function() return "minetest.chat_send_player(\"singleplayer\", \"Hello, world!\")" end})
1832

1933
local axis_indices = {["X axis"]=1, ["Y axis"]=2, ["Z axis"]=3, ["Look direction"]=4}
2034
local axis_values = {"x", "y", "z", "?"}
2135
setmetatable(axis_indices, {__index = function () return 4 end})
2236
setmetatable(axis_values, {__index = function () return "?" end})
2337

38+
local angle_indices = {["90 degrees"]=1, ["180 degrees"]=2, ["270 degrees"]=3}
39+
local angle_values = {90, 180, 270}
40+
setmetatable(angle_indices, {__index = function () return 1 end})
41+
setmetatable(angle_values, {__index = function () return 90 end})
42+
2443
--given multiple sets of privileges, produces a single set of privs that would have the same effect as requiring all of them at the same time
2544
local combine_privs = function(...)
2645
local result = {}
@@ -231,7 +250,7 @@ end)
231250
worldedit.register_gui_function("worldedit_gui_cylinder", {
232251
name = "Cylinder", privs = combine_privs(minetest.chatcommands["/hollowcylinder"].privs, minetest.chatcommands["/cylinder"].privs),
233252
get_formspec = function(name)
234-
local node, axis, length, radius = gui_nodename1[name], gui_axis[name], gui_distance1[name], gui_distance2[name]
253+
local node, axis, length, radius = gui_nodename1[name], gui_axis1[name], gui_distance1[name], gui_distance2[name]
235254
local nodename = worldedit.normalize_nodename(node)
236255
return "size[6.5,5]" .. worldedit.get_formspec_header("worldedit_gui_cylinder") ..
237256
string.format("field[0.5,1.5;4,0.8;worldedit_gui_cylinder_node;Name;%s]", minetest.formspec_escape(node)) ..
@@ -250,14 +269,14 @@ worldedit.register_gui_handler("worldedit_gui_cylinder", function(name, fields)
250269
if fields.worldedit_gui_cylinder_search
251270
or fields.worldedit_gui_cylinder_submit_hollow or fields.worldedit_gui_cylinder_submit_solid then
252271
gui_nodename1[name] = tostring(fields.worldedit_gui_cylinder_node)
253-
gui_axis[name] = axis_indices[fields.worldedit_gui_cylinder_axis]
272+
gui_axis1[name] = axis_indices[fields.worldedit_gui_cylinder_axis]
254273
gui_distance1[name] = tostring(fields.worldedit_gui_cylinder_length)
255274
gui_distance2[name] = tostring(fields.worldedit_gui_cylinder_radius)
256275
worldedit.show_page(name, "worldedit_gui_cylinder")
257276
if fields.worldedit_gui_cylinder_submit_hollow then
258-
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]))
277+
minetest.chatcommands["/hollowcylinder"].func(name, string.format("%s %s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_distance2[name], gui_nodename1[name]))
259278
elseif fields.worldedit_gui_cylinder_submit_solid then
260-
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]))
279+
minetest.chatcommands["/cylinder"].func(name, string.format("%s %s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_distance2[name], gui_nodename1[name]))
261280
end
262281
return true
263282
end
@@ -267,7 +286,7 @@ end)
267286
worldedit.register_gui_function("worldedit_gui_pyramid", {
268287
name = "Pyramid", privs = minetest.chatcommands["/pyramid"].privs,
269288
get_formspec = function(name)
270-
local node, axis, length = gui_nodename1[name], gui_axis[name], gui_distance1[name]
289+
local node, axis, length = gui_nodename1[name], gui_axis1[name], gui_distance1[name]
271290
local nodename = worldedit.normalize_nodename(node)
272291
return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_pyramid") ..
273292
string.format("field[0.5,1.5;4,0.8;worldedit_gui_pyramid_node;Name;%s]", minetest.formspec_escape(node)) ..
@@ -283,11 +302,11 @@ worldedit.register_gui_function("worldedit_gui_pyramid", {
283302
worldedit.register_gui_handler("worldedit_gui_pyramid", function(name, fields)
284303
if fields.worldedit_gui_pyramid_search or fields.worldedit_gui_pyramid_submit then
285304
gui_nodename1[name] = tostring(fields.worldedit_gui_pyramid_node)
286-
gui_axis[name] = axis_indices[fields.worldedit_gui_pyramid_axis]
305+
gui_axis1[name] = axis_indices[fields.worldedit_gui_pyramid_axis]
287306
gui_distance1[name] = tostring(fields.worldedit_gui_pyramid_length)
288307
worldedit.show_page(name, "worldedit_gui_pyramid")
289308
if fields.worldedit_gui_pyramid_submit then
290-
minetest.chatcommands["/pyramid"].func(name, string.format("%s %s %s", axis_values[gui_axis[name]], gui_distance1[name], gui_nodename1[name]))
309+
minetest.chatcommands["/pyramid"].func(name, string.format("%s %s %s", axis_values[gui_axis1[name]], gui_distance1[name], gui_nodename1[name]))
291310
end
292311
return true
293312
end
@@ -329,7 +348,7 @@ end)
329348
worldedit.register_gui_function("worldedit_gui_copy_move", {
330349
name = "Copy/Move", privs = combine_privs(minetest.chatcommands["/copy"].privs, minetest.chatcommands["/move"].privs),
331350
get_formspec = function(name)
332-
local axis = gui_axis[name] or 4
351+
local axis = gui_axis1[name] or 4
333352
local amount = gui_distance1[name] or "10"
334353
return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_copy_move") ..
335354
string.format("field[0.5,1.5;4,0.8;worldedit_gui_copy_move_amount;Amount;%s]", minetest.formspec_escape(amount)) ..
@@ -341,23 +360,286 @@ worldedit.register_gui_function("worldedit_gui_copy_move", {
341360

342361
worldedit.register_gui_handler("worldedit_gui_copy_move", function(name, fields)
343362
if fields.worldedit_gui_copy_move_copy or fields.worldedit_gui_copy_move_move then
344-
gui_axis[name] = axis_indices[fields.worldedit_gui_cylinder_axis] or 4
363+
gui_axis1[name] = axis_indices[fields.worldedit_gui_cylinder_axis] or 4
345364
gui_distance1[name] = tostring(fields.worldedit_gui_copy_move_amount)
346365
worldedit.show_page(name, "worldedit_gui_copy_move")
347366
if fields.worldedit_gui_copy_move_copy then
348-
minetest.chatcommands["/copy"].func(name, string.format("%s %s", axis_values[gui_axis[name]], gui_distance1[name]))
367+
minetest.chatcommands["/copy"].func(name, string.format("%s %s", axis_values[gui_axis1[name]], gui_distance1[name]))
349368
else --fields.worldedit_gui_copy_move_move
350-
minetest.chatcommands["/move"].func(name, string.format("%s %s", axis_values[gui_axis[name]], gui_distance1[name]))
369+
minetest.chatcommands["/move"].func(name, string.format("%s %s", axis_values[gui_axis1[name]], gui_distance1[name]))
351370
end
352371
return true
353372
end
354373
return false
355374
end)
356375

376+
worldedit.register_gui_function("worldedit_gui_stack", {
377+
name = "Stack", privs = minetest.chatcommands["/stack"].privs,
378+
get_formspec = function(name)
379+
local axis, count = gui_axis1[name], gui_count1[name]
380+
return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_stack") ..
381+
string.format("field[0.5,1.5;4,0.8;worldedit_gui_stack_count;Count;%s]", minetest.formspec_escape(count)) ..
382+
string.format("dropdown[4,1.18;2.5;worldedit_gui_stack_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
383+
"button_exit[0,2.5;3,0.8;worldedit_gui_stack_submit;Stack]"
384+
end,
385+
})
386+
387+
worldedit.register_gui_handler("worldedit_gui_stack", function(name, fields)
388+
if fields.worldedit_gui_stack_submit then
389+
gui_axis1[name] = axis_indices[fields.worldedit_gui_stack_axis]
390+
gui_count1[name] = tostring(fields.worldedit_gui_stack_count)
391+
worldedit.show_page(name, "worldedit_gui_stack")
392+
minetest.chatcommands["/stack"].func(name, string.format("%s %s", axis_values[gui_axis1[name]], gui_count1[name]))
393+
return true
394+
end
395+
return false
396+
end)
397+
398+
worldedit.register_gui_function("worldedit_gui_stretch", {
399+
name = "Stretch", privs = minetest.chatcommands["/stretch"].privs,
400+
get_formspec = function(name)
401+
local stretchx, stretchy, stretchz = gui_count1[name], gui_count2[name], gui_count3[name]
402+
return "size[5,5]" .. worldedit.get_formspec_header("worldedit_gui_stretch") ..
403+
string.format("field[0.5,1.5;4,0.8;worldedit_gui_stretch_x;Stretch X;%s]", minetest.formspec_escape(stretchx)) ..
404+
string.format("field[0.5,2.5;4,0.8;worldedit_gui_stretch_y;Stretch Y;%s]", minetest.formspec_escape(stretchy)) ..
405+
string.format("field[0.5,3.5;4,0.8;worldedit_gui_stretch_z;Stretch Z;%s]", minetest.formspec_escape(stretchz)) ..
406+
"button_exit[0,4.5;3,0.8;worldedit_gui_stretch_submit;Stretch]"
407+
end,
408+
})
409+
410+
worldedit.register_gui_handler("worldedit_gui_stretch", function(name, fields)
411+
if fields.worldedit_gui_stretch_submit then
412+
gui_count1[name] = tostring(fields.worldedit_gui_stretch_x)
413+
gui_count2[name] = tostring(fields.worldedit_gui_stretch_y)
414+
gui_count3[name] = tostring(fields.worldedit_gui_stretch_z)
415+
worldedit.show_page(name, "worldedit_gui_stretch")
416+
minetest.chatcommands["/stretch"].func(name, string.format("%s %s %s", gui_count1[name], gui_count2[name], gui_count3[name]))
417+
return true
418+
end
419+
return false
420+
end)
421+
422+
worldedit.register_gui_function("worldedit_gui_transpose", {
423+
name = "Transpose", privs = minetest.chatcommands["/transpose"].privs,
424+
get_formspec = function(name)
425+
local axis1, axis2 = gui_axis1[name], gui_axis2[name]
426+
return "size[5.5,3]" .. worldedit.get_formspec_header("worldedit_gui_transpose") ..
427+
string.format("dropdown[0,1;2.5;worldedit_gui_transpose_axis1;X axis,Y axis,Z axis,Look direction;%d]", axis1) ..
428+
string.format("dropdown[3,1;2.5;worldedit_gui_transpose_axis2;X axis,Y axis,Z axis,Look direction;%d]", axis2) ..
429+
"button_exit[0,2.5;3,0.8;worldedit_gui_transpose_submit;Transpose]"
430+
end,
431+
})
432+
433+
worldedit.register_gui_handler("worldedit_gui_transpose", function(name, fields)
434+
if fields.worldedit_gui_transpose_submit then
435+
gui_axis1[name] = axis_indices[fields.worldedit_gui_transpose_axis1]
436+
gui_axis2[name] = axis_indices[fields.worldedit_gui_transpose_axis2]
437+
worldedit.show_page(name, "worldedit_gui_transpose")
438+
minetest.chatcommands["/transpose"].func(name, string.format("%s %s", axis_values[gui_axis1[name]], axis_values[gui_axis2[name]]))
439+
return true
440+
end
441+
return false
442+
end)
443+
444+
worldedit.register_gui_function("worldedit_gui_flip", {
445+
name = "Flip", privs = minetest.chatcommands["/flip"].privs,
446+
get_formspec = function(name)
447+
local axis = gui_axis2[name]
448+
return "size[5,3]" .. worldedit.get_formspec_header("worldedit_gui_flip") ..
449+
string.format("dropdown[0,1;2.5;worldedit_gui_flip_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
450+
"button_exit[0,2.5;3,0.8;worldedit_gui_flip_submit;Flip]"
451+
end,
452+
})
453+
454+
worldedit.register_gui_handler("worldedit_gui_flip", function(name, fields)
455+
if fields.worldedit_gui_flip_submit then
456+
gui_axis2[name] = axis_indices[fields.worldedit_gui_flip_axis]
457+
worldedit.show_page(name, "worldedit_gui_flip")
458+
minetest.chatcommands["/flip"].func(name, axis_values[gui_axis2[name]])
459+
return true
460+
end
461+
return false
462+
end)
463+
464+
worldedit.register_gui_function("worldedit_gui_rotate", {
465+
name = "Rotate", privs = minetest.chatcommands["/rotate"].privs,
466+
get_formspec = function(name)
467+
local axis, angle = gui_axis1[name], gui_angle[name]
468+
return "size[5.5,3]" .. worldedit.get_formspec_header("worldedit_gui_rotate") ..
469+
string.format("dropdown[0,1;2.5;worldedit_gui_rotate_angle;90 degrees,180 degrees,270 degrees;%s]", angle) ..
470+
string.format("dropdown[3,1;2.5;worldedit_gui_rotate_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) ..
471+
"button_exit[0,2.5;3,0.8;worldedit_gui_rotate_submit;Rotate]"
472+
end,
473+
})
474+
475+
worldedit.register_gui_handler("worldedit_gui_rotate", function(name, fields)
476+
if fields.worldedit_gui_rotate_submit then
477+
gui_axis1[name] = axis_indices[fields.worldedit_gui_rotate_axis]
478+
gui_angle[name] = angle_indices[fields.worldedit_gui_rotate_angle]
479+
worldedit.show_page(name, "worldedit_gui_rotate")
480+
minetest.chatcommands["/rotate"].func(name, string.format("%s %s", axis_values[gui_axis1[name]], angle_values[gui_angle[name]]))
481+
return true
482+
end
483+
return false
484+
end)
485+
486+
worldedit.register_gui_function("worldedit_gui_orient", {
487+
name = "Orient", privs = minetest.chatcommands["/orient"].privs,
488+
get_formspec = function(name)
489+
local angle = gui_angle[name]
490+
return "size[5,3]" .. worldedit.get_formspec_header("worldedit_gui_orient") ..
491+
string.format("dropdown[0,1;2.5;worldedit_gui_rotate_angle;90 degrees,180 degrees,270 degrees;%s]", angle) ..
492+
"button_exit[0,2.5;3,0.8;worldedit_gui_orient_submit;Orient]"
493+
end,
494+
})
495+
496+
worldedit.register_gui_handler("worldedit_gui_orient", function(name, fields)
497+
if fields.worldedit_gui_orient_submit then
498+
gui_angle[name] = angle_indices[fields.worldedit_gui_orient_angle]
499+
worldedit.show_page(name, "worldedit_gui_orient")
500+
minetest.chatcommands["/orient"].func(name, angle_values[gui_angle[name]])
501+
return true
502+
end
503+
return false
504+
end)
505+
506+
worldedit.register_gui_function("worldedit_gui_fixlight", {
507+
name = "Fix Lighting", privs = minetest.chatcommands["/fixlight"].privs,
508+
on_select = function(name)
509+
minetest.chatcommands["/fixlight"].func(name, "")
510+
end,
511+
})
512+
513+
worldedit.register_gui_function("worldedit_gui_hide", {
514+
name = "Hide Region", privs = minetest.chatcommands["/hide"].privs,
515+
on_select = function(name)
516+
minetest.chatcommands["/hide"].func(name, "")
517+
end,
518+
})
519+
520+
worldedit.register_gui_function("worldedit_gui_suppress", {
521+
name = "Suppress Nodes", privs = minetest.chatcommands["/suppress"].privs,
522+
get_formspec = function(name)
523+
local node = gui_nodename1[name]
524+
local nodename = worldedit.normalize_nodename(node)
525+
return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_suppress") ..
526+
string.format("field[0.5,1.5;4,0.8;worldedit_gui_suppress_node;Name;%s]", minetest.formspec_escape(node)) ..
527+
"button[4,1.18;1.5,0.8;worldedit_gui_suppress_search;Search]" ..
528+
(nodename and string.format("item_image[5.5,1.1;1,1;%s]", nodename)
529+
or "image[5.5,1.1;1,1;unknown_node.png]") ..
530+
"button_exit[0,2.5;3,0.8;worldedit_gui_suppress_submit;Suppress Nodes]"
531+
end,
532+
})
533+
534+
worldedit.register_gui_handler("worldedit_gui_suppress", function(name, fields)
535+
if fields.worldedit_gui_suppress_search or fields.worldedit_gui_suppress_submit then
536+
gui_nodename1[name] = tostring(fields.worldedit_gui_suppress_node)
537+
worldedit.show_page(name, "worldedit_gui_suppress")
538+
if fields.worldedit_gui_suppress_submit then
539+
minetest.chatcommands["/suppress"].func(name, gui_nodename1[name])
540+
end
541+
return true
542+
end
543+
return false
544+
end)
545+
546+
worldedit.register_gui_function("worldedit_gui_highlight", {
547+
name = "Highlight Nodes", privs = minetest.chatcommands["/highlight"].privs,
548+
get_formspec = function(name)
549+
local node = gui_nodename1[name]
550+
local nodename = worldedit.normalize_nodename(node)
551+
return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_highlight") ..
552+
string.format("field[0.5,1.5;4,0.8;worldedit_gui_highlight_node;Name;%s]", minetest.formspec_escape(node)) ..
553+
"button[4,1.18;1.5,0.8;worldedit_gui_highlight_search;Search]" ..
554+
(nodename and string.format("item_image[5.5,1.1;1,1;%s]", nodename)
555+
or "image[5.5,1.1;1,1;unknown_node.png]") ..
556+
"button_exit[0,2.5;3,0.8;worldedit_gui_highlight_submit;Highlight Nodes]"
557+
end,
558+
})
559+
560+
worldedit.register_gui_handler("worldedit_gui_highlight", function(name, fields)
561+
if fields.worldedit_gui_highlight_search or fields.worldedit_gui_highlight_submit then
562+
gui_nodename1[name] = tostring(fields.worldedit_gui_highlight_node)
563+
worldedit.show_page(name, "worldedit_gui_highlight")
564+
if fields.worldedit_gui_highlight_submit then
565+
minetest.chatcommands["/highlight"].func(name, gui_nodename1[name])
566+
end
567+
return true
568+
end
569+
return false
570+
end)
571+
572+
worldedit.register_gui_function("worldedit_gui_restore", {
573+
name = "Restore Region", privs = minetest.chatcommands["/restore"].privs,
574+
on_select = function(name)
575+
minetest.chatcommands["/restore"].func(name, "")
576+
end,
577+
})
578+
579+
worldedit.register_gui_function("worldedit_gui_save_load", {
580+
name = "Save/Load", privs = combine_privs(minetest.chatcommands["/save"].privs, minetest.chatcommands["/allocate"].privs, minetest.chatcommands["/load"].privs),
581+
get_formspec = function(name)
582+
local filename = gui_filename[name]
583+
return "size[6,4]" .. worldedit.get_formspec_header("worldedit_gui_save_load") ..
584+
string.format("field[0.5,1.5;4,0.8;worldedit_gui_save_filename;Filename;%s]", minetest.formspec_escape(filename)) ..
585+
"button_exit[0,2.5;3,0.8;worldedit_gui_save_load_submit_save;Save]" ..
586+
"button_exit[3,2.5;3,0.8;worldedit_gui_save_load_submit_allocate;Allocate]" ..
587+
"button_exit[0,3.5;3,0.8;worldedit_gui_save_load_submit_load;Load]"
588+
end,
589+
})
590+
591+
worldedit.register_gui_handler("worldedit_gui_save", function(name, fields)
592+
if fields.worldedit_gui_save_load_submit_save or worldedit_gui_save_load_submit_allocate or worldedit_gui_save_load_submit_load then
593+
gui_filename[name] = tostring(fields.worldedit_gui_save_axis)
594+
worldedit.show_page(name, "worldedit_gui_save_load")
595+
if fields.worldedit_gui_save_load_submit_save then
596+
minetest.chatcommands["/save"].func(name, gui_filename[name])
597+
elseif fields.worldedit_gui_save_load_submit_allocate then
598+
minetest.chatcommands["/allocate"].func(name, gui_filename[name])
599+
else --fields.worldedit_gui_save_load_submit_load
600+
minetest.chatcommands["/load"].func(name, gui_filename[name])
601+
end
602+
return true
603+
end
604+
return false
605+
end)
606+
607+
worldedit.register_gui_function("worldedit_gui_lua", {
608+
name = "Run Lua",
609+
get_formspec = function(name)
610+
local code = gui_code[name]
611+
return "size[8,6.5]" .. worldedit.get_formspec_header("worldedit_gui_lua") ..
612+
string.format("textarea[0.5,1;7.5,5.5;worldedit_gui_lua_code;Lua Code;%s]", minetest.formspec_escape(code)) ..
613+
"button_exit[0,6;3,0.8;worldedit_gui_lua_run;Run Lua]" ..
614+
"button_exit[5,6;3,0.8;worldedit_gui_lua_transform;Lua Transform]"
615+
end,
616+
})
617+
618+
worldedit.register_gui_handler("worldedit_gui_lua", function(name, fields)
619+
if fields.worldedit_gui_lua_run or fields.worldedit_gui_lua_transform then
620+
gui_code[name] = fields.worldedit_gui_lua_value
621+
worldedit.show_page(name, "worldedit_gui_lua")
622+
if fields.worldedit_gui_lua_run then
623+
minetest.chatcommands["/lua"].func(name, gui_code[name])
624+
else --fields.worldedit_gui_lua_transform
625+
minetest.chatcommands["/luatransform"].func(name, gui_code[name])
626+
end
627+
return true
628+
end
629+
return false
630+
end)
631+
632+
worldedit.register_gui_function("worldedit_gui_clearobjects", {
633+
name = "Clear Objects", privs = minetest.chatcommands["/clearobjects"].privs,
634+
on_select = function(name)
635+
minetest.chatcommands["/clearobjects"].func(name, "")
636+
end,
637+
})
638+
357639
worldedit.register_gui_function("worldedit_gui_formspec_tester", {
358640
name = "Formspec Tester",
359641
get_formspec = function(name)
360-
local value = gui_formspec[name] or ""
642+
local value = gui_formspec[name]
361643
return "size[8,6.5]" .. worldedit.get_formspec_header("worldedit_gui_formspec_tester") ..
362644
string.format("textarea[0.5,1;7.5,5.5;worldedit_gui_formspec_tester_value;Formspec Code;%s]", minetest.formspec_escape(value)) ..
363645
"button_exit[0,6;3,0.8;worldedit_gui_formspec_tester_show;Show Formspec]"
@@ -372,7 +654,4 @@ worldedit.register_gui_handler("worldedit_gui_formspec_tester", function(name, f
372654
return true
373655
end
374656
return false
375-
end)
376-
377-
--wip: those other commands
378-
--wip: Run Lua and Lua Transform
657+
end)

0 commit comments

Comments
 (0)
Please sign in to comment.