(hopefully) fix not save bug

This commit is contained in:
cpdef 2018-01-15 22:15:46 +01:00
parent c102d66ad7
commit 87ca00a932

View File

@ -44,7 +44,7 @@ local picbox = {
local current_version = "nopairs" local current_version = "nopairs"
local legacy = {} local legacy = {}
-- puts the version before the compressed data -- puts the version before the data
local function get_metastring(data) local function get_metastring(data)
return current_version.."(version)"..data return current_version.."(version)"..data
end end
@ -138,7 +138,8 @@ minetest.register_node("painting:pic", {
end end
local data = legacy.load_itemmeta(oldmetadata.fields["painting:picturedata"]) local data = legacy.load_itemmeta(oldmetadata.fields["painting:picturedata"])
print("DATA OF DIGGED IMAGE");
print(dump2(data))
--put picture data back into inventory item --put picture data back into inventory item
digger:get_inventory():add_item("main", { digger:get_inventory():add_item("main", {
name = "painting:paintedcanvas", name = "painting:paintedcanvas",
@ -154,10 +155,10 @@ minetest.register_node("painting:pic", {
local data = legacy.load_itemmeta(meta.fields["painting:picturedata"]) local data = legacy.load_itemmeta(meta.fields["painting:picturedata"])
--compare resulutions of picture and canvas the player wields --compare resulutions of picture and canvas the player wields
--if it isn't the same don't copy --if it isn't the same don't copy
wname = player:get_wielded_item():get_name() local wname = player:get_wielded_item():get_name()
local res = tonumber(string.sub(wname, #"painting:canvas_"+1)) local res = tonumber(string.sub(wname, #"painting:canvas_"+1))
if res == nil then return end if res == nil then return end
data_res = minetest.deserialize(minetest.decompress(data)).res data_res = minetest.deserialize(data).res
if data_res == nil then return end if data_res == nil then return end
if res ~= data_res then if res ~= data_res then
minetest.chat_send_player(player:get_player_name(), minetest.chat_send_player(player:get_player_name(),
@ -186,9 +187,7 @@ minetest.register_entity("painting:picent", {
on_activate = function(self, staticdata) on_activate = function(self, staticdata)
local pos = self.object:getpos() local pos = self.object:getpos()
local data = legacy.load_itemmeta(minetest.get_meta(pos):get_string("painting:picturedata")) local data = legacy.load_itemmeta(minetest.get_meta(pos):get_string("painting:picturedata"))
data = minetest.deserialize( data = minetest.deserialize(data)
minetest.decompress(data)
)
if not data if not data
or not data.grid then or not data.grid then
return return
@ -197,9 +196,7 @@ minetest.register_entity("painting:picent", {
if data.version ~= current_version then if data.version ~= current_version then
minetest.log("legacy", "[painting] updating placed picture data") minetest.log("legacy", "[painting] updating placed picture data")
data.version = current_version data.version = current_version
data = minetest.compress( data = minetest.serialize(data)
minetest.serialize(data)
)
minetest.get_meta(pos):set_string("painting:picturedata", get_metastring(data)) minetest.get_meta(pos):set_string("painting:picturedata", get_metastring(data))
end end
end end
@ -338,13 +335,13 @@ minetest.register_craftitem("painting:paintedcanvas", {
minetest.get_meta(pos):set_string("painting:picturedata", get_metastring(data)) minetest.get_meta(pos):set_string("painting:picturedata", get_metastring(data))
--add entity --add entity
dir = dirs[fd] local dir = dirs[fd]
local off = 0.5 - thickness - 0.01 local off = 0.5 - thickness - 0.01
pos.x = pos.x + dir.x * off pos.x = pos.x + dir.x * off
pos.z = pos.z + dir.z * off pos.z = pos.z + dir.z * off
data = minetest.deserialize(minetest.decompress(data)) data = minetest.deserialize(data)
if data == nil then return ItemStack("") end if data == nil then return ItemStack("") end
local obj = minetest.add_entity(pos, "painting:picent") local obj = minetest.add_entity(pos, "painting:picent")
@ -409,7 +406,7 @@ minetest.register_node("painting:canvasnode", {
digger:get_inventory():add_item("main", { digger:get_inventory():add_item("main", {
name = "painting:paintedcanvas", name = "painting:paintedcanvas",
count = 1, count = 1,
metadata = get_metastring(minetest.compress(minetest.serialize(data))) metadata = get_metastring(minetest.serialize(data))
}) })
end end
}) })
@ -567,8 +564,10 @@ function legacy.fix_grid(grid, version)
fix_eldest_grid(grid) fix_eldest_grid(grid)
end end
-- gets the compressed data from meta -- gets the data from meta
function legacy.load_itemmeta(data) function legacy.load_itemmeta(data)
print("LOAD ITEM DATA")
print(dump(data))
local vend = data:find"(version)" local vend = data:find"(version)"
if not vend then -- the oldest version if not vend then -- the oldest version
local t = minetest.deserialize(data) local t = minetest.deserialize(data)
@ -577,7 +576,7 @@ function legacy.load_itemmeta(data)
end end
minetest.log("legacy", "[painting] updating painting meta") minetest.log("legacy", "[painting] updating painting meta")
legacy.fix_grid(t.grid) legacy.fix_grid(t.grid)
return minetest.compress(minetest.serialize(t)) return minetest.serialize(t)
end end
local version = data:sub(1, vend-2) local version = data:sub(1, vend-2)
data = data:sub(vend+8) data = data:sub(vend+8)