2020-02-16 12:55:07 -05:00
|
|
|
local mod_storage = minetest.get_mod_storage();
|
|
|
|
|
2020-06-01 18:00:02 -04:00
|
|
|
-- The path to this mod, for including files
|
|
|
|
local modpath = minetest.get_modpath("cartographer");
|
|
|
|
|
2020-06-01 07:59:34 -04:00
|
|
|
local map_data = {
|
2020-02-16 12:55:07 -05:00
|
|
|
generated = minetest.deserialize(mod_storage:get_string("map")) or {},
|
2020-06-08 20:01:26 -04:00
|
|
|
|
|
|
|
maps = minetest.deserialize(mod_storage:get_string("maps")) or {},
|
|
|
|
next_map_id = mod_storage:get_int("next_map_id"),
|
2020-06-10 20:49:10 -04:00
|
|
|
};
|
2020-02-16 12:55:07 -05:00
|
|
|
|
2020-06-08 20:01:26 -04:00
|
|
|
if map_data.next_map_id == 0 then
|
|
|
|
map_data.next_map_id = 1;
|
|
|
|
end
|
|
|
|
|
2020-02-16 12:55:07 -05:00
|
|
|
local function save()
|
2020-06-08 20:01:26 -04: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 07:59:34 -04:00
|
|
|
mod_storage:set_string("map", minetest.serialize(map_data.generated));
|
2020-02-16 12:55:07 -05: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 07:26:18 -04:00
|
|
|
local chunk_size = 16;
|
2020-06-07 18:20:35 -04:00
|
|
|
local chunk = {
|
2020-06-07 18:31:42 -04:00
|
|
|
to = function(coord)
|
2020-06-08 07:26:18 -04:00
|
|
|
return math.floor(coord / chunk_size);
|
2020-06-07 18:31:42 -04:00
|
|
|
end,
|
|
|
|
|
|
|
|
from = function(coord)
|
2020-06-08 07:26:18 -04:00
|
|
|
return math.floor(coord * chunk_size);
|
2020-06-07 18:31:42 -04:00
|
|
|
end
|
2020-06-07 18:20:35 -04:00
|
|
|
};
|
|
|
|
|
2020-06-08 07:26:18 -04:00
|
|
|
local marker_lookup = {};
|
|
|
|
|
2020-02-16 12:55:07 -05:00
|
|
|
-- Includes
|
2020-06-08 18:34:57 -04:00
|
|
|
local skin = loadfile(modpath .. "/skin_api.lua") ();
|
|
|
|
local gui = loadfile(modpath .. "/formspec.lua") ();
|
2020-06-10 07:02:46 -04:00
|
|
|
local audio = loadfile(modpath .. "/audio.lua") ();
|
2020-06-10 19:54:28 -04:00
|
|
|
local util = loadfile(modpath .. "/util.lua") ();
|
2020-06-08 18:34:57 -04:00
|
|
|
|
2020-06-10 19:54:28 -04:00
|
|
|
local biomes = loadfile(modpath .. "/biome_api.lua") (util);
|
2020-06-10 19:18:36 -04:00
|
|
|
|
2020-06-08 20:08:24 -04:00
|
|
|
local scanner = loadfile(modpath .. "/scanner.lua") (map_data, chunk);
|
2020-06-10 19:39:26 -04:00
|
|
|
local maps = loadfile(modpath .. "/map_api.lua") (map_data, chunk, scanner);
|
2020-06-10 20:01:58 -04:00
|
|
|
local materials = loadfile(modpath .. "/material_api.lua") ();
|
2020-06-10 19:39:26 -04:00
|
|
|
local markers = loadfile(modpath .. "/marker_api.lua") (marker_lookup);
|
2020-06-10 19:54:28 -04:00
|
|
|
local map_formspec = loadfile(modpath .. "/map_formspec.lua") (map_data, gui, skin, util, biomes, markers);
|
2020-06-10 19:45:13 -04:00
|
|
|
local map_item = loadfile(modpath .. "/items.lua") (chunk, marker_lookup, gui, skin, audio, maps, map_formspec);
|
2020-06-10 07:02:46 -04:00
|
|
|
loadfile(modpath .. "/commands.lua") (chunk, audio, map_formspec);
|
2020-06-10 20:01:58 -04:00
|
|
|
loadfile(modpath .. "/table.lua") (gui, skin, audio, maps, materials, map_item);
|
2020-06-10 20:49:10 -04:00
|
|
|
loadfile(modpath .. "/autofill.lua") (chunk, scanner);
|
2020-06-08 20:05:51 -04:00
|
|
|
|
2020-06-10 20:10:15 -04:00
|
|
|
-- The API object
|
|
|
|
cartographer = {
|
|
|
|
skin = skin;
|
|
|
|
biomes = biomes;
|
|
|
|
markers = markers;
|
|
|
|
maps = maps;
|
|
|
|
map_item = map_item;
|
|
|
|
materials = materials;
|
|
|
|
};
|