From ed7a6c966673159b52002f8ba3d319881f2635c7 Mon Sep 17 00:00:00 2001 From: blut Date: Tue, 18 Feb 2025 14:55:54 +0100 Subject: [PATCH] stuff I forgot to commit and the GUI changes for WorldEdit GUI --- ChatCommands.md | 11 +++++------ WorldEdit API.md | 4 ++-- worldedit_commands/transform.lua | 27 +++++++++++++++------------ worldedit_gui/functionality.lua | 21 +++++++++++++++++---- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/ChatCommands.md b/ChatCommands.md index 1b7a1c0..0d6cfc3 100644 --- a/ChatCommands.md +++ b/ChatCommands.md @@ -330,14 +330,13 @@ Rotate the current WorldEdit positions and region along the given axis by angle //rotate z 270 //rotate ? -90 -### `//orient ` +### `//orient ` -Rotate oriented nodes in the current WorldEdit region around the Y axis by angle `` (90 degree increment) +Change orientation of all oriented nodes in the current WorldEdit region performing (rotate or flip) around the axis by angle (90 degree increment, unused for flip operation). - //orient 90 - //orient 180 - //orient 270 - //orient -90 + //orient rotate x 90 + //orient rotate y -90 + //orient flip x 0 ### `//fixlight` diff --git a/WorldEdit API.md b/WorldEdit API.md index ae27f41..fd9285b 100644 --- a/WorldEdit API.md +++ b/WorldEdit API.md @@ -102,9 +102,9 @@ Rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees c Returns the number of nodes rotated, the new position 1, and the new position 2. -### count = worldedit.orient(pos1, pos2, angle) +### count = worldedit.orient(pos1, pos2, operation, axis, angle) -Rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis. +Change orientation of all oriented nodes in a region defined by the positions `pos1` and `pos2` performing `operation` (rotate or flip) around the `axis` axis by angle `angle` (90 degree increment, unused for flip operation). Returns the number of nodes oriented. diff --git a/worldedit_commands/transform.lua b/worldedit_commands/transform.lua index ce3d085..08b9a9f 100644 --- a/worldedit_commands/transform.lua +++ b/worldedit_commands/transform.lua @@ -244,25 +244,28 @@ worldedit.register_command("rotate", { }) worldedit.register_command("orient", { - params = "", - description = S("Rotate oriented nodes in the current WorldEdit region around the Y axis by angle (90 degree increment)"), + params = " x/y/z/? []", + description = S("Change orientation of all oriented nodes in the current WorldEdit region performing (rotate or flip) around the axis by angle (90 degree increment, unused for flip operation)"), category = S("Transformations"), privs = {worldedit=true}, require_pos = 2, parse = function(param) - local found, _, angle = param:find("^([+-]?%d+)$") - if found == nil then - return false - end - angle = tonumber(angle) - if angle % 90 ~= 0 then - return false, S("invalid usage: angle must be multiple of 90") + local operation, axis, angle = unpack(param:split(" ")) + --~ return true, operation, axis, angle + if (operation == 'flip' or operation == 'rotate') and (axis == 'x' or axis == 'y' or axis == 'z' or axis == '?') then + if operation == 'rotate' then + angle = tonumber(angle) or 90 + if angle % 90 ~= 0 then + return false, S("invalid usage: angle must be multiple of 90") + end + end + return true, operation, axis, angle end - return true, angle end, nodes_needed = check_region, - func = function(name, angle) - local count = worldedit.orient(worldedit.pos1[name], worldedit.pos2[name], angle) + func = function(name, operation, axis, angle) + if axis == "?" then axis = worldedit.player_axis(name) end + local count = worldedit.orient(worldedit.pos1[name], worldedit.pos2[name], operation, axis, angle) return true, S("@1 nodes oriented", count) end, }) diff --git a/worldedit_gui/functionality.lua b/worldedit_gui/functionality.lua index 75c205a..df35ac1 100644 --- a/worldedit_gui/functionality.lua +++ b/worldedit_gui/functionality.lua @@ -10,6 +10,7 @@ local gui_count1 = {} --mapping of player names to a quantity (arbitrary strings local gui_count2 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values) local gui_count3 = {} --mapping of player names to a quantity (arbitrary strings may also appear as values) local gui_angle = {} --mapping of player names to an angle (one of 90, 180, 270, representing the angle in degrees clockwise) +local gui_operation = {} -- mapping of player names to operations (flip or rotate, see orient command) local gui_filename = {} --mapping of player names to file names local gui_param2 = {} --mapping of player names to param2 values @@ -25,6 +26,7 @@ setmetatable(gui_count1, {__index = function() return "3" end}) setmetatable(gui_count2, {__index = function() return "6" end}) setmetatable(gui_count3, {__index = function() return "4" end}) setmetatable(gui_angle, {__index = function() return 90 end}) +setmetatable(gui_operation, {__index = function() return 1 end}) setmetatable(gui_filename, {__index = function() return "building" end}) setmetatable(gui_param2, {__index = function() return "0" end}) @@ -38,6 +40,11 @@ local angle_values = {90, 180, 270} setmetatable(angle_indices, {__index = function () return 1 end}) setmetatable(angle_values, {__index = function () return 90 end}) +local operation_indices = {["Rotate"]=1, ["Flip"]=2} +local operation_values = {"rotate", "flip"} +setmetatable(operation_indices, {__index = function () return 1 end}) +setmetatable(operation_values, {__index = function () return "rotate" end}) + -- 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 local combine_privs = function(...) local result = {} @@ -85,6 +92,8 @@ local function copy_changes(name, fields, def) into[name] = axis_indices[value] elseif into == gui_angle then into[name] = angle_indices[value] + elseif into == gui_operation then + into[name] = operation_indices[value] else into[name] = value end @@ -703,15 +712,19 @@ worldedit.register_gui_function("worldedit_gui_orient", { name = "Orient", privs = we_privs("orient"), get_formspec = function(name) - local angle = gui_angle[name] - return "size[5,3]" .. worldedit.get_formspec_header("worldedit_gui_orient") .. - string.format("dropdown[0,1;2.5;worldedit_gui_orient_angle;90 degrees,180 degrees,270 degrees;%s]", angle) .. + local operation, axis, angle = gui_operation[name], gui_axis1[name], gui_angle[name] + return "size[8.5,3]" .. worldedit.get_formspec_header("worldedit_gui_orient") .. + string.format("dropdown[0,1;2.5;worldedit_gui_orient_operation;Rotate,Flip;%d]", operation) .. + string.format("dropdown[3,1;2.5;worldedit_gui_orient_axis;X axis,Y axis,Z axis,Look direction;%d]", axis) .. + string.format("dropdown[6,1;2.5;worldedit_gui_orient_angle;90 degrees,180 degrees,270 degrees;%s]", angle) .. "button_exit[0,2.5;3,0.8;worldedit_gui_orient_submit;Orient]" end, }) worldedit.register_gui_handler("worldedit_gui_orient", function(name, fields) local cg = { + worldedit_gui_orient_operation = gui_operation, + worldedit_gui_orient_axis = gui_axis1, worldedit_gui_orient_angle = gui_angle, } local ret = handle_changes(name, "worldedit_gui_orient", fields, cg) @@ -720,7 +733,7 @@ worldedit.register_gui_handler("worldedit_gui_orient", function(name, fields) worldedit.show_page(name, "worldedit_gui_orient") execute_worldedit_command("orient", name, - tostring(angle_values[gui_angle[name]])) + string.format("%s %s %s", operation_values[gui_operation[name]], axis_values[gui_axis1[name]], angle_values[gui_angle[name]])) return true end return ret