Fixed CLRF Issues (I hope)

This commit is contained in:
VorTechnix 2024-10-07 16:11:35 -07:00
parent 29bac504b0
commit 269a73be48
No known key found for this signature in database
GPG key ID: 091E91A69545D5BA
11 changed files with 551 additions and 549 deletions

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

View file

@ -1,78 +1,78 @@
local Vector3 = require("worldeditadditions_core.utils.vector3") local Vector3 = require("worldeditadditions_core.utils.vector3")
local facing_dirs = dofile("./.tests/parse/axes/include_facing_dirs.lua") local facing_dirs = dofile("./.tests/parse/axes/include_facing_dirs.lua")
local parse = require("worldeditadditions_core.utils.parse.axes_parser") local parse = require("worldeditadditions_core.utils.parse.axes_parser")
local parse_keyword = parse.keyword local parse_keyword = parse.keyword
describe("parse_keyword", function() describe("parse_keyword", function()
-- Basic tests -- Basic tests
it("should work on single axes", function() it("should work on single axes", function()
local ktype, axis, sign = parse_keyword("x") local ktype, axis, sign = parse_keyword("x")
assert.are.equals("axis", ktype) assert.are.equals("axis", ktype)
assert.are.same({"x"}, axis) assert.are.same({"x"}, axis)
assert.are.equals(1, sign) assert.are.equals(1, sign)
end) end)
it("should work with axis clumping", function() it("should work with axis clumping", function()
local ktype, axis, sign = parse_keyword("zx") local ktype, axis, sign = parse_keyword("zx")
assert.are.equals("axis", ktype) assert.are.equals("axis", ktype)
assert.are.same({"x", "z"}, axis) assert.are.same({"x", "z"}, axis)
assert.are.equals(1, sign) assert.are.equals(1, sign)
end) end)
it("should work with h and v", function() it("should work with h and v", function()
local ktype, axis, sign = parse_keyword("hv") local ktype, axis, sign = parse_keyword("hv")
assert.are.equals("axis", ktype) assert.are.equals("axis", ktype)
assert.are.same( assert.are.same(
{"x", "y", "z", rev={"x", "y", "z"}}, {"x", "y", "z", rev={"x", "y", "z"}},
axis) axis)
assert.are.equals(1, sign) assert.are.equals(1, sign)
end) end)
it("should work with h and v in clumping", function() it("should work with h and v in clumping", function()
local ktype, axis, sign = parse_keyword("hyxz") local ktype, axis, sign = parse_keyword("hyxz")
assert.are.equals("axis", ktype) assert.are.equals("axis", ktype)
assert.are.same( assert.are.same(
{"x", "y", "z", rev={"x", "z"}}, {"x", "y", "z", rev={"x", "z"}},
axis) axis)
assert.are.equals(1, sign) assert.are.equals(1, sign)
end) end)
it("should work with negatives", function() it("should work with negatives", function()
local ktype, axis, sign = parse_keyword("-xv") local ktype, axis, sign = parse_keyword("-xv")
assert.are.equals("axis", ktype) assert.are.equals("axis", ktype)
assert.are.same({"x", "y", rev={"y"}}, axis) assert.are.same({"x", "y", rev={"y"}}, axis)
assert.are.equals(-1, sign) assert.are.equals(-1, sign)
end) end)
it("should work with dirs", function() it("should work with dirs", function()
local ktype, axis, sign = parse_keyword("left") local ktype, axis, sign = parse_keyword("left")
assert.are.equals("dir", ktype) assert.are.equals("dir", ktype)
assert.are.equals("left", axis) assert.are.equals("left", axis)
assert.are.equals(1, sign) assert.are.equals(1, sign)
end) end)
it("should work with negative dirs", function() it("should work with negative dirs", function()
local ktype, axis, sign = parse_keyword("-right") local ktype, axis, sign = parse_keyword("-right")
assert.are.equals("dir", ktype) assert.are.equals("dir", ktype)
assert.are.equals("right", axis) assert.are.equals("right", axis)
assert.are.equals(-1, sign) assert.are.equals(-1, sign)
end) end)
it("should work with mirroring", function() it("should work with mirroring", function()
local ktype, axis, sign = parse_keyword("m") local ktype, axis, sign = parse_keyword("m")
assert.are.equals("rev", ktype) assert.are.equals("rev", ktype)
assert.are.equals("mirroring", axis) assert.are.equals("mirroring", axis)
assert.are.equals(nil, sign) assert.are.equals(nil, sign)
end) end)
-- Error tests -- Error tests
it("should return error for bad axis", function() it("should return error for bad axis", function()
local ktype, axis, sign = parse_keyword("-axv") local ktype, axis, sign = parse_keyword("-axv")
assert.are.equals("err", ktype) assert.are.equals("err", ktype)
end) end)
end) end)

