]> git.lizzy.rs Git - worldedit.git/commitdiff
Re-add support for the old WorldEdit save format on a load-only basis. Implemented...
authorAnthony Zhang <azhang9@gmail.com>
Fri, 20 Jul 2012 02:54:26 +0000 (22:54 -0400)
committerAnthony Zhang <azhang9@gmail.com>
Fri, 20 Jul 2012 02:54:26 +0000 (22:54 -0400)
README.md
functions.lua
init.lua

index ffe6852e68039d5113dd64df38c085c156578653..8b17a371e27be9458b723f9564afe41c17d5f2de 100644 (file)
--- a/README.md
+++ b/README.md
@@ -179,6 +179,14 @@ Loads the nodes represented by string `value` at position `originpos`.
 
 Returns the number of nodes deserialized.
 
+### worldedit.deserialize_old(originpos, value)
+
+Loads the nodes represented by string `value` at position `originpos`, using the older table-based WorldEdit format.
+
+This function is deprecated, and should not be used unless there is a need to support legacy WorldEdit save files.
+
+Returns the number of nodes deserialized.
+
 License
 -------
 Copyright 2012 sfan5 and Anthony Zhang (Temperest)
index b752b06de9f6127dffb781bc1ec877b71683bc7b..1e727db3fa2c11033906845985800d0b61f325cf 100644 (file)
@@ -246,4 +246,35 @@ worldedit.deserialize = function(originpos, value)
                count = count + 1\r
        end\r
        return count\r
+end\r
+\r
+--loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized\r
+--based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)\r
+worldedit.deserialize_old = function(originpos, value)\r
+       --obtain the node table\r
+       local count = 0\r
+       local get_tables = loadstring(value)\r
+       if get_tables == nil then --error loading value\r
+               return count\r
+       end\r
+       local tables = get_tables()\r
+\r
+       --transform the node table into an array of nodes\r
+       for i = 1, #tables do\r
+               for j, v in pairs(tables[i]) do\r
+                       if type(v) == "table" then\r
+                               tables[i][j] = tables[v[1]]\r
+                       end\r
+               end\r
+       end\r
+\r
+       --load the node array\r
+       local env = minetest.env\r
+       for i, v in ipairs(tables[1]) do\r
+               local pos = v[1]\r
+               pos.x, pos.y, pos.z = originpos.x + pos.x, originpos.y + pos.y, originpos.z + pos.z\r
+               env:add_node(pos, v[2])\r
+               count = count + 1\r
+       end\r
+       return count\r
 end
\ No newline at end of file
index 9c72ac1b372ad3e252d66d85c59171f73c973704..64e14b5a57e7f3a017e8c0b7a411b66ce1eebf3e 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -1,8 +1,5 @@
 minetest.register_privilege("worldedit", "Can use WorldEdit commands")\r
 \r
---wip: check to make sure player positions are set before doing editing\r
---wip; fix meseconedit to export to new WorldEdit format\r
-\r
 worldedit = {}\r
 \r
 worldedit.set_pos = {}\r
@@ -312,7 +309,12 @@ minetest.register_chatcommand("/load", {
                local value = file:read("*a")\r
                file:close()\r
 \r
-               local count = worldedit.deserialize(pos1, value)\r
+               local count\r
+               if value:find("{") then --old WorldEdit format\r
+                       count = worldedit.deserialize_old(pos1, value)\r
+               else --new WorldEdit format\r
+                       count = worldedit.deserialize(pos1, value)\r
+               end\r
 \r
                minetest.chat_send_player(name, count .. " nodes loaded")\r
        end,\r