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:
parent
142a723eb2
commit
a9c05f0e38
13
internal.lua
13
internal.lua
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user