forked from mtcontrib/Minetest-WorldEdit
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`.
This commit is contained in:
@ -1,27 +1,9 @@
|
||||
worldedit = worldedit or {}
|
||||
local minetest = minetest -- local copy of global
|
||||
--- Lua code execution functions.
|
||||
-- @module worldedit.code
|
||||
|
||||
-- Copies and modifies positions `pos1` and `pos2` so that each component of
|
||||
-- `pos1` is less than or equal to the corresponding component of `pos2`.
|
||||
-- Returns the new positions.
|
||||
worldedit.sort_pos = function(pos1, pos2)
|
||||
pos1 = {x=pos1.x, y=pos1.y, z=pos1.z}
|
||||
pos2 = {x=pos2.x, y=pos2.y, z=pos2.z}
|
||||
if pos1.x > pos2.x then
|
||||
pos2.x, pos1.x = pos1.x, pos2.x
|
||||
end
|
||||
if pos1.y > pos2.y then
|
||||
pos2.y, pos1.y = pos1.y, pos2.y
|
||||
end
|
||||
if pos1.z > pos2.z then
|
||||
pos2.z, pos1.z = pos1.z, pos2.z
|
||||
end
|
||||
return pos1, pos2
|
||||
end
|
||||
|
||||
-- Executes `code` as a Lua chunk in the global namespace,
|
||||
-- returning an error if the code fails, or nil otherwise.
|
||||
worldedit.lua = function(code)
|
||||
--- Executes `code` as a Lua chunk in the global namespace.
|
||||
-- @return An error message if the code fails, or nil on success.
|
||||
function worldedit.lua(code)
|
||||
local func, err = loadstring(code)
|
||||
if not func then -- Syntax error
|
||||
return err
|
||||
@ -33,10 +15,12 @@ worldedit.lua = function(code)
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Executes `code` as a Lua chunk in the global namespace with the variable
|
||||
|
||||
--- Executes `code` as a Lua chunk in the global namespace with the variable
|
||||
-- pos available, for each node in a region defined by positions `pos1` and
|
||||
-- `pos2`, returning an error if the code fails, or nil otherwise
|
||||
worldedit.luatransform = function(pos1, pos2, code)
|
||||
-- `pos2`.
|
||||
-- @return An error message if the code fails, or nil on success.
|
||||
function worldedit.luatransform(pos1, pos2, code)
|
||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||
|
||||
local factory, err = loadstring("return function(pos) " .. code .. " end")
|
||||
@ -45,9 +29,7 @@ worldedit.luatransform = function(pos1, pos2, code)
|
||||
end
|
||||
local func = factory()
|
||||
|
||||
-- Keep area loaded
|
||||
local manip = minetest.get_voxel_manip()
|
||||
manip:read_from_map(pos1, pos2)
|
||||
worldedit.keep_loaded(pos1, pos2)
|
||||
|
||||
local pos = {x=pos1.x, y=0, z=0}
|
||||
while pos.x <= pos2.x do
|
||||
|
Reference in New Issue
Block a user