From 9209d81d2022146ff53aea42dc66739b97b9138b Mon Sep 17 00:00:00 2001 From: Anthony Zhang Date: Wed, 20 Mar 2013 17:12:48 -0400 Subject: //metasave and //metaload are now superceded by //save and //load's new functionality. worldedit.deserialize now supports every version of the WorldEdit format that has ever existed, and the new worldedit.valueversion uses file characteristics to determine which type of file format a given file uses. The new WorldEdit file format is the same as the one used by MineTest for serializing data, and is capable of storing arbitrary data, as well as leaving fields for future improvements. In other words, this is the last forward-compatibility breaking change that will be made to the file format. --- worldedit_commands/init.lua | 85 +++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 61 deletions(-) (limited to 'worldedit_commands') diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 67f50e3..208eb5d 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -750,12 +750,11 @@ minetest.register_chatcommand("/allocate", { local value = file:read("*a") file:close() - local nodepos1, nodepos2, count - if value:find("{") then --old WorldEdit format - nodepos1, nodepos2, count = worldedit.allocate_old(pos1, value) - else --new WorldEdit format - nodepos1, nodepos2, count = worldedit.allocate(pos1, value) + if worldedit.valueversion(value) == 0 then --unknown version + minetest.chat_send_player(name, "Invalid file: file is invalid or created with newer version of WorldEdit") + return end + local nodepos1, nodepos2, count = worldedit.allocate(pos1, value) worldedit.pos1[name] = nodepos1 worldedit.mark_pos1(name) @@ -768,7 +767,7 @@ minetest.register_chatcommand("/allocate", { minetest.register_chatcommand("/load", { params = "", - description = "Load nodes from \"(world folder)/schems/.we\" with position 1 of the current WorldEdit region as the origin", + description = "Load nodes from \"(world folder)/schems/[.we[m]]\" with position 1 of the current WorldEdit region as the origin", privs = {worldedit=true}, func = function(name, param) local pos1 = worldedit.pos1[name] @@ -782,69 +781,33 @@ minetest.register_chatcommand("/load", { return end - local filename = minetest.get_worldpath() .. "/schems/" .. param .. ".we" - local file, err = io.open(filename, "rb") - if err ~= nil then - minetest.chat_send_player(name, "Could not open file \"" .. filename .. "\"") + --find the file in the world path + local testpaths = { + minetest.get_worldpath() .. "/schems/" .. param, + minetest.get_worldpath() .. "/schems/" .. param .. ".we", + minetest.get_worldpath() .. "/schems/" .. param .. ".wem", + } + local file, err + for index, path in ipairs(testpaths) do + file, err = io.open(path, "rb") + if not err then + break + end + end + if err then + minetest.chat_send_player(name, "Could not open file \"" .. param .. "\"") return end local value = file:read("*a") file:close() - 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, -}) - -minetest.register_chatcommand("/metasave", { - params = "", - description = "Save the current WorldEdit region to \"(world folder)/schems/.wem\"", - privs = {worldedit=true}, - func = function(name, param) - local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] - if pos1 == nil or pos2 == nil then - minetest.chat_send_player(name, "No WorldEdit region selected") + if worldedit.valueversion(value) == 0 then --unknown version + minetest.chat_send_player(name, "Invalid file: file is invalid or created with newer version of WorldEdit") return end - if param == "" then - minetest.chat_send_player(name, "Invalid usage: " .. param) - return - end - local count, err = worldedit.metasave(pos1, pos2, param) - if err then - minetest.chat_send_player(name, "error loading file: " .. err) - else - minetest.chat_send_player(name, count .. " nodes saved") - end - end, -}) + local count = worldedit.deserialize(pos1, value) -minetest.register_chatcommand("/metaload", { - params = "", - description = "Load nodes from \"(world folder)/schems/.wem\" with position 1 of the current WorldEdit region as the origin", - privs = {worldedit=true}, - func = function(name, param) - local pos1 = worldedit.pos1[name] - if pos1 == nil then - minetest.chat_send_player(name, "No WorldEdit region selected") - return - end - if param == "" then - minetest.chat_send_player(name, "Invalid usage: " .. param) - return - end - local count, err = worldedit.metaload(pos1, param) - if err then - minetest.chat_send_player(name, "Error loading file: " .. err) - else - minetest.chat_send_player(name, count .. " nodes loaded") - end + minetest.chat_send_player(name, count .. " nodes loaded") end, }) -- cgit v1.2.3