View file

@ -1,46 +1,46 @@
-- ███████ ███████ ██ ███████ ██████ ████████ ██████ ██████ ███████ -- ███████ ███████ ██ ███████ ██████ ████████ ██████ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ █████ ██ █████ ██ ██ ██ ██ ██████ ███████ -- ███████ █████ ██ █████ ██ ██ ██ ██ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ███████ ███████ ██████ ██ ██████ ██ ██ ███████ -- ███████ ███████ ███████ ███████ ██████ ██ ██████ ██ ██ ███████
-- Chat commands that operate on selections. -- Chat commands that operate on selections.
local wea_cmdpath = worldeditadditions_commands.modpath .. "/commands/selectors/" local wea_cmdpath = worldeditadditions_commands.modpath .. "/commands/selectors/"
local weac = worldeditadditions_core local weac = worldeditadditions_core
dofile(wea_cmdpath.."scentre.lua") dofile(wea_cmdpath.."scentre.lua")
dofile(wea_cmdpath.."scloud.lua") dofile(wea_cmdpath.."scloud.lua")
dofile(wea_cmdpath.."sgrow.lua") dofile(wea_cmdpath.."sgrow.lua")
dofile(wea_cmdpath.."smake.lua") dofile(wea_cmdpath.."smake.lua")
dofile(wea_cmdpath.."spop.lua") dofile(wea_cmdpath.."spop.lua")
dofile(wea_cmdpath.."spush.lua") dofile(wea_cmdpath.."spush.lua")
dofile(wea_cmdpath.."srel.lua") dofile(wea_cmdpath.."srel.lua")
dofile(wea_cmdpath.."sshift.lua") dofile(wea_cmdpath.."sshift.lua")
dofile(wea_cmdpath.."sshrink.lua") dofile(wea_cmdpath.."sshrink.lua")
dofile(wea_cmdpath.."sstack.lua") dofile(wea_cmdpath.."sstack.lua")
--- DEPRECATED --- --- DEPRECATED ---
dofile(wea_cmdpath.."scol.lua") dofile(wea_cmdpath.."scol.lua")
dofile(wea_cmdpath.."scube.lua") dofile(wea_cmdpath.."scube.lua")
dofile(wea_cmdpath.."srect.lua") dofile(wea_cmdpath.."srect.lua")
dofile(wea_cmdpath.."sfactor.lua") dofile(wea_cmdpath.."sfactor.lua")
--- END DEPRECATED --- --- END DEPRECATED ---
dofile(wea_cmdpath.."unmark.lua") dofile(wea_cmdpath.."unmark.lua")
dofile(wea_cmdpath.."mark.lua") dofile(wea_cmdpath.."mark.lua")
dofile(wea_cmdpath.."pos1-2.lua") dofile(wea_cmdpath.."pos1-2.lua")
dofile(wea_cmdpath.."reset.lua") dofile(wea_cmdpath.."reset.lua")
-- Aliases -- Aliases
weac.register_alias("sfac", "sfactor") weac.register_alias("sfac", "sfactor")
weac.register_alias("expand", "sgrow", true) -- true = override target weac.register_alias("expand", "sgrow", true) -- true = override target
weac.register_alias("outset", "sgrow", true) -- true = override target weac.register_alias("outset", "sgrow", true) -- true = override target
weac.register_alias("contract", "sshrink", true) -- true = override target weac.register_alias("contract", "sshrink", true) -- true = override target
weac.register_alias("inset", "sshrink", true) -- true = override target weac.register_alias("inset", "sshrink", true) -- true = override target
weac.register_alias("shift", "sshift", true) -- true = override target weac.register_alias("shift", "sshift", true) -- true = override target
weac.register_alias("1", "pos1", true) -- true = override target weac.register_alias("1", "pos1", true) -- true = override target
weac.register_alias("2", "pos2", true) -- true = override target weac.register_alias("2", "pos2", true) -- true = override target

View file

