2020-06-13 14:50:36 +02:00
|
|
|
-- Arguments
|
|
|
|
-- chunk: The chunk coordinate conversion API
|
|
|
|
-- gui: The GUI API
|
|
|
|
-- skin: The GUI skin
|
|
|
|
-- audio: The audio playback API
|
|
|
|
-- maps: The map API
|
|
|
|
-- markers: The marker API
|
|
|
|
-- map_formspec: The map display API
|
2020-06-13 14:01:56 +02:00
|
|
|
local chunk, gui, skin, audio, maps, markers, map_formspec = ...;
|
2020-06-08 00:31:42 +02:00
|
|
|
|
2020-03-28 14:51:38 +01:00
|
|
|
-- The list of players looking at maps, and the map IDs that they're looking at
|
|
|
|
local player_maps = {};
|
|
|
|
|
2020-06-13 14:50:36 +02:00
|
|
|
-- Generate formspec data for the map marker editor
|
|
|
|
--
|
2020-06-09 00:12:05 +02:00
|
|
|
-- selected_id: The id of the currently selected marker, or nil if no marker is
|
|
|
|
-- selected
|
|
|
|
-- detail: The map's detail level
|
|
|
|
-- page: The current page
|
|
|
|
--
|
|
|
|
-- Returns a formspec string for use in containers
|
|
|
|
local function marker_formspec(selected_id, detail, page)
|
2020-06-13 14:01:56 +02:00
|
|
|
local marker_lookup = markers.get_all();
|
2020-06-09 00:12:05 +02:00
|
|
|
|
2020-06-13 14:01:56 +02:00
|
|
|
local formspec = {
|
2020-06-09 00:12:05 +02:00
|
|
|
gui.button {
|
|
|
|
x = 0.125,
|
|
|
|
y = 0.125,
|
|
|
|
|
|
|
|
w = 1.125,
|
|
|
|
h = 0.5,
|
|
|
|
|
|
|
|
id = "clear_marker",
|
|
|
|
text = "Erase",
|
|
|
|
tooltip = "Remove the selected marker",
|
|
|
|
},
|
|
|
|
|
|
|
|
gui.label {
|
|
|
|
x = 1.375,
|
|
|
|
y = 3.5,
|
|
|
|
|
|
|
|
text = string.format("%d / %d", page, math.ceil(#marker_lookup / 20)),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if selected_id then
|
|
|
|
table.insert(formspec, gui.style {
|
|
|
|
selector = "marker-" .. selected_id,
|
|
|
|
properties = {
|
|
|
|
bgimg = skin.marker_button.selected_texture .. ".png",
|
|
|
|
bgimg_hovered = skin.marker_button.selected_texture .. ".png",
|
|
|
|
bgimg_pressed = skin.marker_button.selected_texture .. ".png",
|
|
|
|
}
|
|
|
|
});
|
|
|
|
end
|
|
|
|
|
|
|
|
local starting_id = ((page - 1) * 20) + 1;
|
|
|
|
for i = starting_id,math.min(#marker_lookup,starting_id + 19),1 do
|
|
|
|
local marker = marker_lookup[i];
|
|
|
|
table.insert(formspec, gui.image_button {
|
|
|
|
x = (i - starting_id) % 5 * 0.625 + 0.125,
|
|
|
|
y = math.floor((i - starting_id) / 5) * 0.625 + 0.75,
|
|
|
|
|
|
|
|
w = 0.5,
|
|
|
|
h = 0.5,
|
|
|
|
|
|
|
|
image = marker.textures[math.min(detail, #marker.textures)] .. ".png",
|
|
|
|
id = "marker-" .. marker.id,
|
|
|
|
tooltip = marker.name,
|
|
|
|
});
|
|
|
|
end
|
|
|
|
|
|
|
|
if page > 1 then
|
|
|
|
table.insert(formspec, gui.button {
|
|
|
|
x = 0.125,
|
|
|
|
y = 3.25,
|
|
|
|
|
|
|
|
w = 0.5,
|
|
|
|
h = 0.5,
|
|
|
|
|
|
|
|
id = "prev_button",
|
|
|
|
text = "<"
|
|
|
|
});
|
|
|
|
end
|
|
|
|
|
|
|
|
if starting_id + 19 < #marker_lookup then
|
|
|
|
table.insert(formspec, gui.button {
|
|
|
|
x = 2.625,
|
|
|
|
y = 3.25,
|
|
|
|
|
|
|
|
w = 0.5,
|
|
|
|
h = 0.5,
|
|
|
|
|
|
|
|
id = "next_button",
|
|
|
|
text = ">"
|
|
|
|
});
|
|
|
|
end
|
|
|
|
|
|
|
|
return table.concat(formspec);
|
|
|
|
end
|
|
|
|
|
2020-06-13 14:50:36 +02:00
|
|
|
-- Show a map to a player
|
|
|
|
--
|
|
|
|
-- map: The map to display
|
2020-04-10 23:52:09 +02:00
|
|
|
-- player_x: The X position (in world coordinates)
|
|
|
|
-- player_z: The Z position (in world coordinates)
|
2020-03-28 14:51:38 +01:00
|
|
|
-- player_name: The name of the player to show to
|
2020-04-21 13:36:48 +02:00
|
|
|
-- height_mode: Whether or not to display the map in height mode
|
2020-04-17 01:50:03 +02:00
|
|
|
-- (Optional) marker_page: The current page that the marker editor is on
|
2020-06-13 14:50:36 +02:00
|
|
|
local function show_map_formspec(map, player_x, player_z, player_name, height_mode, marker_page)
|
|
|
|
map:fill_local(player_x, player_z);
|
2020-03-28 14:51:38 +01:00
|
|
|
|
2020-04-17 01:50:03 +02:00
|
|
|
player_maps[player_name] = {
|
2020-06-13 14:50:36 +02:00
|
|
|
id = map.id,
|
2020-04-17 01:50:03 +02:00
|
|
|
page = marker_page or 1,
|
2020-04-21 13:36:48 +02:00
|
|
|
height_mode = height_mode,
|
2020-04-17 01:50:03 +02:00
|
|
|
};
|
2020-03-28 14:51:38 +01:00
|
|
|
|
2020-06-13 17:50:43 +02:00
|
|
|
player_x, player_z = map:to_coordinates(player_x, player_z, true);
|
2020-06-09 01:49:23 +02:00
|
|
|
local formspec, formspec_width, _ = map_formspec.from_map(map, player_x, player_z, height_mode);
|
2020-06-13 14:01:56 +02:00
|
|
|
local height_button_texture;
|
|
|
|
if height_mode then
|
|
|
|
height_button_texture = skin.height_button_texture .. ".png";
|
|
|
|
else
|
|
|
|
height_button_texture = skin.flat_button_texture .. ".png";
|
|
|
|
end
|
2020-06-08 02:35:17 +02:00
|
|
|
|
2020-06-13 14:01:56 +02:00
|
|
|
local data = {
|
|
|
|
gui.style_type {
|
|
|
|
selector = "button,image_button,label",
|
|
|
|
properties = {
|
|
|
|
noclip = true,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
gui.style_type {
|
|
|
|
selector = "button,image_button",
|
|
|
|
properties = {
|
|
|
|
border = false,
|
|
|
|
bgimg = skin.marker_button.texture .. ".png",
|
|
|
|
bgimg_hovered = skin.marker_button.hovered_texture .. ".png",
|
|
|
|
bgimg_pressed = skin.marker_button.pressed_texture .. ".png",
|
|
|
|
bgimg_middle = skin.marker_button.radius,
|
|
|
|
textcolor = skin.marker_button.font_color,
|
2020-06-08 02:35:17 +02:00
|
|
|
},
|
2020-06-13 14:01:56 +02:00
|
|
|
},
|
|
|
|
gui.container {
|
|
|
|
x = formspec_width - 0.01,
|
|
|
|
y = 0.125,
|
|
|
|
w = 0.75,
|
|
|
|
h = 0.75,
|
|
|
|
bg = skin.marker_bg,
|
|
|
|
|
|
|
|
gui.image_button {
|
|
|
|
x = 0.125,
|
2020-06-08 02:35:17 +02:00
|
|
|
y = 0.125,
|
2020-06-13 14:01:56 +02:00
|
|
|
w = 0.5,
|
|
|
|
h = 0.5,
|
|
|
|
|
|
|
|
id = "height_button",
|
|
|
|
image = height_button_texture,
|
|
|
|
tooltip = "Toggle height view",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if markers.count() > 0 then
|
|
|
|
table.insert(data, gui.container {
|
|
|
|
x = formspec_width - 0.01,
|
|
|
|
y = 1,
|
|
|
|
w = 3.25,
|
|
|
|
h = 3.875,
|
|
|
|
bg = skin.marker_bg,
|
|
|
|
|
|
|
|
marker_formspec(map:get_marker(player_x, player_z), map.detail, marker_page or 1)});
|
2020-03-28 14:51:38 +01:00
|
|
|
end
|
2020-06-13 14:01:56 +02:00
|
|
|
|
|
|
|
formspec = formspec .. table.concat(data);
|
2020-03-28 14:51:38 +01:00
|
|
|
minetest.show_formspec(player_name, "cartographer:map", formspec);
|
|
|
|
end
|
|
|
|
|
2020-06-08 02:35:17 +02:00
|
|
|
-- Get the description text for a map ID and dimensions
|
2020-06-13 14:50:36 +02:00
|
|
|
--
|
2020-06-08 02:35:17 +02:00
|
|
|
-- id: The map ID
|
2020-06-13 17:50:43 +02:00
|
|
|
-- from_x: The x coordinate of the top-left corner of the map, in map coordinates
|
|
|
|
-- from_z: The z coordinate of the top-left corner of the map, in map coordinates
|
2020-06-08 02:35:17 +02:00
|
|
|
-- w: The width, in world coordinates
|
|
|
|
-- h: The height, in world coordinates
|
2020-06-13 14:50:36 +02:00
|
|
|
--
|
|
|
|
-- returns a string containing the description
|
2020-06-08 02:35:17 +02:00
|
|
|
local function map_description(id, from_x, from_z, w, h)
|
|
|
|
return string.format("Map #%d\n[%d,%d] - [%d,%d]",
|
|
|
|
id,
|
|
|
|
chunk.from(from_x), chunk.from(from_z),
|
2020-06-13 17:50:43 +02:00
|
|
|
chunk.from(from_x + w + 1), chunk.from(from_z + h + 1));
|
2020-06-08 02:35:17 +02:00
|
|
|
end
|
|
|
|
|
2020-03-28 14:51:38 +01:00
|
|
|
-- Create a map from metadata, and assign the ID to the metadata
|
2020-06-13 14:50:36 +02:00
|
|
|
--
|
2020-03-28 14:51:38 +01:00
|
|
|
-- meta: A metadata object containing the map ID
|
|
|
|
-- player_x: The X position (in map coordinates)
|
|
|
|
-- player_z: The Z position (in map coordinates)
|
2020-06-13 14:50:36 +02:00
|
|
|
--
|
|
|
|
-- Returns the id of the new map
|
2020-03-28 14:51:38 +01:00
|
|
|
local function map_from_meta(meta, player_x, player_z)
|
2020-06-13 17:59:08 +02:00
|
|
|
local size = meta:get_int("cartographer:size");
|
|
|
|
if size == 0 then
|
|
|
|
size = 40;
|
|
|
|
end
|
|
|
|
|
|
|
|
local detail = meta:get_int("cartographer:detail");
|
|
|
|
if detail == 0 then
|
|
|
|
detail = 1;
|
|
|
|
end
|
|
|
|
|
|
|
|
local scale = meta:get_int("cartographer:scale");
|
|
|
|
if scale == 0 then
|
|
|
|
scale = 1;
|
|
|
|
end
|
2020-03-08 15:34:20 +01:00
|
|
|
|
|
|
|
local total_size = size * scale;
|
|
|
|
|
2020-06-13 17:50:43 +02:00
|
|
|
local map_x = math.floor(player_x / total_size) * total_size;
|
|
|
|
local map_y = math.floor(player_z / total_size) * total_size;
|
2020-03-08 15:34:20 +01:00
|
|
|
|
2020-06-11 01:29:06 +02:00
|
|
|
local id = maps.create(map_x, map_y, size, size, false, detail, scale);
|
2020-03-08 15:34:20 +01:00
|
|
|
|
|
|
|
meta:set_int("cartographer:map_id", id);
|
2020-06-08 02:35:17 +02:00
|
|
|
meta:set_string("description", map_description(id, map_x, map_y, total_size, total_size));
|
2020-03-08 15:34:20 +01:00
|
|
|
|
|
|
|
return id;
|
|
|
|
end
|
|
|
|
|
2020-06-13 14:50:36 +02:00
|
|
|
-- Show a map to a player from metadata, creating it if necessary
|
|
|
|
--
|
2020-03-28 14:51:38 +01:00
|
|
|
-- meta: A metadata object containing the map ID
|
|
|
|
-- player: The player to show the map to
|
|
|
|
local function show_map_meta(meta, player)
|
|
|
|
local pos = player:get_pos();
|
2020-06-08 00:31:42 +02:00
|
|
|
local player_x = chunk.to(pos.x);
|
|
|
|
local player_z = chunk.to(pos.z);
|
2020-03-28 14:51:38 +01:00
|
|
|
|
|
|
|
local id = meta:get_int("cartographer:map_id");
|
|
|
|
if id == 0 then
|
|
|
|
id = map_from_meta(meta, player_x, player_z);
|
|
|
|
end
|
|
|
|
|
2020-06-13 14:50:36 +02:00
|
|
|
local map = maps.get(id);
|
|
|
|
if map then
|
|
|
|
show_map_formspec(map, pos.x, pos.z, player:get_player_name(), true);
|
|
|
|
end
|
2020-03-28 14:51:38 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Called when a player sends input to the server from a formspec
|
|
|
|
-- This callback handles player input in the map formspec, for editing markers
|
2020-06-13 14:50:36 +02:00
|
|
|
--
|
2020-03-28 14:51:38 +01:00
|
|
|
-- player: The player who sent the input
|
|
|
|
-- name: The formspec name
|
|
|
|
-- fields: A table containing the input
|
|
|
|
minetest.register_on_player_receive_fields(function(player, name, fields)
|
|
|
|
if name == "cartographer:map" then
|
2020-04-17 01:50:03 +02:00
|
|
|
local data = player_maps[player:get_player_name()];
|
2020-04-21 13:36:48 +02:00
|
|
|
if not data then
|
|
|
|
return;
|
|
|
|
end
|
2020-04-17 01:50:03 +02:00
|
|
|
|
2020-06-11 01:29:06 +02:00
|
|
|
local map = maps.get(data.id);
|
2020-03-28 14:51:38 +01:00
|
|
|
if not map then
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
2020-06-02 00:00:53 +02:00
|
|
|
for k,_ in pairs(fields) do
|
2020-03-28 14:51:38 +01:00
|
|
|
local marker = k:match("marker%-(.+)");
|
2020-04-17 01:50:03 +02:00
|
|
|
local pos = player:get_pos();
|
2020-03-28 14:51:38 +01:00
|
|
|
if marker or k == "clear_marker" then
|
2020-06-13 18:14:07 +02:00
|
|
|
local player_x, player_z = map:to_coordinates(pos.x, pos.z, true);
|
2020-06-10 02:17:39 +02:00
|
|
|
map:set_marker(player_x, player_z, marker);
|
2020-03-28 14:51:38 +01:00
|
|
|
|
2020-06-10 13:02:46 +02:00
|
|
|
audio.play_feedback("cartographer_write", player);
|
2020-06-13 14:50:36 +02:00
|
|
|
show_map_formspec(map, pos.x, pos.z, player:get_player_name(), data.page);
|
2020-04-17 01:50:03 +02:00
|
|
|
elseif k == "prev_button" then
|
2020-06-13 14:50:36 +02:00
|
|
|
show_map_formspec(map, pos.x, pos.z, player:get_player_name(), data.height_mode, data.page - 1);
|
2020-04-17 01:50:03 +02:00
|
|
|
elseif k == "next_button" then
|
2020-06-13 14:50:36 +02:00
|
|
|
show_map_formspec(map, pos.x, pos.z, player:get_player_name(), data.height_mode, data.page + 1);
|
2020-04-21 13:36:48 +02:00
|
|
|
elseif k == "height_button" then
|
2020-06-13 14:50:36 +02:00
|
|
|
show_map_formspec(map, pos.x, pos.z, player:get_player_name(), not data.height_mode, data.page);
|
2020-03-28 14:51:38 +01:00
|
|
|
elseif k == "quit" then
|
|
|
|
player_maps[player:get_player_name()] = nil;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end);
|
|
|
|
|
2020-03-20 13:01:43 +01:00
|
|
|
-- The map item/node
|
2020-02-16 18:55:07 +01:00
|
|
|
minetest.register_node("cartographer:map", {
|
|
|
|
description = "Map",
|
|
|
|
inventory_image = "cartographer_map.png",
|
2020-04-19 02:10:02 +02:00
|
|
|
wield_image = "cartographer_map.png",
|
2020-03-20 13:01:43 +01:00
|
|
|
tiles = { "cartographer_map.png" },
|
2020-02-16 18:55:07 +01:00
|
|
|
drawtype = "signlike",
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "wallmounted",
|
|
|
|
stack_max = 1,
|
2020-03-21 01:38:46 +01:00
|
|
|
sunlight_propagates = true,
|
|
|
|
walkable = false,
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
|
|
|
{-0.5, -0.5, -0.5, 0.5, -7 / 16, 0.5},
|
|
|
|
},
|
|
|
|
},
|
2020-02-16 18:55:07 +01:00
|
|
|
|
2020-04-19 02:10:02 +02:00
|
|
|
groups = {
|
|
|
|
attached_node = 1,
|
|
|
|
dig_immediate = 3,
|
|
|
|
},
|
|
|
|
|
2020-03-20 13:01:43 +01:00
|
|
|
-- Called when this node is placed in the world. Copies map data from the
|
|
|
|
-- item to the node.
|
|
|
|
-- pos: The position of the node
|
|
|
|
-- stack: The itemstack that was placed
|
2020-06-02 00:00:53 +02:00
|
|
|
after_place_node = function(pos, _, stack, _)
|
2020-02-16 18:55:07 +01:00
|
|
|
local meta = stack:get_meta():to_table();
|
2020-03-20 13:01:43 +01:00
|
|
|
local node_meta = minetest.get_meta(pos);
|
2020-02-16 18:55:07 +01:00
|
|
|
node_meta:from_table(meta);
|
|
|
|
|
2020-03-20 13:01:43 +01:00
|
|
|
-- Consume the item after placing
|
|
|
|
return false;
|
2020-02-16 18:55:07 +01:00
|
|
|
end,
|
|
|
|
|
2020-04-19 02:10:02 +02:00
|
|
|
-- Called when this node is dug. Turns the node into an item.
|
|
|
|
-- pos: The position of the node
|
|
|
|
on_dig = function(pos, _, _)
|
|
|
|
local node_meta = minetest.get_meta(pos):to_table();
|
|
|
|
local item = ItemStack("cartographer:map");
|
|
|
|
item:get_meta():from_table(node_meta);
|
|
|
|
|
|
|
|
if minetest.add_item(pos, item) then
|
|
|
|
minetest.remove_node(pos);
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
2020-03-28 14:51:38 +01:00
|
|
|
-- Called when a player right-clicks this node. Display's the map's
|
|
|
|
-- content, creating it if it doesn't exist.
|
|
|
|
-- pos: The position of the node
|
|
|
|
-- player: The player that right-clicked the node
|
|
|
|
on_rightclick = function(pos, _, player)
|
2020-06-10 13:02:46 +02:00
|
|
|
audio.play_feedback("cartographer_open_map", player);
|
2020-03-28 14:51:38 +01:00
|
|
|
show_map_meta(minetest.get_meta(pos), player);
|
|
|
|
end,
|
2020-02-16 18:55:07 +01:00
|
|
|
|
2020-03-28 14:51:38 +01:00
|
|
|
-- Called when a player uses this item. Displays the map's content,
|
|
|
|
-- creating it if it doesn't exist.
|
|
|
|
-- stack: The itemstack
|
|
|
|
-- player: The player that used the item
|
|
|
|
on_use = function(stack, player)
|
2020-06-10 13:02:46 +02:00
|
|
|
audio.play_feedback("cartographer_open_map", player);
|
2020-03-28 14:51:38 +01:00
|
|
|
show_map_meta(stack:get_meta(), player);
|
2020-04-19 02:10:02 +02:00
|
|
|
return stack;
|
|
|
|
end,
|
|
|
|
|
|
|
|
-- Called when a node is about to be turned into an item. Copies all
|
|
|
|
-- metadata into any items matching this node's name.
|
|
|
|
-- oldnode: The old node's data
|
|
|
|
-- oldmeta: A table containing the old node's metadata
|
|
|
|
-- drops: A table containing the new items
|
|
|
|
preserve_metadata = function(_, oldnode, oldmeta, drops)
|
|
|
|
for _,item in ipairs(drops) do
|
|
|
|
if item:get_name() == oldnode.name then
|
|
|
|
item:get_meta():from_table({fields=oldmeta});
|
|
|
|
end
|
|
|
|
end
|
2020-02-16 18:55:07 +01:00
|
|
|
end,
|
|
|
|
});
|
|
|
|
|
2020-06-13 14:50:36 +02:00
|
|
|
-- Create an empty map item with the given parameters
|
|
|
|
--
|
|
|
|
-- size: The size of the map
|
|
|
|
-- detail: The detail level of the map
|
|
|
|
-- scale: The scaling factor of the map
|
|
|
|
--
|
|
|
|
-- Returns an ItemStack
|
2020-06-11 01:45:13 +02:00
|
|
|
local function create_map_item(size, detail, scale)
|
2020-02-16 18:55:07 +01:00
|
|
|
local map = ItemStack("cartographer:map");
|
|
|
|
local meta = map:get_meta();
|
|
|
|
meta:set_int("cartographer:size", size);
|
|
|
|
meta:set_int("cartographer:detail", detail);
|
2020-03-08 15:34:20 +01:00
|
|
|
meta:set_int("cartographer:scale", scale);
|
2020-02-16 18:55:07 +01:00
|
|
|
meta:set_string("description", "Empty Map\nUse to set the initial location");
|
|
|
|
|
|
|
|
return map;
|
|
|
|
end
|
|
|
|
|
2020-04-11 21:36:15 +02:00
|
|
|
-- Create a copy of the given map
|
2020-06-13 14:50:36 +02:00
|
|
|
--
|
2020-04-11 21:36:15 +02:00
|
|
|
-- stack: An itemstack containing a map
|
2020-06-02 00:00:53 +02:00
|
|
|
--
|
2020-06-13 14:50:36 +02:00
|
|
|
-- Returns a new ItemStack with the copied map
|
2020-06-11 01:45:13 +02:00
|
|
|
local function copy_map_item(stack)
|
2020-02-16 18:55:07 +01:00
|
|
|
local meta = stack:get_meta();
|
|
|
|
|
|
|
|
local size = meta:get_int("cartographer:size");
|
|
|
|
local detail = meta:get_int("cartographer:detail");
|
2020-03-08 15:34:20 +01:00
|
|
|
local scale = meta:get_int("cartographer:scale");
|
2020-02-16 18:55:07 +01:00
|
|
|
|
2020-06-11 01:45:13 +02:00
|
|
|
local copy = create_map_item(size, detail, scale);
|
2020-02-16 18:55:07 +01:00
|
|
|
local copy_meta = copy:get_meta();
|
|
|
|
|
|
|
|
local id = meta:get_int("cartographer:map_id");
|
|
|
|
if id > 0 then
|
2020-06-11 01:29:06 +02:00
|
|
|
local src = maps.get(id);
|
2020-02-16 18:55:07 +01:00
|
|
|
|
2020-06-11 01:29:06 +02:00
|
|
|
local new_id = maps.create(src.x, src.z, src.w, src.h, false, src.detail, src.scale);
|
|
|
|
local dest = maps.get(new_id);
|
2020-02-16 18:55:07 +01:00
|
|
|
for k,v in pairs(src.fill) do
|
|
|
|
dest.fill[k] = v;
|
|
|
|
end
|
2020-04-11 21:36:15 +02:00
|
|
|
for k,v in pairs(src.markers) do
|
|
|
|
dest.markers[k] = v;
|
|
|
|
end
|
2020-02-16 18:55:07 +01:00
|
|
|
|
|
|
|
copy_meta:set_int("cartographer:map_id", new_id);
|
2020-06-08 02:35:17 +02:00
|
|
|
copy_meta:set_string("description", map_description(new_id,
|
|
|
|
dest.x, dest.z,
|
|
|
|
dest.w, dest.h));
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
end
|
|
|
|
|
2020-06-13 14:50:36 +02:00
|
|
|
-- Resize the given map item
|
|
|
|
--
|
|
|
|
-- meta: A metadata object containing the map data
|
|
|
|
-- size: The new size
|
2020-06-11 01:45:13 +02:00
|
|
|
local function resize_map_item(meta, size)
|
2020-02-16 18:55:07 +01:00
|
|
|
local old_size = meta:get_int("cartographer:size");
|
|
|
|
|
|
|
|
if old_size >= size then
|
|
|
|
return;
|
|
|
|
end
|
|
|
|
|
|
|
|
meta:set_int("cartographer:size", size);
|
|
|
|
|
|
|
|
local id = meta:get_int("cartographer:map_id");
|
|
|
|
if id > 0 then
|
2020-06-11 01:29:06 +02:00
|
|
|
local map = maps.get(id);
|
2020-06-10 02:17:39 +02:00
|
|
|
map:resize(size, size);
|
2020-02-16 18:55:07 +01:00
|
|
|
|
2020-06-09 00:12:05 +02:00
|
|
|
meta:set_string("description", map_description(id,
|
2020-06-13 14:50:36 +02:00
|
|
|
chunk.from(map.x), chunk.from(map.z),
|
|
|
|
chunk.from(map.w), chunk.from(map.h)));
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
end
|
2020-06-11 01:45:13 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
create = create_map_item,
|
|
|
|
copy = copy_map_item,
|
|
|
|
resize = resize_map_item,
|
|
|
|
};
|