From 2ecdd6cb1dd05b5627cbee32b357cfc15594809b Mon Sep 17 00:00:00 2001 From: Anthony Zhang Date: Thu, 19 Jul 2012 22:54:26 -0400 Subject: Re-add support for the old WorldEdit save format on a load-only basis. Implemented as worldedit.deserialize_old(), and documented in README.md. //load will now transparently detect these files and load them correctly. --- functions.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'functions.lua') diff --git a/functions.lua b/functions.lua index b752b06..1e727db 100644 --- a/functions.lua +++ b/functions.lua @@ -246,4 +246,35 @@ worldedit.deserialize = function(originpos, value) count = count + 1 end return count +end + +--loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized +--based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible) +worldedit.deserialize_old = function(originpos, value) + --obtain the node table + local count = 0 + local get_tables = loadstring(value) + if get_tables == nil then --error loading value + return count + end + local tables = get_tables() + + --transform the node table into an array of nodes + for i = 1, #tables do + for j, v in pairs(tables[i]) do + if type(v) == "table" then + tables[i][j] = tables[v[1]] + end + end + end + + --load the node array + local env = minetest.env + for i, v in ipairs(tables[1]) do + local pos = v[1] + pos.x, pos.y, pos.z = originpos.x + pos.x, originpos.y + pos.y, originpos.z + pos.z + env:add_node(pos, v[2]) + count = count + 1 + end + return count end \ No newline at end of file -- cgit v1.2.3