diff options
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | functions.lua | 31 | ||||
-rw-r--r-- | init.lua | 10 |
3 files changed, 45 insertions, 4 deletions
@@ -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) 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 @@ -1,8 +1,5 @@ minetest.register_privilege("worldedit", "Can use WorldEdit commands")
---wip: check to make sure player positions are set before doing editing
---wip; fix meseconedit to export to new WorldEdit format
-
worldedit = {}
worldedit.set_pos = {}
@@ -312,7 +309,12 @@ minetest.register_chatcommand("/load", { local value = file:read("*a")
file:close()
- local count = worldedit.deserialize(pos1, value)
+ local count
+ if value:find("{") then --old WorldEdit format
+ count = worldedit.deserialize_old(pos1, value)
+ else --new WorldEdit format
+ count = worldedit.deserialize(pos1, value)
+ end
minetest.chat_send_player(name, count .. " nodes loaded")
end,
|