From e3dc3163fc10ea878eb426c9aab3b4c2410abf30 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Wed, 12 Aug 2020 09:28:20 +1200 Subject: [PATCH] Use JSON to store areas. This works around a limit of ~21000 areas because of limits in minetest.deserialize(). --- internal.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal.lua b/internal.lua index c19a6d8..01a672d 100644 --- a/internal.lua +++ b/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,20 @@ function areas:load() self.areas = self.areas or {} return err end - self.areas = minetest.deserialize(file:read("*a")) + local data = file:read("*a") + local err + 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