mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 09:03:01 +00:00
parseNumber unstable (0 bug)
This commit is contained in:
parent
f9652c9621
commit
bcaceac28b
1 changed files with 13 additions and 22 deletions
|
@ -66,22 +66,16 @@ local parse = {}
|
||||||
-- @param: str: String: Axis declaration to parse
|
-- @param: str: String: Axis declaration to parse
|
||||||
-- @returns: Table|Bool: axis | axes | false
|
-- @returns: Table|Bool: axis | axes | false
|
||||||
function parse.axis(str)
|
function parse.axis(str)
|
||||||
local ret = {}
|
local ret = { rev={} }
|
||||||
if str:match("[^hvxyz]") then return false end
|
if str:match("[^hvxyz]") then return false end
|
||||||
|
|
||||||
if str:match("v") then
|
for _,v in ipairs({{"x","h"},{"y","v"},{"z","h"}}) do
|
||||||
ret["v"] = true
|
if str:match(v[2]) then table.insert(ret.rev,v[1])
|
||||||
str = "y"..str
|
str = str..v[1] end
|
||||||
|
if str:match(v[1]) then table.insert(ret,v[1]) end
|
||||||
end
|
end
|
||||||
if str:match("h") then
|
|
||||||
ret["h"] = true
|
if #ret.rev < 1 then ret.rev = nil end
|
||||||
str = "xz"..str
|
|
||||||
end
|
|
||||||
|
|
||||||
for _,v in ipairs({"x", "y", "z"}) do
|
|
||||||
if str:match(v) then table.insert(ret,v) end
|
|
||||||
end
|
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -149,18 +143,15 @@ end
|
||||||
-- if error: @returns: false, String: error message
|
-- if error: @returns: false, String: error message
|
||||||
function parse.keytable(tbl, facing, sum)
|
function parse.keytable(tbl, facing, sum)
|
||||||
local min, max = Vector3.new(), Vector3.new()
|
local min, max = Vector3.new(), Vector3.new()
|
||||||
local expected = 1
|
local expected, d = 1, {"x", "y", "z"}
|
||||||
local tmp = {axes = {}, num = 0, sign = 1, mirror = false}
|
local tmp = {axes = {}, num = 0, sign = 1, mirror = false}
|
||||||
|
|
||||||
function tmp:reset()
|
|
||||||
self.axis, self.sign = "", 1
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Processes a number and adds it to the min and max vectors.
|
--- Processes a number and adds it to the min and max vectors.
|
||||||
-- @param num The number to process.
|
-- @param num The number to process.
|
||||||
-- @param axes The axes to apply the number to.
|
-- @param axes The axes to apply the number to.
|
||||||
-- @param sign The sign of the number.
|
-- @param sign The sign of the number.
|
||||||
local function parseNumber(num, axes, sign)
|
local function parseNumber(num, axes, sign)
|
||||||
|
if axes.rev then parseNumber(num, axes.rev, -sign) end
|
||||||
if num * sign >= 0 then
|
if num * sign >= 0 then
|
||||||
max = max:add(parse.vectorize(axes, num, sign))
|
max = max:add(parse.vectorize(axes, num, sign))
|
||||||
else
|
else
|
||||||
|
@ -177,7 +168,7 @@ function parse.keytable(tbl, facing, sum)
|
||||||
|
|
||||||
if expected == 1 then
|
if expected == 1 then
|
||||||
if tmp.num then
|
if tmp.num then
|
||||||
parseNumber(tmp.num, {"x", "y", "z", h = true, v = true}, tmp.sign)
|
parseNumber(tmp.num, {d, rev=d}, tmp.sign)
|
||||||
else
|
else
|
||||||
local key_type, key_entry, key_sign = parse.keyword(v)
|
local key_type, key_entry, key_sign = parse.keyword(v)
|
||||||
|
|
||||||
|
@ -210,10 +201,10 @@ function parse.keytable(tbl, facing, sum)
|
||||||
min = max:multiply(-1)
|
min = max:multiply(-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if sum then
|
if sum then
|
||||||
return min:add(max)
|
return min:add(max)
|
||||||
else
|
else
|
||||||
return min, max
|
return min, max
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue