update cloud wand to use new wea_c.pos interface

This commit is contained in:
Starbeamrainbowlabs 2023-06-27 19:39:57 +01:00
parent 1c163186b6
commit 53bbe14c63
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
2 changed files with 33 additions and 21 deletions

View File

@ -9,28 +9,39 @@ local Vector3 = wea_c.Vector3
---Selection helpers and modifiers ---Selection helpers and modifiers
local selection = {} local selection = {}
--- Additively adds a point to the current selection or --- Additively adds a point to the current selection defined by pos1..pos2 or
-- makes a selection from the provided point. -- makes a selection from the provided point.
-- @param name string Player name. -- @param name string Player name.
-- @param pos vector The position to include. -- @param pos vector The position to include.
function selection.add_point(name, pos) function selection.add_point(name, newpos)
if pos ~= nil then if newpos ~= nil then
local created_new = not worldedit.pos1[name] or not worldedit.pos2[name] print("DEBUG:selection.add_point newpos", newpos)
-- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")") local has_pos1 = not not wea_c.pos.get1(name)
if not worldedit.pos1[name] then worldedit.pos1[name] = Vector3.clone(pos) end local has_pos2 = not not wea_c.pos.get2(name)
if not worldedit.pos2[name] then worldedit.pos2[name] = Vector3.clone(pos) end local created_new = not has_pos1 or not has_pos2
if not has_pos1 then wea_c.pos.set1(name, Vector3.clone(newpos)) end
if not has_pos2 then wea_c.pos.set2(name, Vector3.clone(newpos)) end
worldedit.marker_update(name) -- Now no longer needed, given that the new sysstem uses an event listener to push updates to the selected region automatically
-- worldedit.marker_update(name)
local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) local pos1, pos2 = wea_c.pos.get1(name), wea_c.pos.get2(name)
worldedit.pos1[name], worldedit.pos2[name] = Vector3.expand_region( local volume_before = worldedit.volume(pos1, pos2)
Vector3.clone(worldedit.pos1[name]),
Vector3.clone(worldedit.pos2[name]),
pos local new_pos1, new_pos2 = Vector3.expand_region(
Vector3.clone(pos1),
Vector3.clone(pos2),
newpos
) )
local volume_after = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name]) wea_c.pos.set1(name, new_pos1)
wea_c.pos.set2(name, new_pos2)
local volume_after = worldedit.volume(new_pos1, new_pos2)
local volume_difference = volume_after - volume_before local volume_difference = volume_after - volume_before
if volume_difference == 0 and created_new then if volume_difference == 0 and created_new then
@ -42,21 +53,20 @@ function selection.add_point(name, pos)
msg = msg..volume_difference.." node" msg = msg..volume_difference.." node"
if volume_difference ~= 1 then msg = msg.."s" end if volume_difference ~= 1 then msg = msg.."s" end
worldedit.marker_update(name) -- Done automatically
-- worldedit.marker_update(name)
worldedit.player_notify(name, msg) worldedit.player_notify(name, msg)
else else
worldedit.player_notify(name, "Error: Too far away (try raising your maxdist with //farwand maxdist <number>)") worldedit.player_notify(name, "Error. Too far away (try raising your maxdist with //farwand maxdist <number>)")
-- print("[set_pos1]", name, "nil") -- print("[set_pos1]", name, "nil")
end end
end end
--- Clears current selection. --- Clears current selection, *but only pos1 and pos2!
-- @param name string Player name. -- @param name string Player name.
function selection.clear_points(name) function selection.clear_points(name)
worldedit.pos1[name] = nil wea_c.pos.clear(name)
worldedit.pos2[name] = nil -- worldedit.marker_update(name)
worldedit.marker_update(name)
worldedit.set_pos[name] = nil
worldedit.player_notify(name, "Region cleared") worldedit.player_notify(name, "Region cleared")
end end

View File

@ -146,6 +146,7 @@ end
-- @param pos Vector3 The position to set. -- @param pos Vector3 The position to set.
-- @returns bool Whether the operation was successful or not (players aren't allowed more than positions_count_limit number of positions at a time). -- @returns bool Whether the operation was successful or not (players aren't allowed more than positions_count_limit number of positions at a time).
local function set(player_name, i, pos) local function set(player_name, i, pos)
-- It's a shame that Lua doesn't have a throw/raise, 'cause we could sure use it here
if i > positions_count_limit then return false end if i > positions_count_limit then return false end
ensure_player(player_name) ensure_player(player_name)
@ -196,6 +197,7 @@ local function clear(player_name)
if worldedit then if worldedit then
if worldedit.pos1 then worldedit.pos1[player_name] = nil end if worldedit.pos1 then worldedit.pos1[player_name] = nil end
if worldedit.pos2 then worldedit.pos2[player_name] = nil end if worldedit.pos2 then worldedit.pos2[player_name] = nil end
if worldedit.set_pos then worldedit.set_pos[player_name] = nil end
end end
anchor:emit("clear", { player_name = player_name }) anchor:emit("clear", { player_name = player_name })
end end