Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selection tools refactor #112

Merged
merged 36 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4ab8e7c
Deprecate scol, scube & srect
VorTechnix Sep 12, 2024
8247a59
re-aliasing
VorTechnix Sep 12, 2024
005615d
spaces in aliases don't work
VorTechnix Sep 12, 2024
e24997d
Update split.lua
VorTechnix Sep 12, 2024
78c418c
pos_marker quick patch
VorTechnix Sep 12, 2024
4dacd10
sgrow, srel, sshrink UNSTABLE
VorTechnix Sep 12, 2024
4ff01bb
new commands registered
VorTechnix Sep 12, 2024
23aae69
stabilizing fixes
VorTechnix Sep 13, 2024
981bdc2
tested: stable enough
VorTechnix Sep 13, 2024
f51ed36
some optimization
VorTechnix Sep 13, 2024
12747f6
pos_marker_manage: fix crash
sbrl Sep 13, 2024
d1c4f9b
finish deprecation
VorTechnix Sep 13, 2024
38b5571
scentre, sshift stable + housekeeping
VorTechnix Sep 15, 2024
4c4fab1
Update smake.lua
VorTechnix Sep 16, 2024
d43c821
Documentation Update
VorTechnix Sep 17, 2024
a31e34f
sfactor deprecation
VorTechnix Sep 17, 2024
1a18d4c
params modification for UAK
VorTechnix Sep 17, 2024
aaa976c
aliasing
VorTechnix Sep 17, 2024
753ead2
UAK to UAS
VorTechnix Sep 17, 2024
ea25e36
doc updates
VorTechnix Sep 17, 2024
90f2fcb
added UAS Parse
VorTechnix Sep 19, 2024
d635bec
params fix
VorTechnix Sep 19, 2024
d6c452a
hooked up UAS Parse
VorTechnix Sep 19, 2024
61bfab2
axes parser re-refactor tests passed
VorTechnix Sep 19, 2024
41443f0
Doc update
VorTechnix Sep 20, 2024
462332d
Update Chat-Command-Reference.md
VorTechnix Sep 20, 2024
5415e21
Apply suggested title changes
VorTechnix Oct 1, 2024
b884eb0
Apply suggested removals
VorTechnix Oct 1, 2024
a794429
Show default values in param
VorTechnix Oct 1, 2024
f399d47
UASPARSE touchups
VorTechnix Oct 1, 2024
a48576a
Better errors?
VorTechnix Oct 1, 2024
df2af2d
Description Tweak for removed commands
VorTechnix Oct 1, 2024
f4b3b09
Update init.lua Removed TODO
VorTechnix Oct 1, 2024
e811090
Position statements for command returns
VorTechnix Oct 1, 2024
7a0d24f
CRLF to LF
VorTechnix Oct 1, 2024
b319baa
Merge branch 'dev' into selection-tools-refactor
VorTechnix Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ temp/

# VorTechnix stuff
.vdev/
*.old.lua
# Created by https://www.toptal.com/developers/gitignore/api/archives
# Edit at https://www.toptal.com/developers/gitignore?templates=archives

Expand Down
9 changes: 9 additions & 0 deletions .tests/parse/axes/axes_parser.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ describe("parse_axes", function()
assert.are.same(Vector3.new(40, 77, 99), maxv)
end)

it("should infer that directions before a value are connected to that value", function()
local minv, maxv = parse_axes({
"xy", "-x", "5"
}, facing_dirs.z_neg)
assert.is.truthy(minv)
assert.are.same(Vector3.new(-5, 0, 0), minv)
assert.are.same(Vector3.new(5, 5, 0), maxv)
end)

