2020-02-16 18:55:07 +01:00
|
|
|
local mod_storage = minetest.get_mod_storage();
|
|
|
|
|
2020-06-02 00:00:02 +02:00
|
|
|
-- The path to this mod, for including files
|
|
|
|
local modpath = minetest.get_modpath("cartographer");
|
|
|
|
|
2020-02-16 18:55:07 +01:00
|
|
|
-- The API object
|
|
|
|
cartographer = {
|
|
|
|
scan_queue = {},
|
|
|
|
};
|
|
|
|
|
2020-06-01 13:59:34 +02:00
|
|
|
local map_data = {
|
2020-02-16 18:55:07 +01:00
|
|
|
generated = minetest.deserialize(mod_storage:get_string("map")) or {},
|
2020-06-09 02:01:26 +02:00
|
|
|
|
|
|
|
maps = minetest.deserialize(mod_storage:get_string("maps")) or {},
|
|
|
|
next_map_id = mod_storage:get_int("next_map_id"),
|
2020-02-16 18:55:07 +01:00
|
|
|
}
|
|
|
|
|
2020-06-09 02:01:26 +02:00
|
|
|
if map_data.next_map_id == 0 then
|
|
|
|
map_data.next_map_id = 1;
|
|
|
|
end
|
|
|
|
|
2020-02-16 18:55:07 +01:00
|
|
|
local function save()
|
2020-06-09 02:01:26 +02:00
|
|
|
mod_storage:set_string("maps", minetest.serialize(map_data.maps));
|
|
|
|
mod_storage:set_int("next_map_id", map_data.next_map_id);
|
2020-06-01 13:59:34 +02:00
|
|
|
mod_storage:set_string("map", minetest.serialize(map_data.generated));
|
2020-02-16 18:55:07 +01: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);
|
|
|
|
|
2020-06-08 13:26:18 +02:00
|
|
|
local chunk_size = 16;
|
2020-06-08 00:20:35 +02:00
|
|
|
local chunk = {
|
2020-06-08 00:31:42 +02:00
|
|
|
to = function(coord)
|
2020-06-08 13:26:18 +02:00
|
|
|
return math.floor(coord / chunk_size);
|
2020-06-08 00:31:42 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
from = function(coord)
|
2020-06-08 13:26:18 +02:00
|
|
|
return math.floor(coord * chunk_size);
|
2020-06-08 00:31:42 +02:00
|
|
|
end
|
2020-06-08 00:20:35 +02:00
|
|
|
};
|
|
|
|
|
2020-06-08 13:26:18 +02:00
|
|
|
local biome_lookup = {};
|
|
|
|
local marker_lookup = {};
|
|
|
|
|
2020-02-16 18:55:07 +01:00
|
|
|
-- Includes
|
2020-06-09 00:34:57 +02:00
|
|
|
local skin = loadfile(modpath .. "/skin_api.lua") ();
|
|
|
|
local gui = loadfile(modpath .. "/formspec.lua") ();
|
|
|
|
|
|
|
|
cartographer.skin = skin;
|
|
|
|
|
2020-06-08 00:20:35 +02:00
|
|
|
loadfile(modpath .. "/scanner.lua") (map_data, chunk);
|
2020-06-09 02:01:26 +02:00
|
|
|
loadfile(modpath .. "/map_api.lua") (map_data, chunk, biome_lookup, marker_lookup);
|
2020-06-09 01:49:23 +02:00
|
|
|
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);
|
2020-06-09 02:01:26 +02:00
|
|
|
loadfile(modpath .. "/table.lua") (gui, skin);
|