summaryrefslogtreecommitdiff
path: root/worldedit/serialization.lua
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-10-29 22:47:08 -0400
committerShadowNinja <shadowninja@minetest.net>2015-02-01 15:56:16 -0500
commitbb8456b71119ca6303b9e9706829a84dc7f81ab3 (patch)
tree919026712fb25b847ef8d09626400bbf0fd556eb /worldedit/serialization.lua
parent1f277147ca03788b784ee13fb1dd4e07889b4b59 (diff)
Cleanup and fixup
Non-stylistic changes: * Add LuaDoc/LDoc support. * Fix `clear_objects` area size calculation. * Fix `clear_objects` removing player objects. * Fix shadowing of marker entity name with player name. * Make visualization functions use `swap_node`. * Make hidden nodes unwalkable. * Prevent `hide` from hiding air. * Make deprecated functions log to deprecated stream when called. * Fixed `replaceinverse` not using normalized node names. * Added .gitignore. * Bump version to 1.1. Stylistic changes: * Change `x = function` to `function x`. * Change comment format. * Make missing VoxelManip error less obnoxious. * Move `sort_pos` into `common.lua`, which is a required module. * Remove local copies of `minetest`. * Remove `worldedit = worldedit or {}` from modules. * Replace replaceinverse with an inverse argument to `replace`. * Added `error()`s on on invalid axes. * Change `wip` to `TODO`. * Rename `clearobjects` to `clear_objects`. * Remove `hollow_{sphere,dome,cylinder}` and replace them with a hollow parameter to each function. * Add helpers to reduce code duplication. * Renamed `Chat Commands.md` to `ChatCommands.md`.
Diffstat (limited to 'worldedit/serialization.lua')
-rw-r--r--worldedit/serialization.lua27
1 files changed, 12 insertions, 15 deletions
diff --git a/worldedit/serialization.lua b/worldedit/serialization.lua
index f129168..bec7e09 100644
--- a/worldedit/serialization.lua
+++ b/worldedit/serialization.lua
@@ -1,5 +1,5 @@
-worldedit = worldedit or {}
-local minetest = minetest -- Local copy of global
+--- Schematic serialization and deserialiation.
+-- @module worldedit.serialization
worldedit.LATEST_SERIALIZATION_VERSION = 5
local LATEST_SERIALIZATION_HEADER = worldedit.LATEST_SERIALIZATION_VERSION .. ":"
@@ -52,11 +52,10 @@ end
-- @return The serialized data.
-- @return The number of nodes serialized.
function worldedit.serialize(pos1, pos2)
- -- Keep area loaded
- local manip = minetest.get_voxel_manip()
- manip:read_from_map(pos1, pos2)
+ pos1, pos2 = worldedit.sort_pos(pos1, pos2)
+
+ worldedit.keep_loaded(pos1, pos2)
- local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local pos = {x=pos1.x, y=0, z=0}
local count = 0
local result = {}
@@ -112,7 +111,7 @@ end
-- Contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile)
-- by ChillCode, available under the MIT license.
-- @return A node list in the latest format, or nil on failure.
-function worldedit.load_schematic(value)
+local function load_schematic(value)
local version, header, content = worldedit.read_header(value)
local nodes = {}
if version == 1 or version == 2 then -- Original flat table format
@@ -187,15 +186,15 @@ end
-- @return Low corner position.
-- @return High corner position.
-- @return The number of nodes.
-worldedit.allocate = function(origin_pos, value)
- local nodes = worldedit.load_schematic(value)
+function worldedit.allocate(origin_pos, value)
+ local nodes = load_schematic(value)
if not nodes then return nil end
return worldedit.allocate_with_nodes(origin_pos, nodes)
end
-- Internal
-worldedit.allocate_with_nodes = function(origin_pos, nodes)
+function worldedit.allocate_with_nodes(origin_pos, nodes)
local huge = math.huge
local pos1x, pos1y, pos1z = huge, huge, huge
local pos2x, pos2y, pos2z = -huge, -huge, -huge
@@ -217,14 +216,12 @@ end
--- Loads the nodes represented by string `value` at position `origin_pos`.
-- @return The number of nodes deserialized.
-worldedit.deserialize = function(origin_pos, value)
- local nodes = worldedit.load_schematic(value)
+function worldedit.deserialize(origin_pos, value)
+ local nodes = load_schematic(value)
if not nodes then return nil end
- -- Make area stay loaded
local pos1, pos2 = worldedit.allocate_with_nodes(origin_pos, nodes)
- local manip = minetest.get_voxel_manip()
- manip:read_from_map(pos1, pos2)
+ worldedit.keep_loaded(pos1, pos2)
local origin_x, origin_y, origin_z = origin_pos.x, origin_pos.y, origin_pos.z
local count = 0