it("should return 2 0,0,0 vectors if no input", function()
local minv, maxv = parse_axes({
-- No input
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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.15: The untitled update (unreleased)
## v1.15: The direction update (unreleased)
- Added the optional argument `all` to [`//unmark`](https://worldeditadditions.mooncarrot.space/Reference/#unmark)
- Added a (rather nuclear) fix (attempt 4) at finally exterminating all zombie region marker walls forever
- This is not a hotfix to avoid endless small releases fixing the bug, as it's clear it's much more difficult to fix on all systems than initially expected
Expand All @@ -16,11 +16,21 @@ Note to self: See the bottom of this file for the release template text.
- Added [`//set+`](https://worldeditadditions.mooncarrot.space/Reference/#set) for setting nodes and param2/light levels quickly.
- NOTE TO SELF: Setting light values doesn't appear to be working very well for some reason
- Added [`//ndef`](https://worldeditadditions.mooncarrot.space/Reference/#ndef) to print a given node's definition table. This is for debugging and development purposes.
- Added `//sgrow` and `//sshrink` commands to enlarge and shrink selection regions and aliased them over WorldEdit equivalents (`//expand`, `//outset` and `//contract`, `//inset` respectively).
- Added Unified Axis Syntax (UAS) parser. - Implementation by @VorTechnix
- See [UAS System reference] for details. (Note to self hook up hyperlink)
- Added `//uasparse` command to show the vectors produced by a given UAS expression. - Implementation by @VorTechnix

### Bugfixes and changes
- Don't warn on failed registration of `//flora` → [`//bonemeal`](https://worldeditadditions.mooncarrot.space/Reference/#bonemeal) if the `bonemeal` mod isn't installed (e.g. in MineClone2) - thanks @VorTechnix in #106
- Improve documentation of [`//noise2d`](https://worldeditadditions.mooncarrot.space/Reference/#noise2d). If it still doesn't make sense, please let me know. It's a complicated command that needs reworking a bit to be easier to use.
- Alias `//napply` to [`//nodeapply`](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply)
- Re-factored selection tools to all use WEA position system and UAS Parser if applicable. - Re-factor by @VorTechnix
- `//sshift` now overrides `//shift` from WorldEdit. - Re-factor by @VorTechnix

### Deprecations
- Deprecated `//scol`, `//srect` and `//scube`. Now that `//srel` is using UAS parser there is no need for them. - Deprecated by @VorTechnix
- Deprecated `//sfactor`. Now that `//sgrow` and `//sshrink` exist it is no longer needed. - Deprecated by @VorTechnix


### Lua API changes
Expand Down
95 changes: 91 additions & 4 deletions Chat-Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,16 @@ This command is intended for debugging and development purposes, but if you're i
//ndef glass
```

### `//uasparse <unified axis syntax>`
Short for *Unified Axis Syntax Parse*. Parses the given UAS expression and prints the resulting vectors to the chat window.

```weacmd
//uasparse front right 5
//uasparse y 12 h -2
//uasparse left 3 up 5 -front 7
//uasparse -z 12 -y -2 x -2
```



## Selection
Expand All @@ -1212,6 +1222,58 @@ This command is intended for debugging and development purposes, but if you're i
███████ ███████ ███████ ███████ ██████ ██ ██ ██████ ██ ████
-->

### Unified Axis Syntax (UAS)
The Unified Axis Syntax system allows users to input direction and distance information in three dimensions using "natural" measurement syntax. The key features include axis clumping, double negatives, relative directions, mirroring and compass directions (more information below).

*Note: negatives can be applied to axes, directions **AND** distances*

#### Relative Directions
|Key Words | Interpretation|
|----------|---------------|
|`f[ront]\|facing\|?` | The direction the player is facing most toward in the world
|`b[ack]\|behind\|rear` | The opposite of the direction the player is facing most toward in the world
|`l[eft]` | The direction to the left of the player
|`r[ight]` | The direction to the right of the player

```weacmd
back 1
f r 4
-facing 13
```

#### Compass Directions
|Key Words | Interpretation|
|----------|---------------|
|`n[orth]` | z
|`s[outh]` | -z
|`e[ast]` | x
|`w[est]` | -x
|`u[p]` | y
|`d[own]` | -y

```weacmd
south 3
north west 5
e d -2
```

#### Axis Clumping
Supported axes are `x`, `y`, `z`, `h`, `v`. All horizontal axes are covered by `h` and both vertical ones are covered by `v`.

- `h 5` == `xz -xz 5` == `x 5 z 5 x -5 z -5`
- `v 5` == `up down 5` == `y -y 5`
- `vxz 5` == `xyz -y 5` == `xyz 5 y -5`

#### Inference and Omnidirectionality
The UAS parser takes command input that is split by whitespace and interprets it as a series of numbers preceded by directional cues. If a number is preceded by another number or nothing it assumes that the number is to be applied on all axes in both positive and negative directions.

- `10` == `hv 10` == `xyz -xyz 10`
- `x 3 6` == `x 3 hv 6`

From the above examples you can also see the principle of inference. All direction modifiers before a value are interpreted as belonging to that value. So `x v 5` is equivalent to `x 5 v 5` and `xv 5`.

Because UAS parses "natural" measurement syntax, there are many ways to express the same direction and distance. This caters to users with different ways of thinking and different play styles which will hopefully make the tools easier to use.

### `//unmark`
> First overridden in v1.14

Expand Down Expand Up @@ -1310,7 +1372,6 @@ Short for _select column_. Sets the pos2 at a set distance along 1 axis from pos
//scol x 3
```


### `//srect [<axis1> [<axis2>]] <length>`
> Added in v1.12; deprecated in favour of [`//srel`](#srel) in v1.15

Expand Down Expand Up @@ -1365,17 +1426,43 @@ Short for _select center_. Sets pos1 and pos2 to the centre point(s) of the curr
//scentre
```

### `//srel <axis1> <length1> [<axis2> <length2> [<axis3> <length3>]]`
### `//srel <unified axis syntax>`
Short for _select relative_. Sets the pos2 at set distances along 3 axes relative to pos1. If pos1 is not set it will default to the node directly under the player. The axis arguments accept `x, y, z` as well as `up, down, left, right, front, back`. Left, right, front and back are relative to player facing direction. Negative (`-`) can be applied to the axis, the length or both. Implementation thanks to @VorTechnix.

```weacmd
//srel front 5
//srel y 12 right -2
//srel y 12 right -2
//srel left 3 up 5 -front 7
//srel -z 12 -y -2 x -2
```

### `//sshift <axis1> <length1> [<axis2> <length2> [<axis3> <length3>]]`
### `//sgrow <unified axis syntax>`
> Added in v1.15

Short for _selection grow_. Grows the current selection along specified axes/directions.
Aliases: `//extend`, `//outset`.

```weacmd
//sgrow back 4
//sgrow left -2 v r 2
//sgrow h 4
//sgrow -zy -2 x -2
```

### `//sshrink <unified axis syntax>`
> Added in v1.15

Short for _selection shrink_. Shrinks the current selection along specified axes/directions.
Aliases: `//contract`, `//inset`.

```weacmd
//sshrink left 4
//sshrink right -2 up 2
//sshrink v 4
//sshrink -hy 2 x -3 true
```

### `//sshift <unified axis syntax>`
> Added in v1.13

Short for _selection shift_. Shifts the WorldEdit region along 3 axes. The axis arguments accept `x, y, z` as well as `up, down, left, right, front, back`. Left, right, front and back are relative to player facing direction. Negative (`-`) can be applied to the axis, the length or both. Implementation thanks to @VorTechnix.
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,23 @@ The detailed explanations have moved! Check them out [here](https://worldeditadd
- [`//basename <name>`](https://worldeditadditions.mooncarrot.space/Reference/#basename)
- [`//ngroups <node_name> [v[erbose]]`](https://worldeditadditions.mooncarrot.space/Reference/#ngroups) _(new in v1.15)_
- [`//ndef <node_name>`](https://worldeditadditions.mooncarrot.space/Reference/#ndef) _(new in v1.15)_
- [`//uasparse <unified axis syntax>`](https://worldeditadditions.mooncarrot.space/Reference/#uasparse) _(new in v1.15)_

### Selection
- [`//scol [<axis1> ] <length>`](https://worldeditadditions.mooncarrot.space/Reference/#scol)
- [`//srect [<axis1> [<axis2>]] <length>`](https://worldeditadditions.mooncarrot.space/Reference/#srect)
- [`//scube [<axis1> [<axis2> [<axis3>]]] <length>`](https://worldeditadditions.mooncarrot.space/Reference/#scube)
- [~~`//scol [<axis1> ] <length>`~~](https://worldeditadditions.mooncarrot.space/Reference/#scol) (REMOVED in v1.15)
- [~~`//srect [<axis1> [<axis2>]] <length>`~~](https://worldeditadditions.mooncarrot.space/Reference/#srect) (REMOVED in v1.15)
- [~~`//scube [<axis1> [<axis2> [<axis3>]]] <length>`~~](https://worldeditadditions.mooncarrot.space/Reference/#scube) (REMOVED in v1.15)
- [`//scloud <0-6|stop|reset>`](https://worldeditadditions.mooncarrot.space/Reference/#scloud)
- [`//scentre`](https://worldeditadditions.mooncarrot.space/Reference/#scentre)
- [`//srel <axis1> <length1> [<axis2> <length2> [<axis3> <length3>]]`](https://worldeditadditions.mooncarrot.space/Reference/#srel)
- [`//sgrow <unified axis syntax>`](https://worldeditadditions.mooncarrot.space/Reference/#sgrow) _(new in v1.15)_
- [`//srel <unified axis syntax>`](https://worldeditadditions.mooncarrot.space/Reference/#srel)
- [`//smake <operation:odd|even|equal> <mode:grow|shrink|average> [<target=xz> [<base>]]`](https://worldeditadditions.mooncarrot.space/Reference/#smake)
- [`//sshrink <unified axis syntax>`](https://worldeditadditions.mooncarrot.space/Reference/#sshrink) _(new in v1.15)_
- [`//sstack`](https://worldeditadditions.mooncarrot.space/Reference/#sstack)
- [`//spush`](https://worldeditadditions.mooncarrot.space/Reference/#spush)
- [`//spop`](https://worldeditadditions.mooncarrot.space/Reference/#spop)
- [`//sshift <axis1> <length1> [<axis2> <length2> [<axis3> <length3>]]`](https://worldeditadditions.mooncarrot.space/Reference/#sshift)
- [`//sfactor <mode:grow|shrink|average> <factor> [<target=xz>]`](https://worldeditadditions.mooncarrot.space/Reference/#sfactor)
- [`//sshift <unified axis syntax>`](https://worldeditadditions.mooncarrot.space/Reference/#sshift)
- [~~`//sfactor <mode:grow|shrink|average> <factor> [<target=xz>]`~~](https://worldeditadditions.mooncarrot.space/Reference/#sfactor) (REMOVED in v1.15)
VorTechnix marked this conversation as resolved.
Show resolved Hide resolved
- [`//pos <index>`](https://worldeditadditions.mooncarrot.space/Reference/#pos)
- [`//pos1`](https://worldeditadditions.mooncarrot.space/Reference/#pos1)
- [`//pos2`](https://worldeditadditions.mooncarrot.space/Reference/#pos2)
Expand Down
80 changes: 46 additions & 34 deletions worldeditadditions_commands/commands/selectors/init.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
-- ███████ ███████ ██ ███████ ██████ ████████ ██████ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ █████ ██ █████ ██ ██ ██ ██ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ███████ ███████ ██████ ██ ██████ ██ ██ ███████

-- Chat commands that operate on selections.

local wea_cmdpath = worldeditadditions_commands.modpath .. "/commands/selectors/"
local weac = worldeditadditions_core

dofile(wea_cmdpath.."srel.lua")
dofile(wea_cmdpath.."scentre.lua")
dofile(wea_cmdpath.."scloud.lua")
dofile(wea_cmdpath.."scol.lua")
dofile(wea_cmdpath.."scube.lua")
dofile(wea_cmdpath.."sfactor.lua")
dofile(wea_cmdpath.."smake.lua")
dofile(wea_cmdpath.."spop.lua")
dofile(wea_cmdpath.."spush.lua")
dofile(wea_cmdpath.."srect.lua")
dofile(wea_cmdpath.."sshift.lua")
dofile(wea_cmdpath.."sstack.lua")

dofile(wea_cmdpath.."unmark.lua")
dofile(wea_cmdpath.."mark.lua")
dofile(wea_cmdpath.."pos1-2.lua")
dofile(wea_cmdpath.."reset.lua")

-- Aliases
weac.register_alias("sfac", "sfactor")

weac.register_alias("1", "pos1", true) -- true = override target
weac.register_alias("2", "pos2", true) -- true = override target
-- ███████ ███████ ██ ███████ ██████ ████████ ██████ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ █████ ██ █████ ██ ██ ██ ██ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ███████ ███████ ███████ ██████ ██ ██████ ██ ██ ███████

-- Chat commands that operate on selections.

local wea_cmdpath = worldeditadditions_commands.modpath .. "/commands/selectors/"
local weac = worldeditadditions_core

dofile(wea_cmdpath.."scentre.lua")
dofile(wea_cmdpath.."scloud.lua")
dofile(wea_cmdpath.."sgrow.lua")
dofile(wea_cmdpath.."smake.lua")
dofile(wea_cmdpath.."spop.lua")
dofile(wea_cmdpath.."spush.lua")
dofile(wea_cmdpath.."srel.lua")
dofile(wea_cmdpath.."sshift.lua")
dofile(wea_cmdpath.."sshrink.lua")
dofile(wea_cmdpath.."sstack.lua")

--- DEPRECATED ---
dofile(wea_cmdpath.."scol.lua")
dofile(wea_cmdpath.."scube.lua")
dofile(wea_cmdpath.."srect.lua")
dofile(wea_cmdpath.."sfactor.lua")
--- END DEPRECATED ---

dofile(wea_cmdpath.."unmark.lua")
dofile(wea_cmdpath.."mark.lua")
dofile(wea_cmdpath.."pos1-2.lua")
dofile(wea_cmdpath.."reset.lua")

-- Aliases
weac.register_alias("sfac", "sfactor")

weac.register_alias("sgrow", "expand", true) -- true = override target
weac.register_alias("sgrow", "outset", true) -- true = override target
weac.register_alias("sshrink", "contract", true) -- true = override target
weac.register_alias("sshrink", "inset", true) -- true = override target

weac.register_alias("sshift", "shift", true) -- true = override target

VorTechnix marked this conversation as resolved.
Show resolved Hide resolved
weac.register_alias("1", "pos1", true) -- true = override target
weac.register_alias("2", "pos2", true) -- true = override target
68 changes: 33 additions & 35 deletions worldeditadditions_commands/commands/selectors/scentre.lua
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3

-- ███████ ██████ ███████ ███ ██ ████████ ███████ ██████
-- ██ ██ ██ ████ ██ ██ ██ ██ ██
-- ███████ ██ █████ ██ ██ ██ ██ █████ ██████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██
worldeditadditions_core.register_command("scentre", {
params = "",
description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.",
privs = {worldedit=true},
require_pos = 2,
parse = function(params_text)
return true
end,
func = function(name)
local mean = Vector3.mean(
Vector3.clone(worldedit.pos1[name]),
Vector3.clone(worldedit.pos2[name])
)
local pos1, pos2 = Vector3.clone(mean), Vector3.clone(mean)

pos1 = pos1:floor()
pos2 = pos2:ceil()

worldedit.pos1[name], worldedit.pos2[name] = pos1, pos2
worldedit.mark_pos1(name)
worldedit.mark_pos2(name)

return true, "position 1 set to "..pos1..", position 2 set to "..pos2
end,
})

-- lua print(vecs.mean.x..", "..vecs.mean.y..", "..vecs.mean.z)
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3

-- ███████ ██████ ███████ ███ ██ ████████ ███████ ██████
-- ██ ██ ██ ████ ██ ██ ██ ██ ██
-- ███████ ██ █████ ██ ██ ██ ██ █████ ██████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██████ ███████ ██ ████ ██ ███████ ██ ██
worldeditadditions_core.register_command("scentre", {
params = "",
description = "Set WorldEdit region positions 1 and 2 to the centre of the current selection.",
privs = {worldedit=true},
require_pos = 2,
parse = function(params_text)
return true
end,
func = function(name)
local mean = Vector3.mean(
Vector3.clone(wea_c.pos.get(name, 1)),
Vector3.clone(wea_c.pos.get(name, 2))
)
VorTechnix marked this conversation as resolved.
Show resolved Hide resolved
local pos1, pos2 = Vector3.clone(mean), Vector3.clone(mean)

pos1 = pos1:floor()
pos2 = pos2:ceil()

wea_c.pos.set_all(name, {pos1, pos2})

VorTechnix marked this conversation as resolved.
Show resolved Hide resolved
return true, "Position 1 to "..pos1..", Position 2 to "..pos2
end,
})

-- lua print(vecs.mean.x..", "..vecs.mean.y..", "..vecs.mean.z)
Loading
Loading