Make fill_local a function of map objects

This commit is contained in:
Hugues Ross 2020-06-10 19:23:03 -04:00
parent d7f7210a2d
commit 30249edf44
2 changed files with 13 additions and 14 deletions

View File

@ -116,14 +116,18 @@ end
-- height_mode: Whether or not to display the map in height mode -- height_mode: Whether or not to display the map in height mode
-- (Optional) marker_page: The current page that the marker editor is on -- (Optional) marker_page: The current page that the marker editor is on
local function show_map_id_formspec(id, player_x, player_z, player_name, height_mode, marker_page) local function show_map_id_formspec(id, player_x, player_z, player_name, height_mode, marker_page)
cartographer.fill_local(id, player_x, player_z); local map = cartographer.get_map(id);
if not map then
return
end
map:fill_local(id, player_x, player_z);
player_maps[player_name] = { player_maps[player_name] = {
id = id, id = id,
page = marker_page or 1, page = marker_page or 1,
height_mode = height_mode, height_mode = height_mode,
}; };
local map = cartographer.get_map(id);
player_x, player_z = map:to_coordinates(player_x, player_z) player_x, player_z = map:to_coordinates(player_x, player_z)
local formspec, formspec_width, _ = map_formspec.from_map(map, player_x, player_z, height_mode); local formspec, formspec_width, _ = map_formspec.from_map(map, player_x, player_z, height_mode);

View File

@ -79,18 +79,12 @@ end
-- id: A map ID -- id: A map ID
-- x: The x position, in world coordinates -- x: The x position, in world coordinates
-- z: The z position, in world coordinates -- z: The z position, in world coordinates
function cartographer.fill_local(id, x, z) function Map.fill_local(self, x, z)
local map = cartographer.get_map(id); x, z = self:to_coordinates(x, z);
if not map then
return;
end
x, z = map:to_coordinates(x, z);
-- TODO: Adjust size to match map scale -- TODO: Adjust size to match map scale
if x >= map.x - 2 and x <= map.x + map.w + 1 and z >= map.z - 2 and z <= map.z + map.h + 1 then if x >= self.x - 2 and x <= self.x + self.w + 1 and z >= self.z - 2 and z <= self.z + self.h + 1 then
map:fill_area(x - 2, z - 2, 5, 5); self:fill_area(x - 2, z - 2, 5, 5);
end end
end end
@ -118,9 +112,10 @@ local function fill_loop()
if pos.y > -10 then if pos.y > -10 then
for i = 1,inventory:get_size("main") do for i = 1,inventory:get_size("main") do
local stack = inventory:get_stack("main", i); local stack = inventory:get_stack("main", i);
local map = cartographer.get_map(stack:get_meta():get_int("cartographer:map_id"));
if stack:get_name() == "cartographer:map" then if map then
cartographer.fill_local(stack:get_meta():get_int("cartographer:map_id"), pos.x, pos.z); map:fill_local(pos.x, pos.z);
end end
end end
for i = -2,2 do for i = -2,2 do