Move map item functions into a separate api object
This commit is contained in:
parent
e53bd8af41
commit
ad9c5e77b0
5
init.lua
5
init.lua
@ -56,11 +56,12 @@ local scanner = loadfile(modpath .. "/scanner.lua") (map_data, chunk);
|
||||
local maps = loadfile(modpath .. "/map_api.lua") (map_data, chunk, scanner);
|
||||
local markers = loadfile(modpath .. "/marker_api.lua") (marker_lookup);
|
||||
local map_formspec = loadfile(modpath .. "/map_formspec.lua") (map_data, gui, skin, biomes, markers);
|
||||
loadfile(modpath .. "/items.lua") (chunk, marker_lookup, gui, skin, audio, maps, map_formspec);
|
||||
local map_item = loadfile(modpath .. "/items.lua") (chunk, marker_lookup, gui, skin, audio, maps, map_formspec);
|
||||
loadfile(modpath .. "/commands.lua") (chunk, audio, map_formspec);
|
||||
loadfile(modpath .. "/table.lua") (gui, skin, audio, maps);
|
||||
loadfile(modpath .. "/table.lua") (gui, skin, audio, maps, map_item);
|
||||
|
||||
cartographer.skin = skin;
|
||||
cartographer.biomes = biomes;
|
||||
cartographer.markers = markers;
|
||||
cartographer.maps = maps;
|
||||
cartographer.map_item = map_item;
|
||||
|
14
items.lua
14
items.lua
@ -349,7 +349,7 @@ minetest.register_node("cartographer:map", {
|
||||
end,
|
||||
});
|
||||
|
||||
function cartographer.create_map_item(size, detail, scale)
|
||||
local function create_map_item(size, detail, scale)
|
||||
local map = ItemStack("cartographer:map");
|
||||
local meta = map:get_meta();
|
||||
meta:set_int("cartographer:size", size);
|
||||
@ -364,14 +364,14 @@ end
|
||||
-- stack: An itemstack containing a map
|
||||
--
|
||||
-- Returns an itemstack with the copied map
|
||||
function cartographer.copy_map_item(stack)
|
||||
local function copy_map_item(stack)
|
||||
local meta = stack:get_meta();
|
||||
|
||||
local size = meta:get_int("cartographer:size");
|
||||
local detail = meta:get_int("cartographer:detail");
|
||||
local scale = meta:get_int("cartographer:scale");
|
||||
|
||||
local copy = cartographer.create_map_item(size, detail, scale);
|
||||
local copy = create_map_item(size, detail, scale);
|
||||
local copy_meta = copy:get_meta();
|
||||
|
||||
local id = meta:get_int("cartographer:map_id");
|
||||
@ -396,7 +396,7 @@ function cartographer.copy_map_item(stack)
|
||||
return copy;
|
||||
end
|
||||
|
||||
function cartographer.resize_map_item(meta, size)
|
||||
local function resize_map_item(meta, size)
|
||||
local old_size = meta:get_int("cartographer:size");
|
||||
|
||||
if old_size >= size then
|
||||
@ -415,3 +415,9 @@ function cartographer.resize_map_item(meta, size)
|
||||
chunk.from(map.w), chunk.from(map.h)));
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
create = create_map_item,
|
||||
copy = copy_map_item,
|
||||
resize = resize_map_item,
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
local gui, gui_skin, audio, maps = ...;
|
||||
local gui, gui_skin, audio, maps, map_item = ...;
|
||||
|
||||
local MAP_SIZE = 40;
|
||||
local SCALE_SMALL = 1;
|
||||
@ -715,11 +715,11 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
|
||||
local stack = inv:get_stack("output", 1);
|
||||
|
||||
if stack:is_empty() then
|
||||
inv:set_stack("output", 1, cartographer.create_map_item(size, 1 + detail, scale));
|
||||
inv:set_stack("output", 1, map_item.create(size, 1 + detail, scale));
|
||||
else
|
||||
local smeta = stack:get_meta();
|
||||
smeta:set_int("cartographer:detail", 1 + detail);
|
||||
cartographer.resize_map_item(smeta, size);
|
||||
map_item.resize(smeta, size);
|
||||
|
||||
local map = maps.get(smeta:get_int("cartographer:map_id"));
|
||||
if map then
|
||||
@ -739,7 +739,7 @@ minetest.register_on_player_receive_fields(function(player, name, fields)
|
||||
audio.play_feedback("cartographer_write", player);
|
||||
|
||||
local inv = meta:get_inventory();
|
||||
inv:set_stack("copy_output", 1, cartographer.copy_map_item(inv:get_stack("copy_input", 1)));
|
||||
inv:set_stack("copy_output", 1, map_item.copy(inv:get_stack("copy_input", 1)));
|
||||
end
|
||||
elseif fields["1"] then
|
||||
meta:set_int("detail", 0);
|
||||
|
Loading…
Reference in New Issue
Block a user