@ -1,33 +1,33 @@
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
-- ███████ ██████ ███████ ███ ██ ████████ ███████ ██████ -- ███████ ██████ ███████ ███ ██ ████████ ███████ ██████
-- ██ ██ ██ ████ ██ ██ ██ ██ ██ -- ██ ██ ██ ████ ██ ██ ██ ██ ██
-- ███████ ██ █████ ██ ██ ██ ██ █████ ██████ -- ███████ ██ █████ ██ ██ ██ ██ █████ ██████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██ -- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██
worldeditadditions_core.register_command("scentre", { worldeditadditions_core.register_command("scentre", {
params = "", params = "",
description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.", description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.",
privs = {worldedit=true}, privs = {worldedit=true},
require_pos = 2, require_pos = 2,
parse = function(params_text) parse = function(params_text)
return true return true
end, end,
func = function(name) func = function(name)
local mean = Vector3.mean( local mean = Vector3.mean(
Vector3.clone(wea_c.pos.get(name, 1)), Vector3.clone(wea_c.pos.get(name, 1)),
Vector3.clone(wea_c.pos.get(name, 2)) Vector3.clone(wea_c.pos.get(name, 2))
) )
local pos1, pos2 = Vector3.clone(mean), Vector3.clone(mean) local pos1, pos2 = Vector3.clone(mean), Vector3.clone(mean)
pos1 = pos1:floor() pos1 = pos1:floor()
pos2 = pos2:ceil() pos2 = pos2:ceil()
wea_c.pos.set_all(name, {pos1, pos2}) wea_c.pos.set_all(name, {pos1, pos2})
return true, "Position 1 to "..pos1..", Position 2 to "..pos2 return true, "Position 1 to "..pos1..", Position 2 to "..pos2
end, end,
}) })
-- lua print(vecs.mean.x..", "..vecs.mean.y..", "..vecs.mean.z) -- lua print(vecs.mean.x..", "..vecs.mean.y..", "..vecs.mean.z)

View file

@ -1,22 +1,22 @@
local wea = worldeditadditions local wea = worldeditadditions
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
-- ███████ ███████ █████ ██████ ████████ ██████ ██████ -- ███████ ███████ █████ ██████ ████████ ██████ ██████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ █████ ███████ ██ ██ ██ ██ ██████ -- ███████ █████ ███████ ██ ██ ██ ██ ██████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██ ██ ██ ██████ ██ ██████ ██ ██ -- ███████ ██ ██ ██ ██████ ██ ██████ ██ ██
worldeditadditions_core.register_command("sfactor", { worldeditadditions_core.register_command("sfactor", {
params = "None", params = "None",
description = "DEPRECATED: please use //grow or //shrink instead.", description = "DEPRECATED: please use //grow or //shrink instead.",
privs = { worldedit = true }, privs = { worldedit = true },
parse = function(params_text) parse = function(params_text)
return params_text return params_text
end, end,
func = function(name, paramtext) func = function(name, paramtext)
return false, "DEPRECATED: please use //grow or //shrink instead..." return false, "DEPRECATED: please use //grow or //shrink instead..."
end end
}) })

View file

@ -1,42 +1,42 @@
-- local wea = worldeditadditions -- local wea = worldeditadditions
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
-- ███████ ██████ ██████ ██████ ██ ██ -- ███████ ██████ ██████ ██████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██ ███ ██████ ██ ██ ██ █ ██ -- ███████ ██ ███ ██████ ██ ██ ██ █ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ███ ██
-- ███████ ██████ ██ ██ ██████ ███ ███ -- ███████ ██████ ██ ██ ██████ ███ ███
worldeditadditions_core.register_command("sgrow", { worldeditadditions_core.register_command("sgrow", {
params = "<unified axis syntax>", params = "<unified axis syntax>",
description = "Grow selection region", description = "Grow selection region",
privs = { worldedit = true }, privs = { worldedit = true },
require_pos = 0, require_pos = 0,
parse = function(params_text) parse = function(params_text)
local ret = wea_c.split(params_text) local ret = wea_c.split(params_text)
if #ret < 1 then return false, "SGROW: No params found!" if #ret < 1 then return false, "SGROW: No params found!"
else return true, ret end else return true, ret end
end, end,
func = function(name, params_text) func = function(name, params_text)
local facing = wea_c.player_dir(name) local facing = wea_c.player_dir(name)
local min, max = wea_c.parse.directions(params_text, facing) local min, max = wea_c.parse.directions(params_text, facing)
if not min then return false, max end if not min then return false, max end
local pos1 = wea_c.pos.get(name, 1) local pos1 = wea_c.pos.get(name, 1)
local pos2 = wea_c.pos.get(name, 2) local pos2 = wea_c.pos.get(name, 2)
if not pos2 then wea_c.pos.set(name, 2, pos1) if not pos2 then wea_c.pos.set(name, 2, pos1)
else pos1, pos2 = Vector3.sort(pos1, pos2) end else pos1, pos2 = Vector3.sort(pos1, pos2) end
pos1, pos2 = pos1:add(min), pos2:add(max) pos1, pos2 = pos1:add(min), pos2:add(max)
wea_c.pos.set_all(name, {pos1, pos2}) wea_c.pos.set_all(name, {pos1, pos2})
return true, "Position 1 to "..pos1..", Position 2 to "..pos2 return true, "Position 1 to "..pos1..", Position 2 to "..pos2
end, end,
}) })
-- Tests -- Tests
-- //srel front 5 left 3 y 2 -- //srel front 5 left 3 y 2

