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
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
2 changed files with 33 additions and 21 deletions

@ -9,28 +9,39 @@ local Vector3 = wea_c.Vector3
---Selection helpers and modifiers
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.
-- @param name string Player name.
-- @param pos vector The position to include.
function selection.add_point(name, pos)
if pos ~= nil then
local created_new = not worldedit.pos1[name] or not worldedit.pos2[name]
-- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")")
if not worldedit.pos1[name] then worldedit.pos1[name] = Vector3.clone(pos) end
if not worldedit.pos2[name] then worldedit.pos2[name] = Vector3.clone(pos) end
function selection.add_point(name, newpos)
if newpos ~= nil then
print("DEBUG:selection.add_point newpos", newpos)
local has_pos1 = not not wea_c.pos.get1(name)
local has_pos2 = not not wea_c.pos.get2(name)
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)
local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[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)
worldedit.pos1[name], worldedit.pos2[name] = Vector3.expand_region(
Vector3.clone(worldedit.pos1[name]),
Vector3.clone(worldedit.pos2[name]),
pos
local pos1, pos2 = wea_c.pos.get1(name), wea_c.pos.get2(name)
local volume_before = worldedit.volume(pos1, pos2)
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
if volume_difference == 0 and created_new then
@ -42,21 +53,20 @@ function selection.add_point(name, pos)
msg = msg..volume_difference.." node"
if volume_difference ~= 1 then msg = msg.."s" end
worldedit.marker_update(name)
-- Done automatically
-- worldedit.marker_update(name)
worldedit.player_notify(name, msg)
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")
end
end
--- Clears current selection.
--- Clears current selection, *but only pos1 and pos2!
-- @param name string Player name.
function selection.clear_points(name)
worldedit.pos1[name] = nil
worldedit.pos2[name] = nil
worldedit.marker_update(name)
worldedit.set_pos[name] = nil
wea_c.pos.clear(name)
-- worldedit.marker_update(name)
worldedit.player_notify(name, "Region cleared")
end

@ -146,6 +146,7 @@ end
-- @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).
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
ensure_player(player_name)
@ -196,6 +197,7 @@ local function clear(player_name)
if worldedit then
if worldedit.pos1 then worldedit.pos1[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
anchor:emit("clear", { player_name = player_name })
end