61 lines
1.6 KiB
Lua
61 lines
1.6 KiB
Lua
local mod_storage = minetest.get_mod_storage();
|
|
|
|
-- The path to this mod, for including files
|
|
local modpath = minetest.get_modpath("cartographer");
|
|
|
|
-- The API object
|
|
cartographer = {
|
|
scan_queue = {},
|
|
};
|
|
_cartographer = {
|
|
CHUNK_SIZE = 16,
|
|
|
|
biome_lookup = {},
|
|
marker_lookup = {},
|
|
maps = minetest.deserialize(mod_storage:get_string("maps")) or {},
|
|
next_map_id = mod_storage:get_int("next_map_id"),
|
|
|
|
materials_by_name = {},
|
|
materials_by_group = {},
|
|
};
|
|
|
|
if _cartographer.next_map_id == 0 then
|
|
_cartographer.next_map_id = 1;
|
|
end
|
|
|
|
local map_data = {
|
|
generated = minetest.deserialize(mod_storage:get_string("map")) or {},
|
|
}
|
|
|
|
local function save()
|
|
mod_storage:set_string("maps", minetest.serialize(_cartographer.maps));
|
|
mod_storage:set_int("next_map_id", _cartographer.next_map_id);
|
|
mod_storage:set_string("map", minetest.serialize(map_data.generated));
|
|
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);
|
|
|
|
function tochunk(coord)
|
|
return math.floor(coord / _cartographer.CHUNK_SIZE);
|
|
end
|
|
|
|
function fromchunk(coord)
|
|
return math.floor(coord * _cartographer.CHUNK_SIZE);
|
|
end
|
|
|
|
-- Includes
|
|
cartographer.skin = loadfile(modpath .. "/skin_api.lua") ();
|
|
loadfile(modpath .. "/scanner.lua") (map_data);
|
|
loadfile(modpath .. "/map_api.lua") ();
|
|
loadfile(modpath .. "/items.lua") ();
|
|
loadfile(modpath .. "/marker_formspec.lua") ();
|
|
loadfile(modpath .. "/map_formspec.lua") (map_data);
|
|
loadfile(modpath .. "/commands.lua") ();
|
|
loadfile(modpath .. "/table.lua") ();
|