From e5044368b380b27b8610871974222174edff0436 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 27 Jun 2021 14:38:37 -0700 Subject: [PATCH 1/9] added .vdev folder for myself and gitignored it --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b0e8d5a..f6a72ec 100644 --- a/.gitignore +++ b/.gitignore @@ -235,3 +235,6 @@ tmp/ temp/ # End of https://www.toptal.com/developers/gitignore/api/lua,node + +# VorTechnix stuff +.vdev/ From 0b23f0174b67f26b1e00ae47b63cc618d431b115 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 27 Jun 2021 14:39:36 -0700 Subject: [PATCH 2/9] added separate init.lua for selectors --- .../commands/selectors/init.lua | 22 +++++++++++++++++++ worldeditadditions_commands/init.lua | 14 ++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 worldeditadditions_commands/commands/selectors/init.lua diff --git a/worldeditadditions_commands/commands/selectors/init.lua b/worldeditadditions_commands/commands/selectors/init.lua new file mode 100644 index 0000000..84a05cb --- /dev/null +++ b/worldeditadditions_commands/commands/selectors/init.lua @@ -0,0 +1,22 @@ +-- ███████ ███████ ██ ███████ ██████ ████████ ██████ ██████ ███████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ █████ ██ █████ ██ ██ ██ ██ ██████ ███████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ███████ ███████ ███████ ██████ ██ ██████ ██ ██ ███████ + +-- Chat commands that operate on selections. + +local we_c = worldeditadditions_commands +we_c.modpath = minetest.get_modpath("worldeditadditions_commands") + +dofile(we_c.modpath.."/commands/selectors/srel.lua") +dofile(we_c.modpath.."/commands/selectors/scentre.lua") +dofile(we_c.modpath.."/commands/selectors/scloud.lua") +dofile(we_c.modpath.."/commands/selectors/scol.lua") +dofile(we_c.modpath.."/commands/selectors/scube.lua") +dofile(we_c.modpath.."/commands/selectors/sfactor.lua") +dofile(we_c.modpath.."/commands/selectors/smake.lua") +dofile(we_c.modpath.."/commands/selectors/spop.lua") +dofile(we_c.modpath.."/commands/selectors/spush.lua") +dofile(we_c.modpath.."/commands/selectors/srect.lua") +dofile(we_c.modpath.."/commands/selectors/sstack.lua") diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index a03833d..f435b8c 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -41,16 +41,8 @@ dofile(we_c.modpath.."/commands/meta/many.lua") dofile(we_c.modpath.."/commands/meta/subdivide.lua") dofile(we_c.modpath.."/commands/meta/ellipsoidapply.lua") -dofile(we_c.modpath.."/commands/selectors/srel.lua") -dofile(we_c.modpath.."/commands/selectors/scentre.lua") -dofile(we_c.modpath.."/commands/selectors/scloud.lua") -dofile(we_c.modpath.."/commands/selectors/scol.lua") -dofile(we_c.modpath.."/commands/selectors/scube.lua") -dofile(we_c.modpath.."/commands/selectors/smake.lua") -dofile(we_c.modpath.."/commands/selectors/spop.lua") -dofile(we_c.modpath.."/commands/selectors/spush.lua") -dofile(we_c.modpath.."/commands/selectors/srect.lua") -dofile(we_c.modpath.."/commands/selectors/sstack.lua") +-- Selection Tools +dofile(we_c.modpath.."/commands/selectors/init.lua") dofile(we_c.modpath.."/commands/extra/saplingaliases.lua") dofile(we_c.modpath.."/commands/extra/basename.lua") @@ -85,3 +77,5 @@ worldedit.alias_command("naturalize", "layers") worldedit.alias_command("flora", "bonemeal") worldedit.alias_command("mcount", "count") + +worldedit.alias_command("sfac", "sfactor") From d176cb5419d31d599d21185d71d87cd3b25ade1f Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 27 Jun 2021 14:40:57 -0700 Subject: [PATCH 3/9] revised comments --- worldeditadditions_commands/commands/selectors/smake.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worldeditadditions_commands/commands/selectors/smake.lua b/worldeditadditions_commands/commands/selectors/smake.lua index 6dcab3f..dff331c 100644 --- a/worldeditadditions_commands/commands/selectors/smake.lua +++ b/worldeditadditions_commands/commands/selectors/smake.lua @@ -73,7 +73,7 @@ worldedit.register_command("smake", { local delta = vector.subtract(p2,p1) -- 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.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 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 if base then _m = delta[base] @@ -99,7 +99,7 @@ worldedit.register_command("smake", { elseif mode == "shrink" and abs > 0 then int = abs - 1 else int = abs + 1 end end - if neg then int = int * -1 end + if neg then int = int * -1 end -- Ensure correct facing direction return int end elseif oper == "odd" then From 03093112bb5de6aabbd4d384296a79fbbc136840 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 27 Jun 2021 14:41:16 -0700 Subject: [PATCH 4/9] added sfactor --- .../commands/selectors/sfactor.lua | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 worldeditadditions_commands/commands/selectors/sfactor.lua diff --git a/worldeditadditions_commands/commands/selectors/sfactor.lua b/worldeditadditions_commands/commands/selectors/sfactor.lua new file mode 100644 index 0000000..aecd525 --- /dev/null +++ b/worldeditadditions_commands/commands/selectors/sfactor.lua @@ -0,0 +1,105 @@ +-- ███████ ███████ █████ ██████ ████████ ██████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ █████ ███████ ██ ██ ██ ██ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ██ ██ ██ ██████ ██ ██████ ██ ██ +local wea = worldeditadditions +worldedit.register_command("sfactor", { + params = " []", + description = "Make the length of one or more target axes of the current selection to be multiple(s) of .", + privs = { worldedit = true }, + require_pos = 2, + parse = function(params_text) + local parts = wea.split(params_text, "%s+", false) + + --- Dissable command for current release + if false then + return false, "Feature not yet implemented." + end + + if #parts < 2 then + return false, "Error: Not enough arguments. Expected \" []\"." + end + local mode, fac, targ = unpack(parts) + local modeSet = wea.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.."\". Expected \"grow\", \"shrink\", or \"average\"/\"avg\"." + end + + -- Factor parsing + local factest = tonumber(fac) + if not factest then + return false, "Error: Invalid \""..fac.."\". Expected a number." + elseif factest < 2 then + return false, "Error: 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.tochars(targ:match("[xyz]+"),true,true)) + else + return false, "Error: Invalid \""..targ.."\". Expected \"x\" and or \"y\" and or \"z\"." + end + + if false then -- Argument test + return false, ": " .. tostring(mode) .. ", : " .. type(fac) .. ", : " .. tostring(targ) + end + + return true, mode, fac, targ + end, + func = function(name, mode, fac, targ) + local p1, p2 = vector.new(worldedit.pos1[name]), vector.new(worldedit.pos2[name]) + local delta = vector.subtract(p2,p1) -- 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.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 + + -- Equasion: round(delta[] / factor) * factor + local eval = function(int,fac) + local tmp, abs, neg = int / fac, math.abs(int), int < 0 + + if mode == "avg" then + if int > _m then int = math.floor(abs / fac) * fac + else int = math.ceil(abs / fac) * fac end + elseif mode == "shrink" then int = math.floor(abs / fac) * fac + else int = math.ceil(abs / fac) * fac end + + if int < fac then int = fac end -- Ensure small selections aren't collapsed to 0 + if neg then int = int * -1 end -- Ensure correct facing direction + return int + end + + --- Test: + if false then + local brk = "" + for k,v in pairs(targ) do + brk = brk..k..": "..delta[k]..", " + delta[k] = eval(delta[k],fac) + brk = brk..k..": "..delta[k]..", " + end + return false, brk + end + -- //multi //fp set1 589 2 -82 //fp set2 615 2 -53 + -- //smake even shrink + + for k,v in pairs(targ) do delta[k] = eval(delta[k],fac) end + + worldedit.pos2[name] = vector.add(p1,delta) + worldedit.mark_pos2(name) + return true, "position 2 set to " .. minetest.pos_to_string(p2) + end +}) From df209a9f6166a05b072f1cdaa7dc04c61bebb315 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 27 Jun 2021 15:06:03 -0700 Subject: [PATCH 5/9] removed tests --- .../commands/selectors/sfactor.lua | 20 +------------------ .../commands/selectors/smake.lua | 17 ---------------- 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/worldeditadditions_commands/commands/selectors/sfactor.lua b/worldeditadditions_commands/commands/selectors/sfactor.lua index aecd525..15a10ab 100644 --- a/worldeditadditions_commands/commands/selectors/sfactor.lua +++ b/worldeditadditions_commands/commands/selectors/sfactor.lua @@ -49,10 +49,6 @@ worldedit.register_command("sfactor", { return false, "Error: Invalid \""..targ.."\". Expected \"x\" and or \"y\" and or \"z\"." end - if false then -- Argument test - return false, ": " .. tostring(mode) .. ", : " .. type(fac) .. ", : " .. tostring(targ) - end - return true, mode, fac, targ end, func = function(name, mode, fac, targ) @@ -78,24 +74,10 @@ worldedit.register_command("sfactor", { elseif mode == "shrink" then int = math.floor(abs / fac) * fac else int = math.ceil(abs / fac) * fac end - if int < fac then int = fac end -- Ensure small selections aren't collapsed to 0 - if neg then int = int * -1 end -- Ensure correct facing direction + if neg then int = int * -1 end return int end - --- Test: - if false then - local brk = "" - for k,v in pairs(targ) do - brk = brk..k..": "..delta[k]..", " - delta[k] = eval(delta[k],fac) - brk = brk..k..": "..delta[k]..", " - end - return false, brk - end - -- //multi //fp set1 589 2 -82 //fp set2 615 2 -53 - -- //smake even shrink - for k,v in pairs(targ) do delta[k] = eval(delta[k],fac) end worldedit.pos2[name] = vector.add(p1,delta) diff --git a/worldeditadditions_commands/commands/selectors/smake.lua b/worldeditadditions_commands/commands/selectors/smake.lua index dff331c..d9cb22a 100644 --- a/worldeditadditions_commands/commands/selectors/smake.lua +++ b/worldeditadditions_commands/commands/selectors/smake.lua @@ -61,9 +61,6 @@ worldedit.register_command("smake", { return false, "Error: Invalid operator \""..oper.."\". Expected \"odd\", \"even\" or \"equal\"." end - if false then -- Argument test - return false, ": " .. oper .. ", : " .. tostring(mode) .. ", : " .. tostring(targ) .. ", : " .. tostring(base) - end return true, oper, mode, targ, base end, func = function(name, oper, mode, targ, base) @@ -121,22 +118,8 @@ worldedit.register_command("smake", { if int < 0 then return _m * -1 else return _m end end - -- return false, "Case \"equal\" not handled." end - --- Test: - if false then - local brk = "" - for k,v in pairs(targ) do - brk = brk..k..": "..delta[k]..", " - delta[k] = eval(delta[k]) - brk = brk..k..": "..delta[k]..", " - end - return false, brk - end - -- //multi //fp set1 589 2 -82 //fp set2 615 2 -53 - -- //smake even shrink - for k,v in pairs(targ) do delta[k] = eval(delta[k]) end worldedit.pos2[name] = vector.add(p1,delta) From 79211cf8cbf2ed0609b21d56da5785d105fa5069 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 27 Jun 2021 15:11:00 -0700 Subject: [PATCH 6/9] collapse check --- worldeditadditions_commands/commands/selectors/sfactor.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/worldeditadditions_commands/commands/selectors/sfactor.lua b/worldeditadditions_commands/commands/selectors/sfactor.lua index 15a10ab..cbc32ac 100644 --- a/worldeditadditions_commands/commands/selectors/sfactor.lua +++ b/worldeditadditions_commands/commands/selectors/sfactor.lua @@ -74,7 +74,8 @@ worldedit.register_command("sfactor", { elseif mode == "shrink" then int = math.floor(abs / fac) * fac else int = math.ceil(abs / fac) * fac end - if neg then int = int * -1 end + if int < fac then int = fac end -- Ensure selection doesn't collapse to 0 + if neg then int = int * -1 end -- Ensure correct facing direction return int end From 5d28179babee960cc47e6cba3a87732df3999fe7 Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 27 Jun 2021 15:11:57 -0700 Subject: [PATCH 7/9] remove release block --- worldeditadditions_commands/commands/selectors/sfactor.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/worldeditadditions_commands/commands/selectors/sfactor.lua b/worldeditadditions_commands/commands/selectors/sfactor.lua index cbc32ac..a113f31 100644 --- a/worldeditadditions_commands/commands/selectors/sfactor.lua +++ b/worldeditadditions_commands/commands/selectors/sfactor.lua @@ -12,11 +12,6 @@ worldedit.register_command("sfactor", { parse = function(params_text) local parts = wea.split(params_text, "%s+", false) - --- Dissable command for current release - if false then - return false, "Feature not yet implemented." - end - if #parts < 2 then return false, "Error: Not enough arguments. Expected \" []\"." end From 590a6f3c3a67db15089c5651920a8fb18cfc2cff Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 27 Jun 2021 15:33:24 -0700 Subject: [PATCH 8/9] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4fe01c..caecfe9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ It's about time I started a changelog! This will serve from now on as the main c Note to self: See the bottom of this file for the release template text. +## v1.13: Untitled update (unreleased) + - Add `//sfactor` (_selection factor_) - Selection Tools by @VorTechnix are finished for now. + ## v1.12: The selection tools update (26th June 2021) - Add `//spush`, `//spop`, and `//sstack` - Add `//srect` (_select rectangle_), `//scol` (_select column_), `//scube` (_select cube_) - thanks, @VorTechnix! From 4f895f2da52d24c1e24c3571039fa739aff318ef Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Sun, 27 Jun 2021 16:24:38 -0700 Subject: [PATCH 9/9] Add //sfac to Chat-Command-Reference.md --- Chat-Command-Reference.md | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 9200ec0..a56c35c 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -641,7 +641,7 @@ Value | Description ----------------|-------------- `grow` | Grow each axis specified in `` to the nearest odd/even number to itself `shrink` | Shrink each axis specified in `` to the nearest odd/even number to itself -`average`|`avg` | Take the average of all axes specified in `` and then for each specified axis grow or shrink it, depending on weather it is less than or greater than the average, to the nearest odd/even number to itself +`average`/`avg` | Takes the average of all axes specified in `` and then for each specified axis grows or shrinks it, depending on whether it is less than or greater than the average, to the nearest odd/even number to itself #### *If `` == equal:* The `` argument can be omitted and will not be parsed if present if `` is specified @@ -650,7 +650,8 @@ Value | Description ----------------|--------------- `grow` | Grow each axis specified in `` to the length of the longest specified axis `shrink` | Shrink each axis specified in `` to the length of the shortest specified axis -`average`|`avg` | Set each axis specified in `` to the average length of all the specified axes +`average`/`avg` | Set each axis specified in `` to the average length of all the specified axes +If `` | `` becomes optional. If present it will be ignored. ### Additional arguments: @@ -658,8 +659,25 @@ Name | Description ------------|------------------ `` | Specify axes to perform operation on (default= xz)| ``: If `` == odd or even | Does nothing -``: If `` == equal | Overrides ``^[1] and sets all `` axes equal to itself +``: If `` == equal | Overrides `` and sets all `` axes equal to itself +## `//sfactor []` +Short for _selection make_; alias: `//sfac`. Built specifically for use with `//maze`, this command sets targeted axes equal to the nearest multiple of `` based on the ``. + +Usage examples: + +``` +//sfac grow 5 +//sfac avg 3 xy +``` + +### ``: grow|shrink|average + +Value | Description +--------|-------------- +`grow` | Rounds the length of each target axis up to the nearest multiple of `` +`shrink` | Rounds the length of each target axis down to the nearest multiple of `` +`average`/`avg` | Takes the average of all axes specified in `` and then for each specified axis grows or shrinks it, depending on whether it is less than or greater than the average, to the nearest multiple of `` ## `//sstack` Displays the contents of your per-user selection stack. This stack can be pushed to and popped from rather like a stack of plates. See also `//spush` (for pushing to the selection stack) and `//spop` (for popping from the selection stack). @@ -668,7 +686,6 @@ Displays the contents of your per-user selection stack. This stack can be pushed //sstack ``` - ## `//spush` Pushes the currently defined region onto your per-user selection stack. Does not otherwise alter the defined region.