Remove _cartographer global

This commit is contained in:
Hugues Ross 2020-06-08 20:01:26 -04:00
parent 3510bbcb35
commit b42c9d051f
3 changed files with 20 additions and 21 deletions

View File

@ -7,25 +7,21 @@ local modpath = minetest.get_modpath("cartographer");
cartographer = {
scan_queue = {},
};
_cartographer = {
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 {},
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(_cartographer.maps));
mod_storage:set_int("next_map_id", _cartographer.next_map_id);
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);
@ -58,8 +54,8 @@ local gui = loadfile(modpath .. "/formspec.lua") ();
cartographer.skin = skin;
loadfile(modpath .. "/scanner.lua") (map_data, chunk);
loadfile(modpath .. "/map_api.lua") (chunk, biome_lookup, marker_lookup);
loadfile(modpath .. "/map_api.lua") (map_data, chunk, 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") (_cartographer.materials_by_name, _cartographer.materials_by_group, gui, skin);
loadfile(modpath .. "/table.lua") (gui, skin);

View File

@ -1,7 +1,7 @@
local chunk, biome_lookup, marker_lookup = ...;
local map_data, chunk, biome_lookup, marker_lookup = ...;
function cartographer.create_map(x, z, w, h, filled, detail, scale)
local id = _cartographer.next_map_id;
local id = map_data.next_map_id;
local map = {
id = id,
@ -15,18 +15,18 @@ function cartographer.create_map(x, z, w, h, filled, detail, scale)
markers = {},
};
_cartographer.maps[id] = map;
map_data.maps[id] = map;
if filled then
cartographer.fill(map, x, z, w, h);
end
_cartographer.next_map_id = _cartographer.next_map_id + 1;
map_data.next_map_id = map_data.next_map_id + 1;
return id;
end
function cartographer.get_map(id)
return _cartographer.maps[id];
return map_data.maps[id];
end
function cartographer.resize_map(id, w, h)

View File

@ -1,4 +1,4 @@
local materials_by_name, materials_by_group, gui, gui_skin = ...;
local gui, gui_skin = ...;
local MAP_SIZE = 40;
local SCALE_SMALL = 1;
@ -6,6 +6,9 @@ local SCALE_MEDIUM = 2;
local SCALE_LARGE = 4;
local SCALE_HUGE = 8;
local materials_by_name = {};
local materials_by_group = {};
-- Get the material cost for the given map scale and detail level
-- scale: The map scale
-- detail: The detail level