From 9b26034aea746d6732af50ce5712096d6bdd7140 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 7 Apr 2020 00:14:31 +0200 Subject: [PATCH] Move worldedit.marker_update Markers are part of the UI (`worldedit_chatcommands`) and do not belong in `worldedit`. --- worldedit/cuboid.lua | 15 --------------- worldedit_brush/init.lua | 2 +- worldedit_commands/init.lua | 24 ++++++++---------------- worldedit_commands/mark.lua | 19 +++++++++++++++---- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/worldedit/cuboid.lua b/worldedit/cuboid.lua index d98e25c..d27e233 100644 --- a/worldedit/cuboid.lua +++ b/worldedit/cuboid.lua @@ -98,21 +98,6 @@ worldedit.marker_move = function(name, marker, deltavector) return true end --- Updates the location ingame of the markers -worldedit.marker_update = function(name, marker) - if marker == nil then - worldedit.mark_pos1(name) - worldedit.mark_pos2(name) - elseif marker == 1 then - worldedit.mark_pos1(name) - elseif marker == 2 then - worldedit.mark_pos2(name) - else - minetest.debug( - "worldedit: Invalid execution of function update_markers") - end -end - -- Returns two vectors with the directions for volumetric expansion worldedit.get_expansion_directions = function(mark1, mark2) diff --git a/worldedit_brush/init.lua b/worldedit_brush/init.lua index 0c1ff95..369b6b5 100644 --- a/worldedit_brush/init.lua +++ b/worldedit_brush/init.lua @@ -39,7 +39,7 @@ local brush_on_use = function(itemstack, placer) assert(pointed_thing.type == "node") worldedit.pos1[name] = pointed_thing.under worldedit.pos2[name] = nil - worldedit.mark_region(name) + worldedit.marker_update(name) -- this isn't really clean... local player_notify_old = worldedit.player_notify diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 91c1644..32bbc6c 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -333,8 +333,7 @@ worldedit.register_command("reset", { func = function(name) worldedit.pos1[name] = nil worldedit.pos2[name] = nil - worldedit.mark_pos1(name) - worldedit.mark_pos2(name) + worldedit.marker_update(name) worldedit.set_pos[name] = nil --make sure the user does not try to confirm an operation after resetting pos: reset_pending(name) @@ -347,8 +346,7 @@ worldedit.register_command("mark", { description = "Show markers at the region positions", privs = {worldedit=true}, func = function(name) - worldedit.mark_pos1(name) - worldedit.mark_pos2(name) + worldedit.marker_update(name) worldedit.player_notify(name, "region marked") end, }) @@ -361,8 +359,7 @@ worldedit.register_command("unmark", { local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] worldedit.pos1[name] = nil worldedit.pos2[name] = nil - worldedit.mark_pos1(name) - worldedit.mark_pos2(name) + worldedit.marker_update(name) worldedit.pos1[name] = pos1 worldedit.pos2[name] = pos2 worldedit.player_notify(name, "region unmarked") @@ -945,8 +942,7 @@ worldedit.register_command("move", { pos1[axis] = pos1[axis] + amount pos2[axis] = pos2[axis] + amount - worldedit.mark_pos1(name) - worldedit.mark_pos2(name) + worldedit.marker_update(name) worldedit.player_notify(name, count .. " nodes moved") end, }) @@ -1037,8 +1033,7 @@ worldedit.register_command("stretch", { --reset markers to scaled positions worldedit.pos1[name] = pos1 worldedit.pos2[name] = pos2 - worldedit.mark_pos1(name) - worldedit.mark_pos2(name) + worldedit.marker_update(name) worldedit.player_notify(name, count .. " nodes stretched") end, @@ -1068,8 +1063,7 @@ worldedit.register_command("transpose", { --reset markers to transposed positions worldedit.pos1[name] = pos1 worldedit.pos2[name] = pos2 - worldedit.mark_pos1(name) - worldedit.mark_pos2(name) + worldedit.marker_update(name) worldedit.player_notify(name, count .. " nodes transposed") end, @@ -1119,8 +1113,7 @@ worldedit.register_command("rotate", { --reset markers to rotated positions worldedit.pos1[name] = pos1 worldedit.pos2[name] = pos2 - worldedit.mark_pos1(name) - worldedit.mark_pos2(name) + worldedit.marker_update(name) worldedit.player_notify(name, count .. " nodes rotated") end, @@ -1346,9 +1339,8 @@ worldedit.register_command("allocate", { end worldedit.pos1[name] = nodepos1 - worldedit.mark_pos1(name) worldedit.pos2[name] = nodepos2 - worldedit.mark_pos2(name) + worldedit.marker_update(name) worldedit.player_notify(name, count .. " nodes allocated") end, diff --git a/worldedit_commands/mark.lua b/worldedit_commands/mark.lua index cb45075..874999d 100644 --- a/worldedit_commands/mark.lua +++ b/worldedit_commands/mark.lua @@ -3,7 +3,7 @@ worldedit.marker2 = {} worldedit.marker_region = {} --marks worldedit region position 1 -worldedit.mark_pos1 = function(name) +worldedit.mark_pos1 = function(name, region_too) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if pos1 ~= nil then @@ -22,11 +22,13 @@ worldedit.mark_pos1 = function(name) worldedit.marker1[name]:get_luaentity().player_name = name end end - worldedit.mark_region(name) + if region_too == nil or region_too then + worldedit.mark_region(name) + end end --marks worldedit region position 2 -worldedit.mark_pos2 = function(name) +worldedit.mark_pos2 = function(name, region_too) local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] if pos2 ~= nil then @@ -45,7 +47,9 @@ worldedit.mark_pos2 = function(name) worldedit.marker2[name]:get_luaentity().player_name = name end end - worldedit.mark_region(name) + if region_too == nil or region_too then + worldedit.mark_region(name) + end end worldedit.mark_region = function(name) @@ -111,6 +115,13 @@ worldedit.mark_region = function(name) end end +--convenience function that calls everything +worldedit.marker_update = function(name) + worldedit.mark_pos1(name, false) + worldedit.mark_pos2(name, false) + worldedit.mark_region(name) +end + minetest.register_entity(":worldedit:pos1", { initial_properties = { visual = "cube",