Use JSON to store areas (#47)

This works around a limit of ~21000 areas because of limits in 'minetest.deserialize()'. Files will be migrated to the new format on first change.
This commit is contained in:
luk3yx 2020-08-28 22:54:48 +12:00 committed by GitHub
parent 142a723eb2
commit a9c05f0e38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,7 +18,7 @@ end
-- Save the areas table to a file
function areas:save()
local datastr = minetest.serialize(self.areas)
local datastr = minetest.write_json(self.areas)
if not datastr then
minetest.log("error", "[areas] Failed to serialize area data!")
return
@ -33,10 +33,19 @@ function areas:load()
self.areas = self.areas or {}
return err
end
self.areas = minetest.deserialize(file:read("*a"))
local data = file:read("*a")
if data:sub(1, 1) == "[" then
self.areas, err = minetest.parse_json(data)
else
self.areas, err = minetest.deserialize(data)
end
if type(self.areas) ~= "table" then
self.areas = {}
end
if err and #data > 10 then
minetest.log("error", "[areas] Failed to load area data: " ..
tostring(err))
end
file:close()
self:populateStore()
end