View file

@ -1,131 +1,131 @@
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
-- ███████ ███ ███ █████ ██ ██ ███████ -- ███████ ███ ███ █████ ██ ██ ███████
-- ██ ████ ████ ██ ██ ██ ██ ██ -- ██ ████ ████ ██ ██ ██ ██ ██
-- ███████ ██ ████ ██ ███████ █████ █████ -- ███████ ██ ████ ██ ███████ █████ █████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██ ██ ██ ██ ██ ██ ███████ -- ███████ ██ ██ ██ ██ ██ ██ ███████
worldeditadditions_core.register_command("smake", { worldeditadditions_core.register_command("smake", {
params = "<operation:odd|even|equal> <mode:grow|shrink|average> [<target=xyz> [<base>]]", params = "<operation:odd|even|equal> <mode:grow|shrink|average> [<target=xyz> [<base>]]",
description = "Make one or more axes of the current selection odd, even, or equal to another.", description = "Make one or more axes of the current selection odd, even, or equal to another.",
privs = { worldedit = true }, privs = { worldedit = true },
require_pos = 2, require_pos = 2,
parse = function(params_text) parse = function(params_text)
-- Split params_text, check for missing arguments and fill in empty spots -- Split params_text, check for missing arguments and fill in empty spots
local parts = wea_c.split(params_text, "%s+", false) local parts = wea_c.split(params_text, "%s+", false)
if #parts < 2 then if #parts < 2 then
return false, "Error: Not enough arguments. Expected \"<operation> <mode> [<target=xyz> [<base>]]\"." return false, "Error: Not enough arguments. Expected \"<operation> <mode> [<target=xyz> [<base>]]\"."
else else
for i=3,4 do if not parts[i] then parts[i] = false end end for i=3,4 do if not parts[i] then parts[i] = false end end
end end
-- Initialize local variables and sets -- Initialize local variables and sets
local oper, mode, targ, base = wea_c.table.unpack(parts) local oper, mode, targ, base = wea_c.table.unpack(parts)
local operSet, modeSet = wea_c.table.makeset {"equal", "odd", "even"}, wea_c.table.makeset {"grow", "shrink", "avg"} local operSet, modeSet = wea_c.table.makeset {"equal", "odd", "even"}, wea_c.table.makeset {"grow", "shrink", "avg"}
-- Main Logic -- Main Logic
-- Check base if base is present and if so valid. -- Check base if base is present and if so valid.
if base then if base then
if base:match("[xyz]") then -- ensure correct base syntax if base:match("[xyz]") then -- ensure correct base syntax
base = base:match("[xyz]") base = base:match("[xyz]")
else else
return false, "Error: Invalid base \""..base.."\". Expected \"x\", \"y\" or \"z\"." return false, "Error: Invalid base \""..base.."\". Expected \"x\", \"y\" or \"z\"."
end end
end end
-- Resolve target then mode (in that order incase mode is target). -- Resolve target then mode (in that order incase mode is target).
if not targ then -- If no target set to default (xz) if not targ then -- If no target set to default (xz)
targ = "xz" targ = "xz"
elseif targ:match("[xyz]+") then -- ensure correct target syntax elseif targ:match("[xyz]+") then -- ensure correct target syntax
targ = table.concat(wea_c.tochars(targ:match("[xyz]+"),true,true)) targ = table.concat(wea_c.tochars(targ:match("[xyz]+"),true,true))
else else
return false, "Error: Invalid <target> \""..targ.."\". Expected \"x\" and or \"y\" and or \"z\"." return false, "Error: Invalid <target> \""..targ.."\". Expected \"x\" and or \"y\" and or \"z\"."
end end
if mode == "average" then -- If mode is average set to avg if mode == "average" then -- If mode is average set to avg
mode = "avg" mode = "avg"
elseif mode:match("[xyz]+") then -- If target is actually base set vars to correct values. elseif mode:match("[xyz]+") then -- If target is actually base set vars to correct values.
base, targ, mode = targ:sub(1,1), table.concat(wea_c.tochars(mode:match("[xyz]+"),true,true)), false base, targ, mode = targ:sub(1,1), table.concat(wea_c.tochars(mode:match("[xyz]+"),true,true)), false
elseif not modeSet[mode] and not base then -- If mode is invalid and base isn't present throw error elseif not modeSet[mode] and not base then -- If mode is invalid and base isn't present throw error
return false, "Error: Invalid <mode> \""..mode.."\". Expected \"grow\", \"shrink\", or \"average\"/\"avg\"." return false, "Error: Invalid <mode> \""..mode.."\". Expected \"grow\", \"shrink\", or \"average\"/\"avg\"."
end end
if base then if base then
if oper ~= "equal" then base = false -- If operation isn't equalize we don't need <base> if oper ~= "equal" then base = false -- If operation isn't equalize we don't need <base>
elseif targ:match(base) then -- Else check that base is not in target and return error if it is elseif targ:match(base) then -- Else check that base is not in target and return error if it is
return false, "Error: <base> ("..base..") cannot be included in <target> ("..targ..")." return false, "Error: <base> ("..base..") cannot be included in <target> ("..targ..")."
end end
end end
-- Check if operator is valid -- Check if operator is valid
if not operSet[oper] then if not operSet[oper] then
return false, "Error: Invalid operator \""..oper.."\". Expected \"odd\", \"even\" or \"equal\"." return false, "Error: Invalid operator \""..oper.."\". Expected \"odd\", \"even\" or \"equal\"."
end end
return true, oper, mode, targ, base return true, oper, mode, targ, base
end, end,
func = function(name, oper, mode, targ, base) func = function(name, oper, mode, targ, base)
local pos1, pos2 = Vector3.clone(wea_c.pos.get(name, 1)), Vector3.clone(wea_c.pos.get(name, 2)) local pos1, pos2 = Vector3.clone(wea_c.pos.get(name, 1)), Vector3.clone(wea_c.pos.get(name, 2))
local eval -- Declare eval placeholder function to edit later local eval -- Declare eval placeholder function to edit later
local delta = pos2 - pos1 -- local delta equation: Vd(a) = V2(a) - V1(a) 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 _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 targ = wea_c.tocharset(targ) -- Break up targ string into set table
local _m = 0 -- _m is the container to hold the max, min or average (depending on the mode) of the axes in targ local _m = 0 -- _m is the container to hold the max, min or average (depending on the mode) of the axes in targ
-- set _m to the max, min or mean of the target axes depending on mode or base if it exists -- set _m to the max, min or mean of the target axes depending on mode or base if it exists
if base then _m = delta[base] if base then _m = delta[base]
elseif mode == "avg" then elseif mode == "avg" then
for k,v in pairs(targ) do _m = _m + math.abs(delta[k]) end for k,v in pairs(targ) do _m = _m + math.abs(delta[k]) end
_m = _m / _tl _m = _m / _tl
elseif mode == "grow" then elseif mode == "grow" then
for k,v in pairs(targ) do if math.abs(delta[k]) > _m then _m = math.abs(delta[k]) end end for k,v in pairs(targ) do if math.abs(delta[k]) > _m then _m = math.abs(delta[k]) end end
else else
-- Take output of next(targ), put it in a table, wrap the table in brackets to force evlauation so that -- Take output of next(targ), put it in a table, wrap the table in brackets to force evlauation so that
-- we can call the first element of that table to serve as the key for a call to delta. -- we can call the first element of that table to serve as the key for a call to delta.
_m = delta[({next(targ)})[1]] _m = delta[({next(targ)})[1]]
for k,v in pairs(targ) do if math.abs(delta[k]) < _m then _m = math.abs(delta[k]) end end for k,v in pairs(targ) do if math.abs(delta[k]) < _m then _m = math.abs(delta[k]) end end
end end
if oper == "even" then if oper == "even" then
eval = function(int) eval = function(int)
local tmp, abs, neg = int / 2, math.abs(int), int < 0 local tmp, abs, neg = int / 2, math.abs(int), int < 0
if math.floor(tmp) ~= tmp then if math.floor(tmp) ~= tmp then
if mode == "avg" then if mode == "avg" then
if int > _m then int = abs - 1 if int > _m then int = abs - 1
else int = abs + 1 end else int = abs + 1 end
elseif mode == "shrink" and abs > 0 then int = abs - 1 elseif mode == "shrink" and abs > 0 then int = abs - 1
else int = abs + 1 end else int = abs + 1 end
end end
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
elseif oper == "odd" then elseif oper == "odd" then
eval = function(int) eval = function(int)
local tmp, abs, neg = int / 2, math.abs(int), int < 0 local tmp, abs, neg = int / 2, math.abs(int), int < 0
if math.floor(tmp) == tmp then if math.floor(tmp) == tmp then
if mode == "avg" then if mode == "avg" then
if int > _m then int = abs - 1 if int > _m then int = abs - 1
else int = abs + 1 end else int = abs + 1 end
elseif mode == "shrink" and abs > 0 then int = abs - 1 elseif mode == "shrink" and abs > 0 then int = abs - 1
else int = abs + 1 end else int = abs + 1 end
end end
if neg then int = int * -1 end if neg then int = int * -1 end
return int return int
end end
else -- Case: oper == "equal" else -- Case: oper == "equal"
eval = function(int) eval = function(int)
-- Bug: shrink sets pos2 to pos1 -- Bug: shrink sets pos2 to pos1
if int < 0 then return _m * -1 if int < 0 then return _m * -1
else return _m end else return _m end
end end
end end
for k,_ in pairs(targ) do delta[k] = eval(delta[k]) end for k,_ in pairs(targ) do delta[k] = eval(delta[k]) end
wea_c.pos.set(name, 2, pos1 + delta) wea_c.pos.set(name, 2, pos1 + delta)
return true, "Position 2 to "..pos2 return true, "Position 2 to "..pos2
end end
}) })

