diff options
Diffstat (limited to 'areas')
-rw-r--r-- | areas/chatcommands.lua | 5 | ||||
-rw-r--r-- | areas/internal.lua | 36 |
2 files changed, 31 insertions, 10 deletions
diff --git a/areas/chatcommands.lua b/areas/chatcommands.lua index d37634a..6079e93 100644 --- a/areas/chatcommands.lua +++ b/areas/chatcommands.lua @@ -306,13 +306,14 @@ minetest.register_chatcommand("move_area", { return false, "You need to select an area first." end - area.pos1 = pos1 - area.pos2 = pos2 + areas:move(id, area, pos1, pos2) areas:save() + return true, "Area successfully moved." end, }) + minetest.register_chatcommand("area_info", { description = "Get information about area configuration and usage.", func = function(name, param) diff --git a/areas/internal.lua b/areas/internal.lua index ea94a27..05a31cd 100644 --- a/areas/internal.lua +++ b/areas/internal.lua @@ -128,19 +128,39 @@ function areas:remove(id, recurse) end end --- Checks if a area between two points is entirely contained by another area +--- Move an area. +function areas:move(id, area, pos1, pos2) + area.pos1 = pos1 + area.pos2 = pos2 + + if self.store then + self.store:remove_area(areas.store_ids[id]) + local sid = self.store:insert_area(pos1, pos2, tostring(id)) + if self:checkAreaStoreId(sid) then + self.store_ids[id] = sid + end + end +end + +-- Checks if a area between two points is entirely contained by another area. +-- Positions must be sorted. function areas:isSubarea(pos1, pos2, id) local area = self.areas[id] if not area then return false end - local p1, p2 = area.pos1, area.pos2 - if (pos1.x >= p1.x and pos1.x <= p2.x) and - (pos2.x >= p1.x and pos2.x <= p2.x) and - (pos1.y >= p1.y and pos1.y <= p2.y) and - (pos2.y >= p1.y and pos2.y <= p2.y) and - (pos1.z >= p1.z and pos1.z <= p2.z) and - (pos2.z >= p1.z and pos2.z <= p2.z) then + local ap1, ap2 = area.pos1, area.pos2 + local ap1x, ap1y, ap1z = ap1.x, ap1.y, ap1.z + local ap2x, ap2y, ap2z = ap2.x, ap2.y, ap2.z + local p1x, p1y, p1z = pos1.x, pos1.y, pos1.z + local p2x, p2y, p2z = pos2.x, pos2.y, pos2.z + if + (p1x >= ap1x and p1x <= ap2x) and + (p2x >= ap1x and p2x <= ap2x) and + (p1y >= ap1y and p1y <= ap2y) and + (p2y >= ap1y and p2y <= ap2y) and + (p1z >= ap1z and p1z <= ap2z) and + (p2z >= ap1z and p2z <= ap2z) then return true end end |