forked from mtcontrib/Minetest-WorldEdit
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.
This commit is contained in:
parent
2c2d7fdec1
commit
2ecdd6cb1d
@ -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)
|
||||
|
@ -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
|
10
init.lua
10
init.lua
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user