mirror of
https://github.com/minetest-mods/MoreMesecons.git
synced 2024-08-20 13:14:04 +02:00
MapDataStorage: change serialization in mod storage
Use minetest.serialize on the full values table instead of serializing each value independently and concatenating.
This commit is contained in:
parent
0000cfb474
commit
f2de7c89b1
@ -233,7 +233,6 @@ MapDataStorage.__index = {
|
|||||||
return iterfunc
|
return iterfunc
|
||||||
end,
|
end,
|
||||||
serialize = function(self)
|
serialize = function(self)
|
||||||
local serialize_data = minetest.serialize
|
|
||||||
local indices = {}
|
local indices = {}
|
||||||
local values = {}
|
local values = {}
|
||||||
local i = 1
|
local i = 1
|
||||||
@ -242,12 +241,12 @@ MapDataStorage.__index = {
|
|||||||
-- Convert the double reversible to a string;
|
-- Convert the double reversible to a string;
|
||||||
-- minetest.serialize does not (yet) do this
|
-- minetest.serialize does not (yet) do this
|
||||||
indices[i] = ("%a"):format(vi)
|
indices[i] = ("%a"):format(vi)
|
||||||
values[i] = serialize_data(v)
|
values[i] = v
|
||||||
end
|
end
|
||||||
result = {
|
result = {
|
||||||
version = "MapDataStorage_v1",
|
version = "MapDataStorage_v1",
|
||||||
indices = "return {" .. table.concat(indices, ",") .. "}",
|
indices = "return {" .. table.concat(indices, ",") .. "}",
|
||||||
values = "return {" .. table.concat(values, ",") .. "}",
|
values = minetest.serialize(values),
|
||||||
}
|
}
|
||||||
return minetest.serialize(result)
|
return minetest.serialize(result)
|
||||||
end,
|
end,
|
||||||
@ -260,8 +259,11 @@ MapDataStorage.deserialize = function(txtdata)
|
|||||||
end
|
end
|
||||||
-- I assume that minetest.deserialize correctly deserializes the indices,
|
-- I assume that minetest.deserialize correctly deserializes the indices,
|
||||||
-- which are in the %a format
|
-- which are in the %a format
|
||||||
indices = minetest.deserialize(data.indices)
|
local indices = minetest.deserialize(data.indices)
|
||||||
values = minetest.deserialize(data.values)
|
local values = minetest.deserialize(data.values)
|
||||||
|
if not indices or not values then
|
||||||
|
return MapDataStorage()
|
||||||
|
end
|
||||||
data = MapDataStorage()
|
data = MapDataStorage()
|
||||||
for i = 1,#indices do
|
for i = 1,#indices do
|
||||||
local vi = indices[i]
|
local vi = indices[i]
|
||||||
@ -306,7 +308,7 @@ function moremesecons.load_MapDataStorage_legacy(modstorage, name, oldname)
|
|||||||
modstorage:set_string(oldname, nil)
|
modstorage:set_string(oldname, nil)
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
t = modstorage:get_string("teleporters_rids_v2")
|
t = modstorage:get_string(name)
|
||||||
if t and t ~= "" then
|
if t and t ~= "" then
|
||||||
return MapDataStorage.deserialize(t)
|
return MapDataStorage.deserialize(t)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user