View file

@ -1,37 +1,37 @@
-- local wea = worldeditadditions -- local wea = worldeditadditions
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
-- ███████ ██████ ███████ ██ -- ███████ ██████ ███████ ██
-- ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██
-- ███████ ██████ █████ ██ -- ███████ ██████ █████ ██
-- ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██
-- ███████ ██ ██ ███████ ███████ -- ███████ ██ ██ ███████ ███████
worldeditadditions_core.register_command("srel", { worldeditadditions_core.register_command("srel", {
params = "<unified axis syntax>", params = "<unified axis syntax>",
description = "Set WorldEdit region position 2 relative to position 1 and player facing.", description = "Set WorldEdit region position 2 relative to position 1 and player facing.",
privs = { worldedit = true }, privs = { worldedit = true },
require_pos = 0, require_pos = 0,
parse = function(params_text) parse = function(params_text)
local ret = wea_c.split(params_text) local ret = wea_c.split(params_text)
if #ret < 1 then return false, "SREL: No params found!" if #ret < 1 then return false, "SREL: No params found!"
else return true, ret end else return true, ret end
end, end,
func = function(name, params_text) func = function(name, params_text)
local facing = wea_c.player_dir(name) local facing = wea_c.player_dir(name)
local vec, err = wea_c.parse.directions(params_text, facing, true) local vec, err = wea_c.parse.directions(params_text, facing, true)
if not vec then return false, err end if not vec then return false, err end
local pos1 = wea_c.pos.get(name, 1) local pos1 = wea_c.pos.get(name, 1)
local pos2 = pos1:add(vec) local pos2 = pos1:add(vec)
wea_c.pos.set_all(name, {pos1, pos2}) wea_c.pos.set_all(name, {pos1, pos2})
return true, "Position 1 to "..pos1..", Position 2 to "..pos2 return true, "Position 1 to "..pos1..", Position 2 to "..pos2
end, end,
}) })
-- Tests -- Tests
-- //srel front 5 left 3 y 2 -- //srel front 5 left 3 y 2

