Override basic selection commands

//mark
//unmark
//pos1 //1
//pos2 //2
//reset
Also add //pos <index>
This commit is contained in:
Starbeamrainbowlabs 2023-07-10 20:17:28 +01:00
parent 693fc145d5
commit 5c632df658
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
9 changed files with 255 additions and 26 deletions

View File

@ -12,6 +12,7 @@ Note to self: See the bottom of this file for the release template text.
- Implement custom region boxing UI, which replaces the WorldEdit region box when using WorldEditAdditions wands.
- Is backwards compatible with regular WorldEdit wands and tools, as WorldEditAdditions keeps the new positioning system in sync with WorldEdit's.
- The new multipoint wand required this as a prerequisite
- Add [`//pos`](https://worldeditadditions.mooncarrot.space/Reference/#pos), for setting any numbered point (i.e. not just pos1 and pos2, but pos3 and beyond)
- Add [`//spline`](https://worldeditadditions.mooncarrot.space/Reference/#spline), for drawing curved lines with an arbitrary number of points **(uses the new multi-point wand)**
- Add [`//revolve`](https://worldeditadditions.mooncarrot.space/Reference/#revolve), which makes multiple evenly-spaced rotated copies of the defined region **(uses the new multi-point wand)**
- [`//copy+`](https://worldeditadditions.mooncarrot.space/Reference/#copy), [`//move+`](https://worldeditadditions.mooncarrot.space/Reference/#move): Added support for integrated `airapply` mode, which replaces nodes at the target only if they are air - append `airapply`/`aa` to the command to use

View File

@ -868,7 +868,75 @@ Returns the absolute canonical name of a node, given an alias or partial node na
███████ ███████ ███████ ███████ ██████ ██ ██ ██████ ██ ████
-->
### `//unmark`
Hides the in-game UI that indicates where the current positions and region are located.
This hides both the WorldEditAdditions *and* the WorldEdit UI if displayed, but does **not** change or remove any points that are registered.
Should more than 2 points be defined, they are all hidden.
```weacmd
//unmark
```
### `//mark`
Shows the in-game UI that indicates where the current positions and region are located once more.
Should more than 2 points be defined, they are all shown once more.
Often used after calling [`//unmark`](#unmark)
```weacmd
//mark
```
### `//pos1`
Sets pos1 to the location of the calling player.
This is, as with all other WorldEditAdditions commands, seamlessly synchronised with WorldEdit, allowing you to use any combination of WorldEditAdditions and WorldEdit commands and tools without them desynchronising from one another.
**Aliases:** `//1`
```weacmd
//pos2
```
### `//pos2`
Sets pos1 to the location of the calling player.
This is, as with all other WorldEditAdditions commands, seamlessly synchronised with WorldEdit, allowing you to use any combination of WorldEditAdditions and WorldEdit commands and tools without them desynchronising from one another.
**Aliases:** `//2`
```weacmd
//pos2
```
### `//pos <index>`
Sets position with the given index `<index>` to the location of the calling player.
Should the index be less than or equal to 2, then as with all other WorldEditAdditions commands, seamlessly synchronised with WorldEdit, allowing you to use any combination of WorldEditAdditions and WorldEdit commands and tools without them desynchronising from one another.
Should the index be greater than 2, the position will only be registered in WorldEditAdditions, as WorldEdit does not support defining more than 2 points.
If no index is specified, an error is returned and nothing is done.
```weacmd
//pos 1
//pos 3
//pos 45
//pos 2
```
### `//reset`
Clears all positions defined and the defined region.
This also synchronises with WorldEdit, as all other WorldEditAdditions commands do.
```weacmd
//reset
```
### `//scol [<axis1> ] <length>`

View File

@ -6,21 +6,29 @@
-- Chat commands that operate on selections.
local we_cmdpath = worldeditadditions_commands.modpath .. "/commands/selectors/"
local wea_cmdpath = worldeditadditions_commands.modpath .. "/commands/selectors/"
local weac = worldeditadditions_core
dofile(we_cmdpath.."srel.lua")
dofile(we_cmdpath.."scentre.lua")
dofile(we_cmdpath.."scloud.lua")
dofile(we_cmdpath.."scol.lua")
dofile(we_cmdpath.."scube.lua")
dofile(we_cmdpath.."sfactor.lua")
dofile(we_cmdpath.."smake.lua")
dofile(we_cmdpath.."spop.lua")
dofile(we_cmdpath.."spush.lua")
dofile(we_cmdpath.."srect.lua")
dofile(we_cmdpath.."sshift.lua")
dofile(we_cmdpath.."sstack.lua")
dofile(we_cmdpath.."unmark.lua")
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
worldedit.alias_command("sfac", "sfactor")
weac.register_alias("sfac", "sfactor")
weac.register_alias("1", "pos1", true) -- true = override target
weac.register_alias("2", "pos2", true) -- true = override target

View File

@ -0,0 +1,23 @@
local weac = worldeditadditions_core
local function do_mark(name, params_text)
-- TODO: Decide whether we need to hided the worldeditadditions marker here or not.
-- Show the WorldEditAdditions marker
weac.pos.mark(name)
end
if minetest.registered_chatcommands["/mark"] then
minetest.override_chatcommand("/mark", {
params = "",
description = "Show the markers for the defined region (and any other positions) once more.",
func = do_mark
})
else
minetest.register_chatcommand("/mark", {
params = "",
description = "Show the markers for the defined region (and any other positions) once more.",
privs = { worldedit = true },
func = do_mark
})
end

View File

@ -0,0 +1,63 @@
local weac = worldeditadditions_core
local Vector3 = weac.Vector3
local function do_set(name, i)
local player = minetest.get_player_by_name(name)
weac.pos.set(name, i, Vector3.clone(player:get_pos()))
end
local function do_set1(name, params_text)
do_set(name, 1)
end
local function do_set2(name, params_text)
do_set(name, 2)
end
if minetest.registered_chatcommands["/pos1"] then
minetest.override_chatcommand("/pos1", {
params = "",
description =
"Sets pos1 to the current position of the calling player.",
func = do_set1
})
else
minetest.register_chatcommand("/pos1", {
params = "",
description =
"Sets pos1 to the current position of the calling player.",
privs = { worldedit = true },
func = do_set1
})
end
if minetest.registered_chatcommands["/pos2"] then
minetest.override_chatcommand("/pos2", {
params = "",
description = "Sets pos2 to the current position of the calling player.",
func = do_set2
})
else
minetest.register_chatcommand("/pos2", {
params = "",
description = "Sets pos2 to the current position of the calling player.",
privs = { worldedit = true },
func = do_set2
})
end
minetest.register_chatcommand("//pos", {
params = "<index>",
description = "Sets position <index> to the current position of the calling player.",
privs = { worldedit = true },
func = function(name, params_text)
local i = tonumber(params_text)
if type(i) ~= "number" then
worldedit.player_notify(name, "Error: Invalid index number given.")
return
end
i = math.floor(i)
do_set(name, i)
end
})

View File

@ -0,0 +1,32 @@
local weac = worldeditadditions_core
local worldedit_reset
if minetest.registered_chatcommands["/reset"] then
worldedit_reset = minetest.registered_chatcommands["/reset"].func
end
local function do_reset(name, params_text)
-- Hide the WorldEdit marker, if appropriate
if type(worldedit_reset) == "function" then
worldedit_reset(name, params_text)
end
-- Hide the WorldEditAdditions marker
weac.pos.clear(name)
end
if minetest.registered_chatcommands["/reset"] then
minetest.override_chatcommand("/reset", {
params = "",
description = "Clears all defined points and the currently defined region.",
func = do_reset
})
else
minetest.register_chatcommand("/reset", {
params = "",
description = "Clears all defined points and the currently defined region.",
privs = { worldedit = true },
func = do_reset
})
end

View File

@ -31,6 +31,14 @@ local anchor = nil
-- @event clear
-- @format { player_name: string }
--- It is requested that all position/region marker UI elements be hidden for the given player.
-- @event unmark
-- @format { player_name: string }
--- It is requested that all position/region marker UI elements be shown once more for the given player.
-- @event mark
-- @format { player_name: string }
--- Ensures that a table exists for the given player.
-- @param player_name string The name of the player to check.
local function ensure_player(player_name)
@ -266,6 +274,14 @@ local function unmark(player_name)
})
end
--- Shows the visual markers for the given player's positions and defined region once more.
-- Often used some time after calling worldeditadditions_core.pos.unmark().
-- @param player_name string The name of the player to operate on.
local function mark(player_name)
anchor:emit("mark", {
player_name = player_name
})
end
anchor = wea_c.EventEmitter.new({
get = get,
@ -282,6 +298,7 @@ anchor = wea_c.EventEmitter.new({
set2 = set2,
set_all = set_all,
unmark = unmark,
mark = mark,
compat_worldedit_get = compat_worldedit_get,
})
anchor.debug = false

View File

@ -43,6 +43,15 @@ local function do_create(event)
position_entities[event.player_name][event.i] = new_entity
end
local function do_delete_all(player_name)
if #position_entities[player_name] > 0 then
for _, entity in pairs(position_entities[player_name]) do
wea_c.entities.pos_marker.delete(entity)
end
end
position_entities[player_name] = nil
end
wea_c.pos:addEventListener("push", function(event)
do_create(event)
end)
@ -72,26 +81,32 @@ end)
wea_c.pos:addEventListener("clear", function(event)
ensure_player(event.player_name)
if #position_entities[event.player_name] > 0 then
for _, entity in pairs(position_entities[event.player_name]) do
wea_c.entities.pos_marker.delete(entity)
end
end
do_delete_all(event.player_name)
-- For compatibility, ensure that we also clear the legacy worldedit region too
if worldedit and worldedit.marker_update then
worldedit.marker_update(event.player_name)
end
position_entities[event.player_name] = nil
end)
wea_c.pos:addEventListener("unmark", function(event)
ensure_player(event.player_name)
if #position_entities[event.player_name] > 0 then
for _, entity in pairs(position_entities[event.player_name]) do
wea_c.entities.pos_marker.delete(entity)
end
end
do_delete_all(event.player_name)
-- Note that this function is NOT WorldEdit compatible, because it is only called through our override of WorldEdit's `//unmark`, and WorldEdit doesn't have an API function to call to unmark and everything is complicated.
end)
wea_c.pos:addEventListener("mark", function(event)
ensure_player(event.player_name)
do_delete_all(event.player_name)
for i, pos in pairs(wea_c.pos.get_all(event.player_name)) do
do_create({
player_name = event.player_name,
i = i,
pos = pos
})
end
end)

View File

@ -70,4 +70,6 @@ weac.pos:addEventListener("set", handle_event)
weac.pos:addEventListener("pop", handle_event)
weac.pos:addEventListener("push", handle_event)
weac.pos:addEventListener("clear", do_delete)
weac.pos:addEventListener("unmark", do_delete)
weac.pos:addEventListener("mark", do_update)