mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 07:23:00 +00:00
//sfactor: fix luacheck warnings; fix crash
This commit is contained in:
parent
67b4495aad
commit
4c7bb6a980
1 changed files with 8 additions and 8 deletions
|
@ -16,7 +16,7 @@ worldedit.register_command("sfactor", {
|
||||||
return false, "Error: Not enough arguments. Expected \"<mode> <factor> [<target>]\"."
|
return false, "Error: Not enough arguments. Expected \"<mode> <factor> [<target>]\"."
|
||||||
end
|
end
|
||||||
local mode, fac, targ = unpack(parts)
|
local mode, fac, targ = unpack(parts)
|
||||||
local modeSet = wea.makeset {"grow", "shrink", "avg"}
|
local modeSet = wea.table.makeset {"grow", "shrink", "avg"}
|
||||||
|
|
||||||
-- Mode parsing
|
-- Mode parsing
|
||||||
if mode == "average" then -- If mode is average set to avg
|
if mode == "average" then -- If mode is average set to avg
|
||||||
|
@ -60,16 +60,16 @@ worldedit.register_command("sfactor", {
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Equasion: round(delta[<axis>] / factor) * factor
|
-- Equasion: round(delta[<axis>] / factor) * factor
|
||||||
local eval = function(int,fac)
|
local eval = function(int,fac_inner)
|
||||||
local tmp, abs, neg = int / fac, math.abs(int), int < 0
|
local tmp, abs, neg = int / fac_inner, math.abs(int), int < 0
|
||||||
|
|
||||||
if mode == "avg" then
|
if mode == "avg" then
|
||||||
if int > _m then int = math.floor(abs / fac) * fac
|
if int > _m then int = math.floor(abs / fac_inner) * fac_inner
|
||||||
else int = math.ceil(abs / fac) * fac end
|
else int = math.ceil(abs / fac_inner) * fac_inner end
|
||||||
elseif mode == "shrink" then int = math.floor(abs / fac) * fac
|
elseif mode == "shrink" then int = math.floor(abs / fac_inner) * fac_inner
|
||||||
else int = math.ceil(abs / fac) * fac end
|
else int = math.ceil(abs / fac_inner) * fac_inner end
|
||||||
|
|
||||||
if int < fac then int = fac end -- Ensure selection doesn't collapse to 0
|
if int < fac_inner then int = fac_inner end -- Ensure selection doesn't collapse to 0
|
||||||
if neg then int = int * -1 end -- Ensure correct facing direction
|
if neg then int = int * -1 end -- Ensure correct facing direction
|
||||||
return int
|
return int
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue