cartographer/storage.lua

41 lines
1.1 KiB
Lua
Raw Normal View History

2020-06-13 14:04:54 +02:00
-- Storage and saving
local mod_storage = minetest.get_mod_storage();
local map_data = {
2020-06-13 14:50:36 +02:00
-- Scanned map data
2020-06-13 14:04:54 +02:00
generated = minetest.deserialize(mod_storage:get_string("map")) or {},
2020-06-13 14:50:36 +02:00
-- Maps
2020-06-13 14:04:54 +02:00
maps = minetest.deserialize(mod_storage:get_string("maps")) or {},
2020-06-13 14:50:36 +02:00
-- The next id
2020-06-13 14:04:54 +02:00
next_map_id = mod_storage:get_int("next_map_id"),
2020-06-13 14:50:36 +02:00
-- The version of the map api
api_version = mod_storage:get_int("api_version"),
2020-06-13 14:04:54 +02:00
};
if map_data.next_map_id == 0 then
map_data.next_map_id = 1;
end
2020-06-13 14:50:36 +02:00
if map_data.api_version == 0 then
map_data.api_version = 1;
end
2020-06-13 14:04:54 +02:00
local function save()
mod_storage:set_string("maps", minetest.serialize(map_data.maps));
mod_storage:set_int("next_map_id", map_data.next_map_id);
mod_storage:set_string("map", minetest.serialize(map_data.generated));
2020-06-13 14:50:36 +02:00
mod_storage:set_string("api_version", minetest.serialize(map_data.api_version));
2020-06-13 14:04:54 +02:00
end
minetest.register_on_shutdown(save);
minetest.register_on_leaveplayer(save);
local function periodic_save()
save();
minetest.after(60, periodic_save);
end
minetest.after(60, periodic_save);
return map_data;