sfactor deprecation

This commit is contained in:
VorTechnix 2024-09-17 12:30:21 -07:00
parent d43c8212d2
commit a31e34f420
No known key found for this signature in database
GPG key ID: 091E91A69545D5BA

View file

@ -9,79 +9,14 @@ local Vector3 = wea_c.Vector3
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██ ██ ██ ██████ ██ ██████ ██ ██ -- ███████ ██ ██ ██ ██████ ██ ██████ ██ ██
worldeditadditions_core.register_command("sfactor", { worldeditadditions_core.register_command("sfactor", {
params = "<mode> <factor> [<target=xz>]", params = "None",
description = "Make the length of one or more target axes of the current selection to be multiple(s) of <factor>.", description = "Deprecated.",
privs = { worldedit = true }, privs = { worldedit = true },
require_pos = 2, require_pos = 1,
parse = function(params_text) parse = function(params_text)
local parts = wea_c.split(params_text, "%s+", false) return params_text
if #parts < 2 then
return false, "Error: Not enough arguments. Expected \"<mode> <factor> [<target>]\"."
end
local mode, fac, targ = wea_c.table.unpack(parts)
local modeSet = wea_c.table.makeset {"grow", "shrink", "avg"}
-- Mode parsing
if mode == "average" then -- If mode is average set to avg
mode = "avg"
elseif not modeSet[mode] then -- If mode is invalid throw error
return false, "Error: Invalid <mode> \""..mode.."\". Expected \"grow\", \"shrink\", or \"average\"/\"avg\"."
end
-- Factor parsing
local factest = tonumber(fac)
if not factest then
return false, "Error: Invalid <factor> \""..fac.."\". Expected a number."
elseif factest < 2 then
return false, "Error: <factor> is too low. Expected a number equal to or greater than 2."
else
fac = math.floor(factest+0.5)
end
-- Target parsing
if not targ then -- If no target set to default (xz)
targ = "xz"
elseif targ:match("[xyz]+") then -- ensure correct target syntax
targ = table.concat(wea_c.tochars(targ:match("[xyz]+"),true,true))
else
return false, "Error: Invalid <target> \""..targ.."\". Expected \"x\" and or \"y\" and or \"z\"."
end
return true, mode, fac, targ
end, end,
func = function(name, mode, fac, targ) func = function(name, paramtext)
local pos1, pos2 = Vector3.clone(worldedit.pos1[name]), Vector3.clone(worldedit.pos2[name]) return false, "DEPRECATED: please use //grow or //shrink instead..."
local delta = pos2 - pos1 -- local delta equation: Vd(a) = V2(a) - V1(a)
local _tl = #targ -- Get targ length as a variable incase mode is "average"/"avg"
local targ = wea_c.tocharset(targ) -- Break up targ string into set table
local _m = 0 -- _m is the container to hold the average of the axes in targ
-- set _m to the max, min or mean of the target axes depending on mode (_tl is the length of targ) or base if it exists
if mode == "avg" then
for k,v in pairs(targ) do _m = _m + math.abs(delta[k]) end
_m = _m / _tl
end
-- Equation: round(delta[<axis>] / factor) * factor
local eval = function(int,fac_inner)
local tmp, abs, neg = int / fac_inner, math.abs(int), int < 0
if mode == "avg" then
if int > _m then int = math.floor(abs / fac_inner) * fac_inner
else int = math.ceil(abs / fac_inner) * fac_inner end
elseif mode == "shrink" then int = math.floor(abs / fac_inner) * fac_inner
else int = math.ceil(abs / fac_inner) * fac_inner end
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
return int
end
for k,v in pairs(targ) do delta[k] = eval(delta[k],fac) end
worldedit.pos2[name] = pos1 + delta
worldedit.mark_pos2(name)
return true, "position 2 set to "..pos2
end end
}) })