View file

@ -1,42 +1,42 @@
-- local wea = worldeditadditions -- local wea = worldeditadditions
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3 local Vector3 = wea_c.Vector3
-- ███████ ███████ ██ ██ ██████ ██ ███ ██ ██ ██ -- ███████ ███████ ██ ██ ██████ ██ ███ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██
-- ███████ ███████ ███████ ██████ ██ ██ ██ ██ █████ -- ███████ ███████ ███████ ██████ ██ ██ ██ ██ █████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ██ ██ ██ ██ ██ ██ ████ ██ ██ -- ███████ ███████ ██ ██ ██ ██ ██ ██ ████ ██ ██
worldeditadditions_core.register_command("sshrink", { worldeditadditions_core.register_command("sshrink", {
params = "<unified axis syntax>", params = "<unified axis syntax>",
description = "Shrink selection region", description = "Shrink selection region",
privs = { worldedit = true }, privs = { worldedit = true },
require_pos = 0, require_pos = 0,
parse = function(params_text) parse = function(params_text)
local ret = wea_c.split(params_text) local ret = wea_c.split(params_text)
if #ret < 1 then return false, "Error: No params found!" if #ret < 1 then return false, "Error: No params found!"
else return true, ret end else return true, ret end
end, end,
func = function(name, params_text) func = function(name, params_text)
local facing = wea_c.player_dir(name) local facing = wea_c.player_dir(name)
local min, max = wea_c.parse.directions(params_text, facing) local min, max = wea_c.parse.directions(params_text, facing)
if not min then return false, max end if not min then return false, max end
local pos1 = wea_c.pos.get(name, 1) local pos1 = wea_c.pos.get(name, 1)
local pos2 = wea_c.pos.get(name, 2) local pos2 = wea_c.pos.get(name, 2)
if not pos2 then wea_c.pos.set(name, 2, pos1) if not pos2 then wea_c.pos.set(name, 2, pos1)
else pos1, pos2 = Vector3.sort(pos1, pos2) end else pos1, pos2 = Vector3.sort(pos1, pos2) end
pos1, pos2 = pos1:add(max), pos2:add(min) pos1, pos2 = pos1:add(max), pos2:add(min)
wea_c.pos.set_all(name, {pos1, pos2}) wea_c.pos.set_all(name, {pos1, pos2})
return true, "Position 1 to "..pos1..", Position 2 to "..pos2 return true, "Position 1 to "..pos1..", Position 2 to "..pos2
end, end,
}) })
-- Tests -- Tests
-- //srel front 5 left 3 y 2 -- //srel front 5 left 3 y 2

