srect: localify parsing function

This commit is contained in:
Starbeamrainbowlabs 2021-03-01 21:08:32 +00:00
parent 2acc6b3470
commit e1755ce8e1
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -3,42 +3,37 @@
-- ███████ ██████ █████ ██ ██ -- ███████ ██████ █████ ██ ██
-- ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██
-- ███████ ██ ██ ███████ ██████ ██ -- ███████ ██ ██ ███████ ██████ ██
-- local -- TODO: set this to local once development is finished
function parse_params_srect(params_text)
local wea = worldeditadditions
local find = wea.split(params_text, "%s", false)
local ax1, ax2, len = find[1], find[2], find[table.maxn(find)]
-- If ax1 is bad set to player facing dir
if ax1 == len or not ax1:match('[xyz]') then ax1 = "get"
else
local success, value = wea.getsign(ax1, "int")
if not success then return success, value
else ax1 = { value, ax1:gsub('[^xyz]',''):sub(1,1) }
end
end
-- If ax2 is bad set to +y
if not ax2 or ax2 == len or not ax2:match('[xyz]') then ax2 = "y" end
local success, value = wea.getsign(ax2, "int")
if not success then return success, value end
ax2 = { value, ax2:gsub('[^xyz]',''):sub(1,1) }
len = tonumber(len)
-- If len == nill cancel the operation
if len == nil then
return false, "No length specified."
end
return true, ax1, ax2, len
end
worldedit.register_command("srect", { worldedit.register_command("srect", {
params = "[<axis1> [<axis2>]] <length>", params = "[<axis1> [<axis2>]] <length>",
description = "Set WorldEdit region position 2 at a set distance along 2 axes.", description = "Set WorldEdit region position 2 at a set distance along 2 axes.",
privs = {worldedit=true}, privs = {worldedit=true},
require_pos = 1, require_pos = 1,
parse = function(params_text) parse = function(params_text)
local values = {parse_params_srect(params_text)} local wea = worldeditadditions
return unpack(values) local find = wea.split(params_text, "%s", false)
local ax1, ax2, len = find[1], find[2], find[table.maxn(find)]
-- If ax1 is bad set to player facing dir
if ax1 == len or not ax1:match('[xyz]') then ax1 = "get"
else
local success, value = wea.getsign(ax1, "int")
if not success then return success, value
else ax1 = { value, ax1:gsub('[^xyz]',''):sub(1,1) }
end
end
-- If ax2 is bad set to +y
if not ax2 or ax2 == len or not ax2:match('[xyz]') then ax2 = "y" end
local success, value = wea.getsign(ax2, "int")
if not success then return success, value end
ax2 = { value, ax2:gsub('[^xyz]',''):sub(1,1) }
len = tonumber(len)
-- If len == nill cancel the operation
if len == nil then
return false, "No length specified."
end
return true, ax1, ax2, len
end, end,
func = function(name, axis1, axis2, len) func = function(name, axis1, axis2, len)
if axis1 == "get" then axis1 = worldeditadditions.player_axis2d(name) end if axis1 == "get" then axis1 = worldeditadditions.player_axis2d(name) end