Commit 04645b1a authored by Fedja Beader's avatar Fedja Beader
Browse files

worldedit: support loading saved builds

parent 50d88f67
......@@ -226,6 +226,8 @@ local function csmwe_chatcommand_func(param)
if args[2] then
node_storage:save(args[2])
end
elseif args[1] == "load" and args[2] then
node_storage = WorldEdit.NodeStorage:load(args[2]) -- overwrite old node_storage
elseif args[1] == "paste" then
if not positions:get(1) then
l:err("You need to specify anchor position (minimal x,y,z) to paste a build")
......
......@@ -83,6 +83,25 @@ function NodeStorage:from_bounding_box(bb)
end
-- TODO: lua can't really list files in a directory...
function NodeStorage:load(fname)
local file = io.open(fname, "r")
if file then
local contents = file:read("*all")
file:close()
local object = minetest.deserialize(contents)
object.fname = fname
setmetatable(object, self)
object.__index = self
return object
else
l:err("Unable to open file '" .. fname .. "' for loading!")
end
end
function NodeStorage:save(fname)
self.fname = fname
local file = io.open(fname, "w")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment