]> git.lizzy.rs Git - worldedit.git/commitdiff
Mark the region with an entity cube.
authorUberi <azhang9@gmail.com>
Tue, 24 Dec 2013 19:07:42 +0000 (14:07 -0500)
committerUberi <azhang9@gmail.com>
Tue, 24 Dec 2013 19:07:42 +0000 (14:07 -0500)
worldedit/serialization.lua
worldedit_commands/mark.lua
worldedit_commands/textures/worldedit_cube.png [new file with mode: 0644]
worldedit_gui/init.lua

index 731b8d44459edff48aa1e6fe44cfa7463092fb92..bbedca5a966f49f4e2201c2b1f7038ba5bd5e4cf 100644 (file)
@@ -183,7 +183,7 @@ end
 --loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized\r
 --contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)\r
 worldedit.deserialize = function(originpos, value)\r
-       --make area stay loaded --wip: not very performant\r
+       --make area stay loaded\r
        local pos1, pos2 = worldedit.allocate(originpos, value)\r
        local manip = minetest.get_voxel_manip()\r
        manip:read_from_map(pos1, pos2)\r
index ad57a39a64fa6e69445833bd368aa8352e1dc117..e07e84925bcd0b18cb16f90c8b358147cabf22bc 100644 (file)
@@ -1,25 +1,6 @@
 worldedit.marker1 = {}\r
 worldedit.marker2 = {}\r
-worldedit.marker = {}\r
-\r
---wip: use this as a huge entity to make a full worldedit region box\r
-minetest.register_entity(":worldedit:region_cube", {\r
-       initial_properties = {\r
-               visual = "upright_sprite",\r
-               visual_size = {x=1.1, y=1.1},\r
-               textures = {"worldedit_pos1.png"},\r
-               visual_size = {x=10, y=10},\r
-               physical = false,\r
-       },\r
-       on_step = function(self, dtime)\r
-               if self.active == nil then\r
-                       self.object:remove()\r
-               end\r
-       end,\r
-       on_punch = function(self, hitter)\r
-               --wip: remove the entire region marker\r
-       end,\r
-})\r
+worldedit.marker_region = {}\r
 \r
 --marks worldedit region position 1\r
 worldedit.mark_pos1 = function(name)\r
@@ -37,11 +18,11 @@ worldedit.mark_pos1 = function(name)
        if pos1 ~= nil then\r
                --add marker\r
                worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1")\r
-               worldedit.marker1[name]:get_luaentity().active = true\r
-               if pos2 ~= nil then --region defined\r
-                       worldedit.mark_region(pos1, pos2)\r
+               if worldedit.marker1[name] ~= nil then\r
+                       worldedit.marker1[name]:get_luaentity().name = name\r
                end\r
        end\r
+       worldedit.mark_region(name)\r
 end\r
 \r
 --marks worldedit region position 2\r
@@ -60,23 +41,58 @@ worldedit.mark_pos2 = function(name)
        if pos2 ~= nil then\r
                --add marker\r
                worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2")\r
-               worldedit.marker2[name]:get_luaentity().active = true\r
-               if pos1 ~= nil then --region defined\r
-                       worldedit.mark_region(pos1, pos2)\r
+               if worldedit.marker2[name] ~= nil then\r
+                       worldedit.marker2[name]:get_luaentity().name = name\r
                end\r
        end\r
+       worldedit.mark_region(name)\r
 end\r
 \r
-worldedit.mark_region = function(pos1, pos2)\r
-       --make area stay loaded\r
-       local manip = minetest.get_voxel_manip()\r
-       manip:read_from_map(pos1, pos2)\r
+worldedit.mark_region = function(name)\r
+       local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]\r
 \r
-       if worldedit.marker[name] ~= nil then --marker already exists\r
-               --wip: remove markers\r
+       if worldedit.marker_region[name] ~= nil then --marker already exists\r
+               --wip: make the area stay loaded somehow\r
+               for _, entity in ipairs(worldedit.marker_region[name]) do\r
+                       entity:remove()\r
+               end\r
+               worldedit.marker_region[name] = nil\r
        end\r
        if pos1 ~= nil and pos2 ~= nil then\r
