forked from nalc/areas
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
4eeb2a9d11
13
internal.lua
13
internal.lua
@ -18,7 +18,7 @@ end
|
|||||||
|
|
||||||
-- Save the areas table to a file
|
-- Save the areas table to a file
|
||||||
function areas:save()
|
function areas:save()
|
||||||
local datastr = minetest.serialize(self.areas)
|
local datastr = minetest.write_json(self.areas)
|
||||||
if not datastr then
|
if not datastr then
|
||||||
minetest.log("error", "[areas] Failed to serialize area data!")
|
minetest.log("error", "[areas] Failed to serialize area data!")
|
||||||
return
|
return
|
||||||
@ -33,10 +33,19 @@ function areas:load()
|
|||||||
self.areas = self.areas or {}
|
self.areas = self.areas or {}
|
||||||
return err
|
return err
|
||||||
end
|
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
|
if type(self.areas) ~= "table" then
|
||||||
self.areas = {}
|
self.areas = {}
|
||||||
end
|
end
|
||||||
|
if err and #data > 10 then
|
||||||
|
minetest.log("error", "[areas] Failed to load area data: " ..
|
||||||
|
tostring(err))
|
||||||
|
end
|
||||||
file:close()
|
file:close()
|
||||||
self:populateStore()
|
self:populateStore()
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user