61 lines
1.7 KiB
Lua
61 lines
1.7 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 = {
|
|
};
|
|
|
|
local map_data = {
|
|
generated = minetest.deserialize(mod_storage:get_string("map")) or {},
|
|
|
|
maps = minetest.deserialize(mod_storage:get_string("maps")) or {},
|
|
next_map_id = mod_storage:get_int("next_map_id"),
|
|
}
|
|
|
|
if map_data.next_map_id == 0 then
|
|
map_data.next_map_id = 1;
|
|
end
|
|
|
|
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));
|
|
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);
|
|
|
|
local chunk_size = 16;
|
|
local chunk = {
|
|
to = function(coord)
|
|
return math.floor(coord / chunk_size);
|
|
end,
|
|
|
|
from = function(coord)
|
|
return math.floor(coord * chunk_size);
|
|
end
|
|
};
|
|
|
|
local biome_lookup = {};
|
|
local marker_lookup = {};
|
|
|
|
-- Includes
|
|
local skin = loadfile(modpath .. "/skin_api.lua") ();
|
|
local gui = loadfile(modpath .. "/formspec.lua") ();
|
|
|
|
local scanner = loadfile(modpath .. "/scanner.lua") (map_data, chunk);
|
|
loadfile(modpath .. "/map_api.lua") (map_data, chunk, scanner, biome_lookup, marker_lookup);
|
|
local map_formspec = loadfile(modpath .. "/map_formspec.lua") (map_data, gui, skin);
|
|
loadfile(modpath .. "/items.lua") (chunk, marker_lookup, gui, skin, map_formspec);
|
|
loadfile(modpath .. "/commands.lua") (map_formspec);
|
|
loadfile(modpath .. "/table.lua") (gui, skin);
|
|
|
|
cartographer.skin = skin;
|