Remove _cartographer global
This commit is contained in:
parent
3510bbcb35
commit
b42c9d051f
26
init.lua
26
init.lua
@ -7,25 +7,21 @@ local modpath = minetest.get_modpath("cartographer");
|
|||||||
cartographer = {
|
cartographer = {
|
||||||
scan_queue = {},
|
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 = {
|
local map_data = {
|
||||||
generated = minetest.deserialize(mod_storage:get_string("map")) or {},
|
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()
|
local function save()
|
||||||
mod_storage:set_string("maps", minetest.serialize(_cartographer.maps));
|
mod_storage:set_string("maps", minetest.serialize(map_data.maps));
|
||||||
mod_storage:set_int("next_map_id", _cartographer.next_map_id);
|
mod_storage:set_int("next_map_id", map_data.next_map_id);
|
||||||
mod_storage:set_string("map", minetest.serialize(map_data.generated));
|
mod_storage:set_string("map", minetest.serialize(map_data.generated));
|
||||||
end
|
end
|
||||||
minetest.register_on_shutdown(save);
|
minetest.register_on_shutdown(save);
|
||||||
@ -58,8 +54,8 @@ local gui = loadfile(modpath .. "/formspec.lua") ();
|
|||||||
cartographer.skin = skin;
|
cartographer.skin = skin;
|
||||||
|
|
||||||
loadfile(modpath .. "/scanner.lua") (map_data, chunk);
|
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);
|
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 .. "/items.lua") (chunk, marker_lookup, gui, skin, map_formspec);
|
||||||
loadfile(modpath .. "/commands.lua") (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);
|
||||||
|
10
map_api.lua
10
map_api.lua
@ -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)
|
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 = {
|
local map = {
|
||||||
id = id,
|
id = id,
|
||||||
@ -15,18 +15,18 @@ function cartographer.create_map(x, z, w, h, filled, detail, scale)
|
|||||||
markers = {},
|
markers = {},
|
||||||
};
|
};
|
||||||
|
|
||||||
_cartographer.maps[id] = map;
|
map_data.maps[id] = map;
|
||||||
if filled then
|
if filled then
|
||||||
cartographer.fill(map, x, z, w, h);
|
cartographer.fill(map, x, z, w, h);
|
||||||
end
|
end
|
||||||
|
|
||||||
_cartographer.next_map_id = _cartographer.next_map_id + 1;
|
map_data.next_map_id = map_data.next_map_id + 1;
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
end
|
end
|
||||||
|
|
||||||
function cartographer.get_map(id)
|
function cartographer.get_map(id)
|
||||||
return _cartographer.maps[id];
|
return map_data.maps[id];
|
||||||
end
|
end
|
||||||
|
|
||||||
function cartographer.resize_map(id, w, h)
|
function cartographer.resize_map(id, w, h)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local materials_by_name, materials_by_group, gui, gui_skin = ...;
|
local gui, gui_skin = ...;
|
||||||
|
|
||||||
local MAP_SIZE = 40;
|
local MAP_SIZE = 40;
|
||||||
local SCALE_SMALL = 1;
|
local SCALE_SMALL = 1;
|
||||||
@ -6,6 +6,9 @@ local SCALE_MEDIUM = 2;
|
|||||||
local SCALE_LARGE = 4;
|
local SCALE_LARGE = 4;
|
||||||
local SCALE_HUGE = 8;
|
local SCALE_HUGE = 8;
|
||||||
|
|
||||||
|
local materials_by_name = {};
|
||||||
|
local materials_by_group = {};
|
||||||
|
|
||||||
-- Get the material cost for the given map scale and detail level
|
-- Get the material cost for the given map scale and detail level
|
||||||
-- scale: The map scale
|
-- scale: The map scale
|
||||||
-- detail: The detail level
|
-- detail: The detail level
|
||||||
|
Loading…
Reference in New Issue
Block a user