View file

@ -1,29 +1,29 @@
local wea_c = worldeditadditions_core local wea_c = worldeditadditions_core
-- local Vector3 = wea_c.Vector3 -- local Vector3 = wea_c.Vector3
-- ██ ██ █████ ███████ ██████ █████ ██████ ███████ ███████ -- ██ ██ █████ ███████ ██████ █████ ██████ ███████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ███████ ███████ ██████ ███████ ██████ ███████ █████ -- ██ ██ ███████ ███████ ██████ ███████ ██████ ███████ █████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██████ ██ ██ ███████ ██ ██ ██ ██ ██ ███████ ███████ -- ██████ ██ ██ ███████ ██ ██ ██ ██ ██ ███████ ███████
worldeditadditions_core.register_command("uasparse", { worldeditadditions_core.register_command("uasparse", {
params = "<unified axis syntax>", params = "<unified axis syntax>",
description = "Debug command. Returns min and max vectors for given inputs", description = "Debug command. Returns min and max vectors for given inputs",
privs = { worldedit = true }, privs = { worldedit = true },
-- require_pos = 2, -- require_pos = 2,
parse = function(params_text) parse = function(params_text)
local ret = wea_c.split(params_text) local ret = wea_c.split(params_text)
if #ret < 1 then return false, "Error: No params found!" if #ret < 1 then return false, "Error: No params found!"
else return true, ret end else return true, ret end
end, end,
func = function(name, params_text) func = function(name, params_text)
local facing = wea_c.player_dir(name) local facing = wea_c.player_dir(name)
local min, max = wea_c.parse.directions(params_text, facing) local min, max = wea_c.parse.directions(params_text, facing)
if not min then if not min then
return false, max return false, max
else else
return true, "Min: "..min.." Max: "..max return true, "Min: "..min.." Max: "..max
end end
end end
}) })

View file

