mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
Added getsign, fixed srect glitch
This commit is contained in:
parent
b62e4f706d
commit
cb1d54c665
2 changed files with 43 additions and 24 deletions
|
@ -40,3 +40,21 @@ function worldeditadditions.eta(existing_times, done_count, total_count)
|
|||
if times_left == 0 then return 0 end
|
||||
return average * times_left
|
||||
end
|
||||
|
||||
--- Returns the sign (+ or -) at the beginning of a string if present.
|
||||
-- @param str string Input string.
|
||||
-- @param type string The type of value to return. Valid values: "string" (default), "int"
|
||||
-- @return string|int Returns the sign string or signed multiplier (1|-1).
|
||||
function worldeditadditions.getsign(str, type)
|
||||
if not type then type = "string" end
|
||||
if not (type == "string" or type == "int") then
|
||||
return false, "Error: Unknown type '"..type.."'."
|
||||
end
|
||||
if str:sub(1, 1) == "-" then
|
||||
if type == "int" then return -1
|
||||
else return "-" end
|
||||
else
|
||||
if type == "int" then return 1
|
||||
else return "+" end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,20 +3,22 @@
|
|||
-- ███████ ██████ █████ ██ ██
|
||||
-- ██ ██ ██ ██ ██ ██
|
||||
-- ███████ ██ ██ ███████ ██████ ██
|
||||
-- lua parse_params_srect("10")
|
||||
-- local -- TODO: set this to local once development is finished
|
||||
function parse_params_srect(params_text)
|
||||
local find, _, sn1, ax1, sn2, ax2, len = params_text:find("([+-]?)([xyz]?)%s*([+-]?)([xyz]?)%s*(%d*)")
|
||||
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 nil set to player facing dir
|
||||
if ax1 == "" then ax1 = "get"
|
||||
else ax1 = {tonumber(sn1..1),string.lower(ax1)}
|
||||
-- If ax1 is bad set to player facing dir
|
||||
if ax1 == len or not ax1:match('[xyz]') then ax1 = "get"
|
||||
else ax1 = {wea.getsign(ax1, "int"),ax1:gsub('-?',''):sub(1,1)}
|
||||
end
|
||||
-- If ax2 is nil set to +y
|
||||
if ax2 == "" then ax2 = "y" end
|
||||
ax2 = {tonumber(sn2..1),string.lower(ax2)}
|
||||
-- If ax2 is bad set to +y
|
||||
if not ax2 or ax2 == len or not ax2:match('[xyz]') then ax2 = "y" end
|
||||
ax2 = {wea.getsign(ax2, "int"),ax2:gsub('-?',''):sub(1,1)}
|
||||
|
||||
len = tonumber(len)
|
||||
-- If len == nill cancel the operation
|
||||
if len == nil then
|
||||
return false, "No length specified."
|
||||
end
|
||||
|
@ -36,17 +38,16 @@ worldedit.register_command("srect", {
|
|||
if axis1 == "get" then axis1 = worldeditadditions.player_axis2d(name) end
|
||||
|
||||
local pos1 = worldedit.pos1[name]
|
||||
local p2 = {["x"] = pos1.x,["y"] = pos1.y,["z"] = pos1.z}
|
||||
local p2 = vector.new(pos1)
|
||||
|
||||
p2[axis1[2]] = p2[axis1[2]] + tonumber(len) * axis1[1]
|
||||
p2[axis2[2]] = p2[axis2[2]] + tonumber(len) * axis2[1]
|
||||
|
||||
worldedit.pos2[name] = p2
|
||||
worldedit.mark_pos2(name)
|
||||
worldedit.player_notify(name, "position 2 set to " .. minetest.pos_to_string(p2))
|
||||
return true, "position 2 set to " .. minetest.pos_to_string(p2)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Tests
|
||||
-- params_text = "-x z 13"
|
||||
-- params_text = "-x a 13"
|
||||
-- /multi //fp set1 -63 19 -20 //srect 5
|
||||
|
|
Loading…
Reference in a new issue