Merge pull request #6 from cpdef/master
found the picture not save bug (hopefully)
This commit is contained in:
commit
830e612be8
@ -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(dump(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",
|
||||||
@ -150,14 +151,15 @@ minetest.register_node("painting:pic", {
|
|||||||
on_punch = function(pos, node, player, pointed_thing)
|
on_punch = function(pos, node, player, pointed_thing)
|
||||||
local meta = minetest.get_meta(pos):to_table()
|
local meta = minetest.get_meta(pos):to_table()
|
||||||
if meta == nil then return end
|
if meta == nil then return end
|
||||||
|
--print("metadata: painting:picturedata:")
|
||||||
|
--print(dump(meta.fields["painting:picturedata"]))
|
||||||
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(),
|
||||||
@ -185,10 +187,16 @@ 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 ldata = legacy.load_itemmeta(minetest.get_meta(pos):get_string("painting:picturedata"))
|
||||||
data = minetest.deserialize(
|
local data = minetest.deserialize(ldata)
|
||||||
minetest.decompress(data)
|
-- for backwards compatiblity
|
||||||
)
|
if not data then
|
||||||
|
data = minetest.deserialize(minetest.decompress(ldata))
|
||||||
|
if data then
|
||||||
|
print("loaded old data, converted to new uncompressed")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- end backwards compatiblity
|
||||||
if not data
|
if not data
|
||||||
or not data.grid then
|
or not data.grid then
|
||||||
return
|
return
|
||||||
@ -197,9 +205,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
|
||||||
@ -280,6 +286,14 @@ minetest.register_entity("painting:paintent", {
|
|||||||
|
|
||||||
on_activate = function(self, staticdata)
|
on_activate = function(self, staticdata)
|
||||||
local data = minetest.deserialize(staticdata)
|
local data = minetest.deserialize(staticdata)
|
||||||
|
-- for backwards compatiblity
|
||||||
|
if not data then
|
||||||
|
data = minetest.deserialize(minetest.decompress(staticdata))
|
||||||
|
if data then
|
||||||
|
print("loaded old data, converted to new uncompressed")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- end backwards compatiblity
|
||||||
if not data then
|
if not data then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -334,17 +348,28 @@ minetest.register_craftitem("painting:paintedcanvas", {
|
|||||||
|
|
||||||
--save metadata
|
--save metadata
|
||||||
local data = legacy.load_itemmeta(itemstack:get_metadata())
|
local data = legacy.load_itemmeta(itemstack:get_metadata())
|
||||||
|
-- for backwards compatiblity
|
||||||
|
if not minetest.deserialize(data) then
|
||||||
|
status, data = pcall(minetest.decompress(data))
|
||||||
|
if (status and data) then
|
||||||
|
print("tryed to save old data"..
|
||||||
|
"converted to new uncompressed, save")
|
||||||
|
elseif not status then
|
||||||
|
print("error loading data")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- end backwards compatiblity
|
||||||
if data == nil then return ItemStack("") end
|
if data == nil then return ItemStack("") end
|
||||||
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 +434,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 +592,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("LEGACY 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 +604,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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user