-               --wip: place markers\r
+               local pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+               local thickness = 0.2\r
+               local sizex, sizey, sizez = (1 + pos2.x - pos1.x) / 2, (1 + pos2.y - pos1.y) / 2, (1 + pos2.z - pos1.z) / 2\r
+\r
+               --make area stay loaded\r
+               local manip = minetest.get_voxel_manip()\r
+               manip:read_from_map(pos1, pos2)\r
+\r
+               local markers = {}\r
+\r
+               --XY plane markers\r
+               for _, z in ipairs({pos1.z - 0.5, pos2.z + 0.5}) do\r
+                       local marker = minetest.add_entity({x=pos1.x + sizex - 0.5, y=pos1.y + sizey - 0.5, z=z}, "worldedit:region_cube")\r
+                       marker:set_properties({\r
+                               visual_size={x=sizex * 2, y=sizey * 2},\r
+                               collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},\r
+                       })\r
+                       marker:get_luaentity().name = name\r
+                       table.insert(markers, marker)\r
+               end\r
+\r
+               --YZ plane markers\r
+               for _, x in ipairs({pos1.x - 0.5, pos2.x + 0.5}) do\r
+                       local marker = minetest.add_entity({x=x, y=pos1.y + sizey - 0.5, z=pos1.z + sizez - 0.5}, "worldedit:region_cube")\r
+                       marker:set_properties({\r
+                               visual_size={x=sizez * 2, y=sizey * 2},\r
+                               collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},\r
+                       })\r
+                       marker:setyaw(math.pi / 2)\r
+                       marker:get_luaentity().name = name\r
+                       table.insert(markers, marker)\r
+               end\r
+\r
+               worldedit.marker_region[name] = markers\r
        end\r
 end\r
 \r
@@ -91,14 +107,13 @@ minetest.register_entity(":worldedit:pos1", {
                physical = false,\r
        },\r
        on_step = function(self, dtime)\r
-               if self.active == nil then\r
+               if worldedit.marker1[self.name] == nil then\r
                        self.object:remove()\r
                end\r
        end,\r
        on_punch = function(self, hitter)\r
                self.object:remove()\r
-               local name = hitter:get_player_name()\r
-               worldedit.marker1[name] = nil\r
+               worldedit.marker1[self.name] = nil\r
        end,\r
 })\r
 \r
@@ -113,13 +128,34 @@ minetest.register_entity(":worldedit:pos2", {
                physical = false,\r
        },\r
        on_step = function(self, dtime)\r
-               if self.active == nil then\r
+               if worldedit.marker2[self.name] == nil then\r
                        self.object:remove()\r
                end\r
        end,\r
        on_punch = function(self, hitter)\r
                self.object:remove()\r
-               local name = hitter:get_player_name()\r
-               worldedit.marker2[name] = nil\r
+               worldedit.marker2[self.name] = nil\r
+       end,\r
+})\r
+\r
+minetest.register_entity(":worldedit:region_cube", {\r
+       initial_properties = {\r
+               visual = "upright_sprite",\r
+               visual_size = {x=1.1, y=1.1},\r
+               textures = {"worldedit_cube.png"},\r
+               visual_size = {x=10, y=10},\r
+               physical = false,\r
+       },\r
+       on_step = function(self, dtime)\r
+               if worldedit.marker_region[self.name] == nil then\r
+                       self.object:remove()\r
+                       return\r
+               end\r
+       end,\r
+       on_punch = function(self, hitter)\r
+               for _, entity in ipairs(worldedit.marker_region[self.name]) do\r
+                       entity:remove()\r
+               end\r
+               worldedit.marker_region[self.name] = nil\r
        end,\r
 })
\ No newline at end of file
diff --git a/worldedit_commands/textures/worldedit_cube.png b/worldedit_commands/textures/worldedit_cube.png
new file mode 100644 (file)
index 0000000..fde36a8
Binary files /dev/null and b/worldedit_commands/textures/worldedit_cube.png differ
index be6e94691c48d6f4717f1692b9d90576218eb146..9373cf8bebabe1df3a1fbe1599f5c4bfd32d97f1 100644 (file)
@@ -1,5 +1,7 @@
 worldedit = worldedit or {}
 
+--wip: simply add a button to the player inventory if unified_inventory AND inventory++ are both not installed
+
 --[[
 Example:
 
@@ -129,7 +131,7 @@ end
 worldedit.register_gui_function("worldedit_gui", {
        name = "WorldEdit GUI",
        get_formspec = function(name)
-               --create a form with all the buttons arranged in a grid --wip: show only buttons that the player has privs for
+               --create a form with all the buttons arranged in a grid
                local buttons, x, y, index = {}, 0, 1, 0
                local width, height = 3, 0.8
                local columns = 5