From bb8456b71119ca6303b9e9706829a84dc7f81ab3 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Wed, 29 Oct 2014 22:47:08 -0400 Subject: Cleanup and fixup Non-stylistic changes: * Add LuaDoc/LDoc support. * Fix `clear_objects` area size calculation. * Fix `clear_objects` removing player objects. * Fix shadowing of marker entity name with player name. * Make visualization functions use `swap_node`. * Make hidden nodes unwalkable. * Prevent `hide` from hiding air. * Make deprecated functions log to deprecated stream when called. * Fixed `replaceinverse` not using normalized node names. * Added .gitignore. * Bump version to 1.1. Stylistic changes: * Change `x = function` to `function x`. * Change comment format. * Make missing VoxelManip error less obnoxious. * Move `sort_pos` into `common.lua`, which is a required module. * Remove local copies of `minetest`. * Remove `worldedit = worldedit or {}` from modules. * Replace replaceinverse with an inverse argument to `replace`. * Added `error()`s on on invalid axes. * Change `wip` to `TODO`. * Rename `clearobjects` to `clear_objects`. * Remove `hollow_{sphere,dome,cylinder}` and replace them with a hollow parameter to each function. * Add helpers to reduce code duplication. * Renamed `Chat Commands.md` to `ChatCommands.md`. --- worldedit_commands/init.lua | 28 ++++++++++++++-------------- worldedit_commands/mark.lua | 25 +++++++++++++------------ 2 files changed, 27 insertions(+), 26 deletions(-) (limited to 'worldedit_commands') diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 9daa809..424082f 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -1,7 +1,5 @@ minetest.register_privilege("worldedit", "Can use WorldEdit commands") ---wip: fold the hollow stuff into the main functions and add a hollow flag at the end, then add the compatibility stuff - worldedit.set_pos = {} worldedit.inspect = {} @@ -340,10 +338,11 @@ minetest.register_chatcommand("/replace", { description = "Replace all instances of with in the current WorldEdit region", privs = {worldedit=true}, func = safe_region(function(name, param) - local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$") - local newsearchnode = worldedit.normalize_nodename(searchnode) - local newreplacenode = worldedit.normalize_nodename(replacenode) - local count = worldedit.replace(worldedit.pos1[name], worldedit.pos2[name], newsearchnode, newreplacenode) + local found, _, search_node, replace_node = param:find("^([^%s]+)%s+(.+)$") + local norm_search_node = worldedit.normalize_nodename(search_node) + local norm_replace_node = worldedit.normalize_nodename(replace_node) + local count = worldedit.replace(worldedit.pos1[name], worldedit.pos2[name], + norm_search_node, norm_replace_node) worldedit.player_notify(name, count .. " nodes replaced") end, check_replace), }) @@ -353,10 +352,11 @@ minetest.register_chatcommand("/replaceinverse", { description = "Replace all nodes other than with in the current WorldEdit region", privs = {worldedit=true}, func = safe_region(function(name, param) - local found, _, searchnode, replacenode = param:find("^([^%s]+)%s+(.+)$") - local newsearchnode = worldedit.normalize_nodename(searchnode) - local newreplacenode = worldedit.normalize_nodename(replacenode) - local count = worldedit.replaceinverse(worldedit.pos1[name], worldedit.pos2[name], searchnode, replacenode) + local found, _, search_node, replace_node = param:find("^([^%s]+)%s+(.+)$") + local norm_search_node = worldedit.normalize_nodename(search_node) + local norm_replace_node = worldedit.normalize_nodename(replace_node) + local count = worldedit.replace(worldedit.pos1[name], worldedit.pos2[name], + norm_search_node, norm_replace_node, true) worldedit.player_notify(name, count .. " nodes replaced") end, check_replace), }) @@ -383,7 +383,7 @@ minetest.register_chatcommand("/hollowsphere", { func = safe_region(function(name, param) local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") local node = get_node(name, nodename) - local count = worldedit.hollow_sphere(worldedit.pos1[name], tonumber(radius), node) + local count = worldedit.sphere(worldedit.pos1[name], tonumber(radius), node, true) worldedit.player_notify(name, count .. " nodes added") end, check_sphere), }) @@ -422,7 +422,7 @@ minetest.register_chatcommand("/hollowdome", { func = safe_region(function(name, param) local found, _, radius, nodename = param:find("^(%d+)%s+(.+)$") local node = get_node(name, nodename) - local count = worldedit.hollow_dome(worldedit.pos1[name], tonumber(radius), node) + local count = worldedit.dome(worldedit.pos1[name], tonumber(radius), node, true) worldedit.player_notify(name, count .. " nodes added") end, check_dome), }) @@ -466,7 +466,7 @@ minetest.register_chatcommand("/hollowcylinder", { length = length * sign end local node = get_node(name, nodename) - local count = worldedit.hollow_cylinder(worldedit.pos1[name], axis, length, tonumber(radius), node) + local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius), node, true) worldedit.player_notify(name, count .. " nodes added") end, check_cylinder), }) @@ -1114,7 +1114,7 @@ minetest.register_chatcommand("/clearobjects", { description = "Clears all objects within the WorldEdit region", privs = {worldedit=true}, func = safe_region(function(name, param) - local count = worldedit.clearobjects(worldedit.pos1[name], worldedit.pos2[name]) + local count = worldedit.clear_objects(worldedit.pos1[name], worldedit.pos2[name]) worldedit.player_notify(name, count .. " objects cleared") end), }) diff --git a/worldedit_commands/mark.lua b/worldedit_commands/mark.lua index e07e849..4062cae 100644 --- a/worldedit_commands/mark.lua +++ b/worldedit_commands/mark.lua @@ -19,7 +19,7 @@ worldedit.mark_pos1 = function(name) --add marker worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1") if worldedit.marker1[name] ~= nil then - worldedit.marker1[name]:get_luaentity().name = name + worldedit.marker1[name]:get_luaentity().player_name = name end end worldedit.mark_region(name) @@ -42,7 +42,7 @@ worldedit.mark_pos2 = function(name) --add marker worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2") if worldedit.marker2[name] ~= nil then - worldedit.marker2[name]:get_luaentity().name = name + worldedit.marker2[name]:get_luaentity().player_name = name end end worldedit.mark_region(name) @@ -76,7 +76,7 @@ worldedit.mark_region = function(name) visual_size={x=sizex * 2, y=sizey * 2}, collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness}, }) - marker:get_luaentity().name = name + marker:get_luaentity().player_name = name table.insert(markers, marker) end @@ -88,7 +88,7 @@ worldedit.mark_region = function(name) collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez}, }) marker:setyaw(math.pi / 2) - marker:get_luaentity().name = name + marker:get_luaentity().player_name = name table.insert(markers, marker) end @@ -107,13 +107,13 @@ minetest.register_entity(":worldedit:pos1", { physical = false, }, on_step = function(self, dtime) - if worldedit.marker1[self.name] == nil then + if worldedit.marker1[self.player_name] == nil then self.object:remove() end end, on_punch = function(self, hitter) self.object:remove() - worldedit.marker1[self.name] = nil + worldedit.marker1[self.player_name] = nil end, }) @@ -128,13 +128,13 @@ minetest.register_entity(":worldedit:pos2", { physical = false, }, on_step = function(self, dtime) - if worldedit.marker2[self.name] == nil then + if worldedit.marker2[self.player_name] == nil then self.object:remove() end end, on_punch = function(self, hitter) self.object:remove() - worldedit.marker2[self.name] = nil + worldedit.marker2[self.player_name] = nil end, }) @@ -147,15 +147,16 @@ minetest.register_entity(":worldedit:region_cube", { physical = false, }, on_step = function(self, dtime) - if worldedit.marker_region[self.name] == nil then + if worldedit.marker_region[self.player_name] == nil then self.object:remove() return end end, on_punch = function(self, hitter) - for _, entity in ipairs(worldedit.marker_region[self.name]) do + for _, entity in ipairs(worldedit.marker_region[self.player_name]) do entity:remove() end - worldedit.marker_region[self.name] = nil + worldedit.marker_region[self.player_name] = nil end, -}) \ No newline at end of file +}) + -- cgit v1.2.3