@ -1,90 +1,90 @@
-- Licence: GPLv2 (MPL-2.0 is compatible, so we can use this here) -- Licence: GPLv2 (MPL-2.0 is compatible, so we can use this here)
-- Source: https://stackoverflow.com/a/43582076/1460422 -- Source: https://stackoverflow.com/a/43582076/1460422
-- gsplit: iterate over substrings in a string separated by a pattern -- gsplit: iterate over substrings in a string separated by a pattern
-- --
-- Parameters: -- Parameters:
-- text (string) - the string to iterate over -- text (string) - the string to iterate over
-- pattern (string) - the separator pattern -- pattern (string) - the separator pattern
-- plain (boolean) - if true (or truthy), pattern is interpreted as a plain -- plain (boolean) - if true (or truthy), pattern is interpreted as a plain
-- string, not a Lua pattern -- string, not a Lua pattern
-- --
-- Returns: iterator -- Returns: iterator
-- --
-- Usage: -- Usage:
-- for substr in gsplit(text, pattern, plain) do -- for substr in gsplit(text, pattern, plain) do
-- doSomething(substr) -- doSomething(substr)
-- end -- end
local function gsplit(text, pattern, plain) local function gsplit(text, pattern, plain)
local splitStart, length = 1, #text local splitStart, length = 1, #text
return function () return function ()
if splitStart then if splitStart then
local sepStart, sepEnd = string.find(text, pattern, splitStart, plain) local sepStart, sepEnd = string.find(text, pattern, splitStart, plain)
local ret local ret
if not sepStart then if not sepStart then
ret = string.sub(text, splitStart) ret = string.sub(text, splitStart)
splitStart = nil splitStart = nil
elseif sepEnd < sepStart then elseif sepEnd < sepStart then
-- Empty separator! -- Empty separator!
ret = string.sub(text, splitStart, sepStart) ret = string.sub(text, splitStart, sepStart)
if sepStart < length then if sepStart < length then
splitStart = sepStart + 1 splitStart = sepStart + 1
else else
splitStart = nil splitStart = nil
end end
else else
ret = sepStart > splitStart and string.sub(text, splitStart, sepStart - 1) or '' ret = sepStart > splitStart and string.sub(text, splitStart, sepStart - 1) or ''
splitStart = sepEnd + 1 splitStart = sepEnd + 1
end end
return ret return ret
end end
end end
end end
--- Split a string into substrings separated by a pattern. -- Deprecated --- Split a string into substrings separated by a pattern. -- Deprecated
-- @param text string The string to iterate over -- @param text string The string to iterate over
-- @param pattern string The separator pattern -- @param pattern string The separator pattern
-- @param plain boolean If true (or truthy), pattern is interpreted as a -- @param plain boolean If true (or truthy), pattern is interpreted as a
-- plain string, not a Lua pattern -- plain string, not a Lua pattern
-- @returns table A sequence table containing the substrings -- @returns table A sequence table containing the substrings
local function dsplit(text, pattern, plain) local function dsplit(text, pattern, plain)
local ret = {} local ret = {}
for match in gsplit(text, pattern, plain) do for match in gsplit(text, pattern, plain) do
table.insert(ret, match) table.insert(ret, match)
end end
return ret return ret
end end
--- Split a string into substrings separated by a pattern. --- Split a string into substrings separated by a pattern.
-- @param str string The string to iterate over -- @param str string The string to iterate over
-- @param dlm="%s+" string The delimiter (separator) pattern. If a falsey value is passed, then the default value is used. -- @param dlm="%s+" string The delimiter (separator) pattern. If a falsey value is passed, then the default value is used.
-- @param plain boolean If true (or truthy), pattern is interpreted as a -- @param plain boolean If true (or truthy), pattern is interpreted as a
-- plain string, not a Lua pattern -- plain string, not a Lua pattern
-- @returns table A sequence table containing the substrings -- @returns table A sequence table containing the substrings
local function split(str,dlm,plain) local function split(str,dlm,plain)
if not dlm then dlm = "%s+" end if not dlm then dlm = "%s+" end
local pos, ret = 0, {} local pos, ret = 0, {}
local ins, i = str:find(dlm,pos,plain) local ins, i = str:find(dlm,pos,plain)
-- "if plain" shaves off some time in the while statement -- "if plain" shaves off some time in the while statement
if plain then if plain then
while ins do while ins do
table.insert(ret,str:sub(pos,ins - 1)) table.insert(ret,str:sub(pos,ins - 1))
pos = ins + #dlm pos = ins + #dlm
ins = str:find(dlm,pos,true) ins = str:find(dlm,pos,true)
end end
else else
while ins do while ins do
table.insert(ret,str:sub(pos,ins - 1)) table.insert(ret,str:sub(pos,ins - 1))
pos = i + 1 pos = i + 1
ins, i = str:find(dlm,pos) ins, i = str:find(dlm,pos)
end end
end end
-- print(pos..","..#str) -- print(pos..","..#str)
if str:sub(pos,#str) ~= "" then if str:sub(pos,#str) ~= "" then
table.insert(ret,str:sub(pos,#str)) table.insert(ret,str:sub(pos,#str))
end end
return ret return ret
end end
return split return split