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/ 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! 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. 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/commands/selectors/sfactor.lua b/worldeditadditions_commands/commands/selectors/sfactor.lua new file mode 100644 index 0000000..a113f31 --- /dev/null +++ b/worldeditadditions_commands/commands/selectors/sfactor.lua @@ -0,0 +1,83 @@ +-- ███████ ███████ █████ ██████ ████████ ██████ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ █████ ███████ ██ ██ ██ ██ ██████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ███████ ██ ██ ██ ██████ ██ ██████ ██ ██ +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) + + 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 + + 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 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] = vector.add(p1,delta) + worldedit.mark_pos2(name) + return true, "position 2 set to " .. minetest.pos_to_string(p2) + end +}) diff --git a/worldeditadditions_commands/commands/selectors/smake.lua b/worldeditadditions_commands/commands/selectors/smake.lua index 9ccddf9..a5d0e2f 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) @@ -73,7 +70,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 +96,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 @@ -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) 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")