mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
srel stable?
This commit is contained in:
parent
20a879a7af
commit
00b9a1f517
4 changed files with 90 additions and 1 deletions
|
@ -18,5 +18,21 @@ function worldeditadditions.axis_left(axis,sign)
|
|||
else return true, "x", -sign end
|
||||
end
|
||||
|
||||
--- Dehumanize Direction: translates up, down, left, right, front, into xyz based on player orientation.
|
||||
-- @param name string The name of the player to return facing direction of.
|
||||
-- @param dir string Relative direction to translate.
|
||||
-- @return Returns axis name and sign multiplier.
|
||||
function worldeditadditions.dh_dir(name, dir)
|
||||
local axfac, drfac = worldeditadditions.player_axis2d(name)
|
||||
local _, axlft, drlft = worldeditadditions.axis_left(axfac,drfac)
|
||||
if dir:match("front") or dir:match("back") then
|
||||
return axfac, dir:match("front") and drfac or -drfac
|
||||
elseif dir:match("left") or dir:match("right") then
|
||||
return axlft, dir:match("left") and drlft or -drlft
|
||||
elseif dir:match("up") or dir:match("down") then
|
||||
return "y", dir == "down" and -1 or 1
|
||||
else return false, "\"" .. dir .. "\" not a recognized direction! Try: (up | down | left | right | front | back)" end
|
||||
end
|
||||
|
||||
-- Tests
|
||||
-- /lua print(unpack(worldeditadditions.player_axis2d(myname)))
|
||||
|
|
|
@ -46,3 +46,22 @@ function worldeditadditions.table_get_last(tbl, count)
|
|||
math.max(0, (#tbl) - (count - 1))
|
||||
)}
|
||||
end
|
||||
|
||||
--- Returns the key value pairs in a table as a single string
|
||||
-- @param tbl table input table
|
||||
-- @param sep string key value seperator
|
||||
-- @param new_line string key value pair delimiter
|
||||
-- @return string concatenated table pairs
|
||||
function worldeditadditions.table_tostring(tbl, sep, new_line)
|
||||
if type(sep) ~= "string" then sep = ": " end
|
||||
if type(new_line) ~= "string" then new_line = ", " end
|
||||
local ret = {}
|
||||
if type(tbl) ~= "table" then return "Error: input not table!" end
|
||||
for key,value in pairs(tbl) do
|
||||
ret:append(key)
|
||||
ret:append(sep)
|
||||
ret:append(value)
|
||||
ret:append(new_line)
|
||||
end
|
||||
return ret:concat("")
|
||||
end
|
||||
|
|
54
worldeditadditions_commands/commands/selectors/srel.lua
Normal file
54
worldeditadditions_commands/commands/selectors/srel.lua
Normal file
|
@ -0,0 +1,54 @@
|
|||
-- ███████ ██████ ███████ ██
|
||||
-- ██ ██ ██ ██ ██
|
||||
-- ███████ ██████ █████ ██
|
||||
-- ██ ██ ██ ██ ██
|
||||
-- ███████ ██ ██ ███████ ███████
|
||||
local wea = worldeditadditions
|
||||
local function parse_with_name(name,args)
|
||||
local vec, tmp = vector.new(0, 0, 0), {}
|
||||
local find, _, i = {}, 0, 0
|
||||
repeat
|
||||
_, i, tmp.proc = args:find("([%l%s+-]+%d+)%s*", i)
|
||||
if tmp.proc:match("[xyz]") then
|
||||
tmp.ax = tmp.proc:match("[xyz]")
|
||||
tmp.dir = tonumber(tmp.proc:match("[+-]?%d+")) * (tmp.proc:match("-%l+") and -1 or 1)
|
||||
else
|
||||
tmp.ax, _ = wea.dh_dir(name, tmp.proc:match("%l+"))
|
||||
if not tmp.ax then return false, _ end
|
||||
tmp.dir = tonumber(tmp.proc:match("[+-]?%d+")) * (tmp.proc:match("-%l+") and -1 or 1) * _
|
||||
end
|
||||
vec[tmp.ax] = tmp.dir
|
||||
until not args:find("([%l%s+-]+%d+)%s*", i)
|
||||
return true, vec
|
||||
end
|
||||
worldedit.register_command("srel", {
|
||||
params = "<axis1> <length1> [<axis2> <length2> [<axis3> <length3>]]",
|
||||
description = "Set WorldEdit region position 2 at set distances along 3 axes.",
|
||||
privs = { worldedit = true },
|
||||
require_pos = 0,
|
||||
parse = function(params_text)
|
||||
if params_text:match("([%l%s+-]+%d+)") then return true, params_text
|
||||
else return false, "No acceptable params found" end
|
||||
end,
|
||||
func = function(name, params_text)
|
||||
local ret = ""
|
||||
local _, vec = parse_with_name(name,params_text)
|
||||
if not _ then return false, vec end
|
||||
|
||||
if not worldedit.pos1[name] then
|
||||
local pos = vector.add(minetest.get_player_by_name(name):get_pos(), vector.new(0.5,-0.5,0.5))
|
||||
wea.vector.floor(pos)
|
||||
worldedit.pos1[name] = pos
|
||||
worldedit.mark_pos1(name)
|
||||
ret = "position 1 set to " .. minetest.pos_to_string(pos) .. ", "
|
||||
end
|
||||
|
||||
local p2 = vector.add(vec,worldedit.pos1[name])
|
||||
worldedit.pos2[name] = p2
|
||||
worldedit.mark_pos2(name)
|
||||
return true, ret .. "position 2 set to " .. minetest.pos_to_string(p2)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Tests
|
||||
-- //srel front 5 left 3 y 2
|
|
@ -41,7 +41,7 @@ dofile(we_c.modpath.."/commands/meta/many.lua")
|
|||
dofile(we_c.modpath.."/commands/meta/subdivide.lua")
|
||||
dofile(we_c.modpath.."/commands/meta/ellipsoidapply.lua")
|
||||
|
||||
-- dofile(we_c.modpath.."/commands/selectors/srel.lua")
|
||||
dofile(we_c.modpath.."/commands/selectors/srel.lua")
|
||||
dofile(we_c.modpath.."/commands/selectors/scentre.lua")
|
||||
dofile(we_c.modpath.."/commands/selectors/scloud.lua")
|
||||
dofile(we_c.modpath.."/commands/selectors/scol.lua")
|
||||
|
|
Loading…
Reference in a new issue